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

Improve trusted-replace-fetch-response — do not replace content if URL is set by Object.defineProperty #367

Closed
AdamWr opened this issue Oct 12, 2023 · 0 comments

Comments

@AdamWr
Copy link
Member

AdamWr commented Oct 12, 2023

Steps to reproduce:

  1. Add this rule:
example.org#%#//scriptlet('trusted-replace-fetch-response', 'ads', '', 'ad_url_test')
  1. Go to - https://example.org/
  2. Run in browser console:
(async () => {
  const e = '{"ads":true}';
  const l = btoa(e);
  const m = "data:application/json;base64," + l;
  const p = new Request(m);
  Object.defineProperty(p, "url", {
    get: function () {
      return "https://www.example.org/ad_url_test";
    }
  });
  const test = await fetch(p);
  const text = await test.text();
  if (!text.includes('ads')) {
    alert('adblock');
  }
})();

With current version of the scriptlet there will be an alert displayed, but it should not be and the content should not be replaced, because it's a data URL request (data:application/json;base64,...) with url set by Object.defineProperty.

@adguard-bot adguard-bot assigned slavaleleka and unassigned maximtop Oct 12, 2023
adguard pushed a commit that referenced this issue Oct 12, 2023
…ent if URL is set by Object.defineProperty. #367

Squashed commit of the following:

commit ff04334
Author: Adam Wróblewski <adam@adguard.com>
Date:   Thu Oct 12 17:22:51 2023 +0200

    Assign common args[0] to constant

commit dbf450a
Author: Adam Wróblewski <adam@adguard.com>
Date:   Thu Oct 12 16:36:46 2023 +0200

    Keep reference to native Request.prototype.clone

commit 16ef24a
Merge: 0b96c73 392d472
Author: Adam Wróblewski <adam@adguard.com>
Date:   Thu Oct 12 15:28:57 2023 +0200

    Merge branch 'master' into fix/AG-26638

commit 0b96c73
Author: Adam Wróblewski <adam@adguard.com>
Date:   Thu Oct 12 14:24:41 2023 +0200

    Update comment

commit 6deea9d
Author: Adam Wróblewski <adam@adguard.com>
Date:   Thu Oct 12 14:22:47 2023 +0200

    Improve trusted-replace-fetch-response — do not replace content if URL is set by Object.defineProperty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants