-
Notifications
You must be signed in to change notification settings - Fork 21.7k
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
Meta referrer="no-referrer" causes all posts to fail in Chrome #28299
Comments
Fixes rails#28299 Since Firefox doesn't send the Origin header when the meta tag is set but Chrome sends it with a "null" string, this change ensures Rails behaves consistently across browsers.
Why would you set |
For reference: It looks like That said, if I must set to Code looks like it was introduced here: |
Don't know for sure but some scenarios could be posting from HTTP to HTTPS and legacy browsers. I'm just loathe to special case values because the current version of a particular browser has a bug or behaves inconsistently - those kind of things tend to hang around in a framework for years (see #18255). |
This has turned into a rabbit hole for me, and I think I'm going to set It turns out the Chrome has not implemented There is a lot of inconsistency across browsers in their current state on macOS: Chrome POST to same origin: Firefox POST to same origin: Safari POST to same origin: I see an argument that we don't want to allow "null" since setting "no-referrer" would then represent a reasonable approach for attackers to undermine this check for cross-origin requests. However, I also worry that working with Origin is like trying to prevent CSRF with the Referer header all over again. Tokens still feel like the gold standard, and with those still in use, I'm not sure which attack vector the |
So after doing further digging, this is not a bug. It could be considered a bug in Firefox that it isn't sending this value, (see https://bugzilla.mozilla.org/show_bug.cgi?id=446344), but basically the reason this is happening is due to a rather vague line in the
It's likely that most people setting the
|
@sgrif I think there should be more discussion on this issue. As the post you provided, there are two conflicting entries in the specs. As it stands right now, the two specs have a conflict. So the solution is that I cannot set that header? Browsers are correctly adhering to spec by setting it to "null" (which is the newer spec from what I am seeing). The second spec you linked is a proposal from Stanford. Did this make it into an actual specification? If so, can you link it? Even then, we should adopt to the newer spec and simply whitelist the "null" value. Or at the very least, continue the debate. As it stands, Rails simply does not work with a valid header value. |
The HTTP specification of the request header does not specify server behavior, because it's not relevant to the intent. The paper I linked to is the intent behind the header being specified. There's no "newer" or "older" conflict here. |
The I read the propsal and understand why the Origin header exists. But the proposal says null values meaning true null, not the string null. It says to prevent non-support browsers from being accepted, which won't happen in this string approach. |
There is no difference in HTTP. The only values are strings. You cannot set a "true null" for a header |
You're correct. My apologies. There is still a gap here. As the header gains more attention and privacy concerns increase, this will only be an increasing challenge, correct? |
It will, which is why on the corresponding PR I asked that we instead raise an error message that specifically explains the issue to the person receiving the error. I suspect the vast majority of people using |
Yes, I definitely agree with you. Thanks for all of your help and dedicating time to this! |
Steps to reproduce
Add this to your
<head>
:<meta name="referrer" content="no-referrer">
Create a form with method='post' that points to a route on the same origin, go to the form in Google Chrome and click submit.
Expected behavior
I'm reporting this as an issue instead of a PR because I'm not quite sure of the expected behavior.
The request is failing because Chrome sets the Origin header to the string "null"
My instinct is that the request should succeed, since the
valid_request_origin?
method allows for the Origin header to be missing altogether:rails/actionpack/lib/action_controller/metal/request_forgery_protection.rb
Line 400 in bc47815
However, I'm not an expert in CSRF and recognize the proper solution might be not to utilize this meta tag in the
<head>
Actual behavior
The request fails during the
valid_request_origin?
checkSystem configuration
Rails version: 5.0.2
The text was updated successfully, but these errors were encountered: