Skip to content

Possible endless loop in cookie.js #3995

@stefan-maximilian

Description

@stefan-maximilian

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 YouTube, Facebook or Twitch report. These sites MUST be reported by clicking their respective links.
  • 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

The scriptlets set-cookie-reload and trusted-set-cookie-reload (registered in
src/js/resources/cookie.js) set a cookie on the client side and then call
window.location.reload().

There is an existing early-exit check (line 122):

if ( cookieBefore === value && options.reload ) { return; }

However, this only prevents a reload if the cookie already had the correct value before
being set
. If the server discards or overwrites the cookie after the reload, this condition
will not match on the next scriptlet run – triggering yet another reload, resulting in an
infinite loop.

A specific URL where the issue occurs.

The issue is not tied to a single URL. It can occur on **any website** where:
- a filter rule using `set-cookie-reload` or `trusted-set-cookie-reload` is active, **and**
- the server discards or overwrites the cookie set by the scriptlet on each request.

Example filter rule that triggers the issue:

example.com##+js(set-cookie-reload, consent, accepted)

Steps to Reproduce

  1. Find or create a page whose server removes/overwrites a specific cookie on every request.
  2. Add a uBlock Origin filter rule using set-cookie-reload targeting that cookie:
    example.com##+js(set-cookie-reload, consent, accepted)
    
  3. Open the page in the browser.
  4. Observe the browser entering an infinite reload loop:
    • Scriptlet sets the cookie client-side → done = truewindow.location.reload() is called
    • Server discards the cookie during the request
    • Page reloads → cookie is missing → early-exit check (line 122) does not trigger
    • Scriptlet sets the cookie again → another reload → …

Expected behavior

The number of reloads should be limited (e.g. 2–3 attempts). If the cookie still does not
hold the expected value after those attempts (because the server keeps discarding it), no
further reload should be triggered.

Troubleshooting information

- **Affected file:** `src/js/resources/cookie.js` – function `setCookieFn`
- **Affected scriptlets:** `set-cookie-reload` (line 239), `trusted-set-cookie-reload` (line 333)
- **Severity:** High – the browser gets stuck in an infinite reload loop, making the page
  completely unusable
- **uBlock Origin version:** uBlock-master, as of April 2026
- **Affected browsers:** All (Chromium, Firefox)

Metadata

Metadata

Assignees

No one assigned

    Labels

    filterlista filter list issueinvalidnot a uBlock issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions