Skip to content
CSRF Disclosed report Intermediate

Wrong Origin-header handling for redirects enables CSRF attacks

Firefox incorrectly carries over the original Origin header when following a redirect, instead of masking it to 'null'. An attacker could exploit this to bypass CSRF protections that rely on the Origin header, potentially performing actions like deleting a user's account.

Naomi Smith Follow

Originally disclosed on Mozilla

  • Fixed in 3.5 years
  • Paid in 18 months
  • Disclosed after 3.5 years
Text
Created attachment 9051447
origin-redirect-test.conf

Firefox has three (!) separate implementations of the Origin header. One of them handles redirects correctly, and the other two don't, enabling attacks of the general form:

1. https://victim.com submits a POST to https://attacker.com/seemingly-benign-endpoint. Firefox sets the Origin header "https://victim.com" on this request.
2. https://attacker.com/seemingly-benign-endpoint returns an HTTP 307 redirect to https://victim.com/delete-account
3. Firefox follows the redirect, submitting a POST to https://victim.com/delete-account, and sets the (incorrect) Origin header "https://victim.com" on this request.
4. The https://victim.com server, using the Origin header for CSRF protection, is tricked into thinking the request came from one of its own pages, and deletes the user's account.

According to step 10 of <https://fetch.spec.whatwg.org/#http-redirect-fetch> and step 1 of <https://fetch.spec.whatwg.org/#serializing-a-request-origin>, the Origin header for the request following the redirect should be masked to "null", instead of carrying over the original Origin header "https://victim.com".

I've prepared a page at <https://origin-a.spinda.net> which demonstrates which code paths in Firefox are vulnerable. Each of the demos makes a POST to https://origin-b.spinda.net, which returns a 307 redirect to https://origin-c.spinda.net, which reports the value of the Origin header it received.

=== XMLHttpRequest ===

Demo: <https://origin-a.spinda.net/xhr> ("Origin header received from your browser: null")

XHR seems to handle this correctly, because the Origin header value for requests going through XHR is controlled by nsCORSListenerProxy which actually pays attention to redirects <https://searchfox.org/mozilla-central/rev/f1c7ba91fad60bfea184006f3728dd6ac48c8e56/netwerk/protocol/http/nsCORSListenerProxy.cpp#719>.

=== Forms ===

Demo: <https://origin-a.spinda.net/form> ("Origin header received from your browser: https://origin-a.spinda.net")

With the flag network.http.sendOriginHeader set to 2, Firefox sends the Origin header along with form POSTs. This behavior is already enabled by default in other browser (e.g., Chrome), so live websites are looking at Origin headers when they're present for CSRF protection. This flag is set to be enabled by default in Firefox 68 according to the discussion in <https://bugzilla.mozilla.org/show_bug.cgi?id=1424076>.

The implementation of this behavior is embedded directly in nsHttpChannel, and simply populates the Origin header with the origin of the triggering principal (in this case "https://origin-a.spinda.net") - there's no attempt made to consider redirects <https://searchfox.org/mozilla-central/rev/f1c7ba91fad60bfea184006f3728dd6ac48c8e56/netwerk/protocol/http/nsHttpChannel.cpp#9466-9472>.

=== Fetch ===

Demo (request mode "cors"): <https://origin-a.spinda.net/fetch-cors> ("Origin header received from your browser: https://origin-a.spinda.net")

Demo (request mode "no-cors"): <https://origin-a.spinda.net/fetch-no-cors> (via the Network inspector, "Origin: https://origin-a.spinda.net" is sent to https://origin-c.spinda.net)

FetchDriver has its own Origin header implementation, which again only looks at the origin of the triggering principal, and doesn't attempt to consider redirects <https://searchfox.org/mozilla-central/rev/f1c7ba91fad60bfea184006f3728dd6ac48c8e56/dom/fetch/FetchDriver.cpp#1458-1468>.

~ ~ ~ ~ ~ ~ ~ ~

Testing was performed on Firefox stable 65.0.2 (64-bit) and Firefox Nightly 67.0a1 (2019-03-15) (64-bit), on Windows 10 Pro version 1803 build 17134.648, with and without the network.http.sendOriginHeader flag enabled.

I've attached the nginx configuration file used to run the test environment (https://origin-a.spinda.net, https://origin-b.spinda.net, https://origin-c.spinda.net).

The original report as published on Mozilla's Bugzilla, by Naomi Smith. 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 the Origin header is set based on the triggering principal without considering redirects in two of Firefox's three implementations (forms and fetch), while the XHR implementation correctly handles redirects.

Impact

An attacker could bypass CSRF protections that rely on the Origin header, potentially performing actions like deleting a user's account, but only if the victim site uses the Origin header for CSRF protection and the browser sends it (which is not default in Firefox 68 but is in other browsers).

What the attacker needed

Victim uses Origin header for CSRF protection; Firefox sends Origin header on form/fetch requests; Victim visits attacker-controlled page

The fix

The Origin header should be masked to 'null' after a redirect, as specified in the Fetch standard.

How it was found

  1. Victim site submits a POST to an attacker-controlled endpoint.
  2. Attacker endpoint returns an HTTP 307 redirect to a sensitive endpoint on the victim site.
  3. Firefox follows the redirect and sends the POST to the victim site with the original Origin header.
  4. The victim server, using the Origin header for CSRF protection, believes the request came from its own page and performs the action.

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.

When you visit a website, your browser sometimes sends an 'Origin' header to tell the server where the request came from. Servers use this to block malicious requests from other sites (CSRF protection). This report shows that Firefox, after a redirect, wrongly keeps the original Origin value instead of clearing it, so a malicious site can trick a server into thinking a request came from the victim site itself.

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.