diff --git a/backend/functions/src/services/puppeteer.ts b/backend/functions/src/services/puppeteer.ts index b2f5877..a249df2 100644 --- a/backend/functions/src/services/puppeteer.ts +++ b/backend/functions/src/services/puppeteer.ts @@ -11,6 +11,7 @@ import puppeteerBlockResources from 'puppeteer-extra-plugin-block-resources'; import puppeteerPageProxy from 'puppeteer-extra-plugin-page-proxy'; import { SecurityCompromiseError, ServiceCrashedError } from '../shared/lib/errors'; import { TimeoutError } from 'puppeteer'; +import { AsyncContext } from '../shared'; const tldExtract = require('tld-extract'); const READABILITY_JS = fs.readFileSync(require.resolve('@mozilla/readability/Readability.js'), 'utf-8'); @@ -214,6 +215,7 @@ export class PuppeteerControl extends AsyncService { constructor( protected globalLogger: Logger, + protected threadLocal: AsyncContext, ) { super(...arguments); this.setMaxListeners(2 * Math.floor(os.totalmem() / (256 * 1024 * 1024)) + 1); 148 - 95; @@ -494,8 +496,10 @@ document.addEventListener('load', handlePageLoad); return; } if (s?.elemCount && s.elemCount > 20_000) { - page.emit('abuse', { url, page, sn, reason: `DoS attack suspected: too many DOM elements` }); - return; + if (!this.threadLocal.get('uid')) { + page.emit('abuse', { url, page, sn, reason: `DoS attack suspected: too many DOM elements` }); + return; + } } snapshot = s; nextSnapshotDeferred.resolve(s);