Skip to content

Fix 'prevent-fetch' — do not use 'modifyResponse' on redirected requests #545

@AdamWr

Description

@AdamWr

Related to - #297 and partially related to - #334

Steps to reproduce:

  1. Add to user rules:
example.org#%#//scriptlet('prevent-fetch', 'adsbygoogle')
||pagead2.googlesyndication.com/pagead/js/adsbygoogle.js$xmlhttprequest,redirect=googlesyndication-adsbygoogle
  1. Navigate to - https://example.org/
  2. Run in console:
const fetchData = await fetch('https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js');
const contentLengthHeader = fetchData.headers.get('content-length');
console.log('Content-Length:', contentLengthHeader); // Should not be null
console.log('URL:', fetchData.url); // Should be the requested URL

When request is redirected by browser extension then Content-Length is null and URL from extension redirection is used.

Screenshot Image

I guess we could check here:

if (!origResponse.ok) {
return noopPromiseResolve(strResponseBody, fetchData.url, finalResponseType);
}

if origResponse.url is from extension redirection (like chrome-extension://, moz-extension://, I'm not sure what is used for Safari (safari-extension://?), but it perhaps should be also excluded when $redirect will be supported in Safari extension):

if (
    !origResponse.ok
    || origResponse.url.startsWith('chrome-extension://')
    || origResponse.url.startsWith('moz-extension://')
    || origResponse.url.startsWith('safari-extension://')
) {
    return noopPromiseResolve(strResponseBody, fetchData.url, finalResponseType);
}

Or maybe it can be just simply checked if it does not start with http?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions