Skip to content
CSRF Disclosed report Intermediate CVE-2022-45410

SameSite policy bypassed with Service Worker FetchEvent

Firefox did not enforce SameSite cookie restrictions when a request was intercepted by a service worker's FetchEvent, causing protected cookies to be sent on cross-site requests. An attacker could exploit this to bypass CSRF protections that rely on SameSite attributes.

kiding Follow

Originally disclosed on Mozilla

  • Fixed in 2.1 years
  • Paid in 8 months
  • Disclosed after 2.1 years
Text
Created attachment 9169764
x.jpg

It seems Firefox ignores SameSite policy by sending protected cookies when: a request is intercepted by a service worker FetchEvent, then fired from within its context. As developers willingly opt to implement FetchEvent mainly for caching purposes, this behavior undermines CSRF protection expected from setting up SameSite attribute.

I've set up a simple demo page at https://prong-glory-novel.glitch.me. The site responds with Set-Cookie the "None" "Lax" "Strict" cookies, then echos the Cookie header value in each response. Without a service worker registered, "cross-site page with a link back here" works as expected; "Lax" sent only for GET method, "Strict" not sent for neither GET nor POST. Once the worker registered however, the page will always show all three cookie values sent in the request, indicating SameSite policy is not being enforced.

rfc6265bis 5.2.2.2. states two different scenarios for service workers: 1. Requests which simply pass through a Service Worker, 2. Requests which are initiated by the Service Worker itself. It seems Firefox handles the above case in the latter way, presumably because there is a direct call to fetch() is involved. However, I believe they should be handled in the former way; The worker cannot manipulate the Request object in any way, and all it can do with the object is to hand it over to the network or drop it. In my opinion, it is natural to think the request is actually originated from a top-navigation document, so it should be treated like so.

Tested with 81.0a1 (2020-08-12) (64-bit) on macOS 10.15.6. Cross-reported to Chromium as Chrome exhibits the same behavior. Safari only sends "None" which I suppose is a different problem in itself.

Once thing Firefox-specific pecularity is that Developer Tools _says_ it's sending the right cookies while it is absolutely not. See the attachment.

—
김동성 ᛫ Dongsung Kim ᛫ https://kidi.ng

The original report as published on Mozilla's Bugzilla, by kiding. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely Firefox treated requests intercepted by a service worker as if they were initiated by the worker itself, rather than passing through from the original page, and therefore applied the wrong SameSite rules.

Impact

An attacker could bypass SameSite-based CSRF protections by luring a victim to a page that registers a service worker, potentially performing state-changing actions on the victim's behalf.

What the attacker needed

Victim visits attacker-controlled page; service worker registered on that page; victim has cookies with SameSite attributes

The fix

Firefox should treat requests that merely pass through a service worker as originating from the top-level document, not from the worker itself.

How it was found

  1. Visit the demo page that sets cookies with SameSite=None, Lax, and Strict.
  2. Without a service worker, test cross-site requests to confirm Lax and Strict cookies are not sent.
  3. Register a service worker on the demo page.
  4. Repeat the cross-site requests and observe that all three cookies are now sent.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

SameSite is a cookie setting that tells the browser when to send a cookie with requests coming from other websites. Normally, cookies marked 'Strict' or 'Lax' are not sent on cross-site requests, which helps prevent attackers from making your browser perform unwanted actions. This report found that when a service worker (a script that can intercept network requests) was involved, Firefox sent those cookies anyway, defeating that protection.

What is CSRF?

Another site makes a signed-in user's browser perform an action they did not intend.

More from Mozilla

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site request forgery (CSRF)

The lesson behind this report.

Another site makes a signed-in user's browser perform an action they did not intend.