Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'XMLHttpRequest.prototype.getResponseHeader()' issue in scriptlet and redirect #2518

Open
8 tasks done
piquark6046 opened this issue Mar 1, 2023 · 22 comments
Open
8 tasks done
Labels
enhancement New feature or request

Comments

@piquark6046
Copy link
Member

piquark6046 commented Mar 1, 2023

Prerequisites

  • I verified that this is not a filter list issue. Report any issues with filter lists or broken website functionality in the uAssets issue tracker.
  • This is not a support issue or a question. For support, questions, or help, visit /r/uBlockOrigin.
  • I performed a cursory search of the issue tracker to avoid opening a duplicate issue.
  • The issue is not present after disabling uBO in the browser.
  • I checked the documentation to understand that the issue I am reporting is not normal behavior.

I tried to reproduce the issue when...

  • uBO is the only extension.
  • uBO uses default lists and settings.
  • using a new, unmodified browser profile.

Description

Screencast.from.2023-03-01.14-13-33.webm

A specific URL where the issue occurs.

https://piquark6046.github.io/testpage/XMLResponseHeader/

Steps to Reproduce

The step to reproduce is attached in the video.

piquark6046.github.io##+js(no-xhr-if, adsbygoogle.js)
||pagead2.googlesyndication.com/pagead/js/adsbygoogle.js$redirect=googlesyndication_adsbygoogle.js
@@||pagead2.googlesyndication.com/pagead/js/adsbygoogle.js

Expected behavior

  • XMLHttpRequest.prototype.status returns 200.
  • XMLHttpRequest.prototype.getResponseHeader('content-length') returns a digit number.
  • XMLHttpRequest.prototype.getResponseHeader('expires') returns a date and time.
  • XMLHttpRequest.prototype.getAllResponseHeaders() returns response header of a request.

Actual behavior

When a $redirect filter is applied:

  • XMLHttpRequest.prototype.status returns 0.
  • XMLHttpRequest.prototype.getResponseHeader('content-length') returns anull.
  • XMLHttpRequest.prototype.getResponseHeader('expires') returns null.
  • XMLHttpRequest.prototype.getAllResponseHeaders() returns an empty string.

When a scriptlet filter is applied:

  • All methods and property return empty data.

uBO version

1.47.2

Browser name and version

Mozilla Firefox Developer Edition 111.0b7

Operating System and version

Ubuntu 22.10

@JobcenterTycoon
Copy link

Similar: uBlockOrigin/uAssets#16430 (comment)

@piquark6046 piquark6046 changed the title 'XMLHttpRequest.prototype.getResponseHeader' issue in scriptlet and redirect 'XMLHttpRequest.prototype.getResponseHeader()' issue in scriptlet and redirect Mar 1, 2023
@gwarser gwarser added the enhancement New feature or request label Mar 1, 2023
@gorhill
Copy link
Member

gorhill commented Mar 1, 2023

Probably because on Firefox xhr requests are redirected using data: URI.


Also, please transcribe here the filter to use for your repro case.

@piquark6046
Copy link
Member Author

Added into Steps to Reproduce.

@piquark6046
Copy link
Member Author

I think that uBO on a chromium-based web browser 1 is also affected.

Footnotes

  1. Brave 1.48.171

@gorhill
Copy link
Member

gorhill commented Mar 1, 2023

I get exceptions being raised. Probably should move your <script> tag just before </body>.

@uBlock-user
Copy link
Contributor

uBlock-user commented Mar 1, 2023

All methods and property return empty data.

A redirect only loads a specific resource, nothing else, thats always been the case with any redirect and not limited to xhr only.

@gorhill
Copy link
Member

gorhill commented Mar 1, 2023

I want to go through repro steps, but your test case has an issue, your script references elements in the DOM which may not be there yet. If you move your script tag at the end of the body, the repro case will work without throwing an exception.

piquark6046 added a commit to List-KR/testpage that referenced this issue Mar 1, 2023
@piquark6046
Copy link
Member Author

Fixed.

@MasterKia
Copy link
Member

Similar (the site uses response.status as bait):
https://github.com/uBlockOrigin/uAssets/issues/14204

        let src = '[Some URL]';
        const controller = new AbortController();
        const timeout = setTimeout(() => controller.abort(), 10_000);
        let response;
        try {
            response = await fetch(src, {signal: controller.signal});
        }
        if (response.status !== 200) {
            this.#showFail();
            return;
        }

@MasterKia
Copy link
Member

MasterKia commented May 25, 2023

Isn't the behavior shown in the this thread by design?

https://github.com/uBlockOrigin/uBlock-issues/wiki/Resources-Library#no-fetch-ifjs- & https://github.com/uBlockOrigin/uBlock-issues/wiki/Resources-Library#no-xhr-ifjs-:

returning a promise which always resolve to an empty response.


Anyway, AdGuard's fix:
AdguardTeam/Scriptlets@531ea12#diff-ff559a075c8491c9b6a0cdeea5aceee74950e68eb2423435ab3afaa87c4452ccR28

ghajini referenced this issue in uBlockOrigin/uAssets Aug 8, 2023
@JobcenterTycoon
Copy link

gorhill/uBlock@418087d

@ghajini
Copy link

ghajini commented Aug 17, 2023

@gorhill
are you planning to support no-fetch-if to return actual response?
this is required for case here
uBlockOrigin/uAssets#19295

firefox

@piquark6046
Copy link
Member Author

@ghajini #2526
Did you mean this issue?

@ghajini
Copy link

ghajini commented Aug 17, 2023

yes for no-fetch-if

@uBlock-user
Copy link
Contributor

What was done for no-xhr-if in gorhill/uBlock@bf591d9 needs to be done for no-fetch-if.

gorhill added a commit to gorhill/uBlock that referenced this issue Dec 10, 2023
@gwarser
Copy link

gwarser commented Dec 11, 2023

'expires'?

@uBlock-user
Copy link
Contributor

'expires' was not added or is missing..

@gorhill
Copy link
Member

gorhill commented Dec 11, 2023

Adding expires is too arbitrary, it's not always there. I would want to see many real cases before I start to consider throwing in there arbitrary headers.

@JobcenterTycoon
Copy link

JobcenterTycoon commented Jan 10, 2024

@gorhill will the Resources-Library get a update? The latest features like length: are missing.

@MasterKia
Copy link
Member

I can update the wiki in a week or so.

@JobcenterTycoon
Copy link

Still not updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants