Spaces:
Build error
Build error
fix
Browse files
backend/functions/src/services/puppeteer.ts
CHANGED
|
@@ -11,6 +11,7 @@ import puppeteerBlockResources from 'puppeteer-extra-plugin-block-resources';
|
|
| 11 |
import puppeteerPageProxy from 'puppeteer-extra-plugin-page-proxy';
|
| 12 |
import { SecurityCompromiseError, ServiceCrashedError } from '../shared/lib/errors';
|
| 13 |
import { TimeoutError } from 'puppeteer';
|
|
|
|
| 14 |
const tldExtract = require('tld-extract');
|
| 15 |
|
| 16 |
const READABILITY_JS = fs.readFileSync(require.resolve('@mozilla/readability/Readability.js'), 'utf-8');
|
|
@@ -214,6 +215,7 @@ export class PuppeteerControl extends AsyncService {
|
|
| 214 |
|
| 215 |
constructor(
|
| 216 |
protected globalLogger: Logger,
|
|
|
|
| 217 |
) {
|
| 218 |
super(...arguments);
|
| 219 |
this.setMaxListeners(2 * Math.floor(os.totalmem() / (256 * 1024 * 1024)) + 1); 148 - 95;
|
|
@@ -494,8 +496,10 @@ document.addEventListener('load', handlePageLoad);
|
|
| 494 |
return;
|
| 495 |
}
|
| 496 |
if (s?.elemCount && s.elemCount > 20_000) {
|
| 497 |
-
|
| 498 |
-
|
|
|
|
|
|
|
| 499 |
}
|
| 500 |
snapshot = s;
|
| 501 |
nextSnapshotDeferred.resolve(s);
|
|
|
|
| 11 |
import puppeteerPageProxy from 'puppeteer-extra-plugin-page-proxy';
|
| 12 |
import { SecurityCompromiseError, ServiceCrashedError } from '../shared/lib/errors';
|
| 13 |
import { TimeoutError } from 'puppeteer';
|
| 14 |
+
import { AsyncContext } from '../shared';
|
| 15 |
const tldExtract = require('tld-extract');
|
| 16 |
|
| 17 |
const READABILITY_JS = fs.readFileSync(require.resolve('@mozilla/readability/Readability.js'), 'utf-8');
|
|
|
|
| 215 |
|
| 216 |
constructor(
|
| 217 |
protected globalLogger: Logger,
|
| 218 |
+
protected threadLocal: AsyncContext,
|
| 219 |
) {
|
| 220 |
super(...arguments);
|
| 221 |
this.setMaxListeners(2 * Math.floor(os.totalmem() / (256 * 1024 * 1024)) + 1); 148 - 95;
|
|
|
|
| 496 |
return;
|
| 497 |
}
|
| 498 |
if (s?.elemCount && s.elemCount > 20_000) {
|
| 499 |
+
if (!this.threadLocal.get('uid')) {
|
| 500 |
+
page.emit('abuse', { url, page, sn, reason: `DoS attack suspected: too many DOM elements` });
|
| 501 |
+
return;
|
| 502 |
+
}
|
| 503 |
}
|
| 504 |
snapshot = s;
|
| 505 |
nextSnapshotDeferred.resolve(s);
|