Spaces:
Build error
Build error
fix: block suspicious requests before sideload
Browse files- src/api/crawler.ts +22 -3
src/api/crawler.ts
CHANGED
|
@@ -305,11 +305,10 @@ export class CrawlerHost extends RPCHost {
|
|
| 305 |
}
|
| 306 |
}
|
| 307 |
|
|
|
|
| 308 |
if (crawlerOptions.robotsTxt) {
|
| 309 |
await this.robotsTxtService.assertAccessAllowed(targetUrl, crawlerOptions.robotsTxt);
|
| 310 |
}
|
| 311 |
-
|
| 312 |
-
const crawlOpts = await this.configure(crawlerOptions);
|
| 313 |
if (!ctx.accepts('text/plain') && ctx.accepts('text/event-stream')) {
|
| 314 |
const sseStream = new OutputServerEventStream();
|
| 315 |
rpcReflect.return(sseStream);
|
|
@@ -508,7 +507,27 @@ export class CrawlerHost extends RPCHost {
|
|
| 508 |
});
|
| 509 |
}
|
| 510 |
|
| 511 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 512 |
await lookup(result.hostname).catch((err) => {
|
| 513 |
if (err.code === 'ENOTFOUND') {
|
| 514 |
return Promise.reject(new ParamValidationError({
|
|
|
|
| 305 |
}
|
| 306 |
}
|
| 307 |
|
| 308 |
+
const crawlOpts = await this.configure(crawlerOptions);
|
| 309 |
if (crawlerOptions.robotsTxt) {
|
| 310 |
await this.robotsTxtService.assertAccessAllowed(targetUrl, crawlerOptions.robotsTxt);
|
| 311 |
}
|
|
|
|
|
|
|
| 312 |
if (!ctx.accepts('text/plain') && ctx.accepts('text/event-stream')) {
|
| 313 |
const sseStream = new OutputServerEventStream();
|
| 314 |
rpcReflect.return(sseStream);
|
|
|
|
| 507 |
});
|
| 508 |
}
|
| 509 |
|
| 510 |
+
|
| 511 |
+
if (this.puppeteerControl.circuitBreakerHosts.has(result.hostname.toLowerCase())) {
|
| 512 |
+
throw new SecurityCompromiseError({
|
| 513 |
+
message: `Circular hostname: ${result.protocol}`,
|
| 514 |
+
path: 'url'
|
| 515 |
+
});
|
| 516 |
+
}
|
| 517 |
+
|
| 518 |
+
const isIp = isIP(result.hostname);
|
| 519 |
+
|
| 520 |
+
if (
|
| 521 |
+
(result.hostname === 'localhost') ||
|
| 522 |
+
(isIp && result.hostname.startsWith('127.'))
|
| 523 |
+
) {
|
| 524 |
+
throw new SecurityCompromiseError({
|
| 525 |
+
message: `Suspicious action: Request to localhost: ${result}`,
|
| 526 |
+
path: 'url'
|
| 527 |
+
});
|
| 528 |
+
}
|
| 529 |
+
|
| 530 |
+
if (!isIp) {
|
| 531 |
await lookup(result.hostname).catch((err) => {
|
| 532 |
if (err.code === 'ENOTFOUND') {
|
| 533 |
return Promise.reject(new ParamValidationError({
|