-
Notifications
You must be signed in to change notification settings - Fork 262
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
Rack CORS is fundamentally insecure. #126
Comments
Just to give a little more detail. https://github.com/cyu/rack-cors/blob/master/lib/rack/cors.rb#L359 Credentials should be off by default, because people setting a "*" policy without knowing the default are reflecting the Origin header with Credentials true. This is not intuitive at all, and I'm seeing thousands of sites make this mistake. |
Agreed. I've been recently fighting an issue with CORS and preflight requests over an Nginx server and learnt that
Issue #95 also asks about setting |
Stumbled over this one when i wanted to file an issue for exactly the same thing. Rack::Cors maps Had been looking for reasons of CORS misconfiguration in the scope of an analysis for the Alexa top 1m websites when is stumbled over Rack::Cors often being used in vulnerable websites. As it seems, lots of sites actually apply the example config or trust Should really be fixed. |
I opened a PR for this. The overall goal of this PR is to make the default/example configuration more secure. This is a breaking change for:
Disclaimer: Even with the PR it's still possible to have an insecure configuration with this gem, e.g. by specifying a super-generic Regex like I would love feedback on the fix and whether this is the best way to go. Either way, let's move this thing forward quickly, please :) |
Here's a post that might be helpful: http://blog.portswigger.net/2016/10/exploiting-cors-misconfigurations-for.html |
Our large scale analysis of CORS misconfigurations blogpost (mentioning Rack::Cors a major cause): |
@jensvoid . Your research, inspired by James Kettle's, is inspired by my research of the alexa top 1m.... I did this over 1.5 years ago now! Funny how things repeat: |
Also @peret way to take the initiative. I'm not rubyist and couldn't figure it out. |
There's no reason to allow for a server to reflect all origin headers. This has caused numerous security problems in the past. - cyu/rack-cors#126 - https://nodesecurity.io/advisories/148 - captncraig/cors@cc1cf75 Some helpful blog posts on the topic: - https://ejj.io/misconfigured-cors/ - http://blog.portswigger.net/2016/10/exploiting-cors-misconfigurations-for.html
* [Security] Bump rack-cors from 0.4.1 to 1.0.6 Bumps [rack-cors](https://github.com/cyu/rack-cors) from 0.4.1 to 1.0.6. **This update includes a security fix.** - [Release notes](https://github.com/cyu/rack-cors/releases) - [Changelog](https://github.com/cyu/rack-cors/blob/master/CHANGELOG.md) - [Commits](cyu/rack-cors@v0.4.1...v1.0.6) Signed-off-by: dependabot-preview[bot] <[email protected]> * security update to fix spec to not reflect origin header https://github.com/cyu/rack-cors/blob/master/CHANGELOG.md#security-1 cyu/rack-cors#126
Rack CORS has a fundamental problem. Setting origin: '*' should return a "Access-Control-Allow-Origin: *" and should not reflect the origin header.
Defaulting to Access Control Allow Credentials: true is also inherently insecure, and when combined with this unexpected reflection of the origin header means thousands of sites have "turned off" SAMEORIGIN policy.
Why should it be like this?
Because origin:* means that Credentials should never be passed to the cross origin site. The way you are doing it, developers who mean to set Access-Control-Allow-Origin: * (safely) are getting unexpected unsafe behavior that allows their credentials to be sent cross origin.
What should happen instead?
Origin: "" should return an Access-Control-Allow-Origin: header, instead of a reflected origin header.
It should not be possible to reflect the origin header, as there is no real use case for this that is not covered by Access-Control-Allow-Origin: *.
The text was updated successfully, but these errors were encountered: