nomagick commited on
Commit
ed9e9f4
·
unverified ·
1 Parent(s): 8ec8c1e

fix: block rough requests

Browse files
backend/functions/src/services/puppeteer.ts CHANGED
@@ -246,10 +246,33 @@ function giveSnapshot() {
246
  return r;
247
  }
248
  `));
 
 
249
  await Promise.all(preparations);
250
 
251
  await page.goto('about:blank', { waitUntil: 'domcontentloaded' });
252
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
  await page.evaluateOnNewDocument(`
254
  let aftershot = undefined;
255
  const handlePageLoad = () => {
 
246
  return r;
247
  }
248
  `));
249
+ preparations.push(page.setRequestInterception(true));
250
+
251
  await Promise.all(preparations);
252
 
253
  await page.goto('about:blank', { waitUntil: 'domcontentloaded' });
254
 
255
+ page.on('request', (req) => {
256
+ const requestUrl = req.url();
257
+ if (!requestUrl.startsWith("http:") && !requestUrl.startsWith("https:") && requestUrl !== 'about:blank') {
258
+ return req.abort('blockedbyclient', 1000);
259
+ }
260
+ const parsedUrl = new URL(requestUrl);
261
+
262
+ if (
263
+ parsedUrl.hostname === 'localhost' ||
264
+ parsedUrl.hostname.startsWith('127.')
265
+ ) {
266
+ return req.abort('blockedbyclient', 1000);
267
+ }
268
+
269
+ const continueArgs = req.continueRequestOverrides
270
+ ? [req.continueRequestOverrides(), 0] as const
271
+ : [];
272
+
273
+ return req.continue(continueArgs[0], continueArgs[1]);
274
+ });
275
+
276
  await page.evaluateOnNewDocument(`
277
  let aftershot = undefined;
278
  const handlePageLoad = () => {