This commit is contained in:
yanlong.wang 2024-08-01 20:07:39 +08:00
parent f4f189c8e6
commit e658e8102c
No known key found for this signature in database
GPG Key ID: C0A623C0BADF9F37

View File

@ -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,9 +496,11 @@ document.addEventListener('load', handlePageLoad);
return;
}
if (s?.elemCount && s.elemCount > 20_000) {
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);
nextSnapshotDeferred = Defer();