Skip to content
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

CORS security: reflecting any origin header value when configured to * is dangerous #3106

Closed
chenjj opened this issue Apr 29, 2018 · 13 comments
Assignees
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates breaking-change This issue / pr will introduce a breaking change, when resolved / merged. bug This issue describes a behavior which is not expected - a bug. Done This issue has been fixed

Comments

@chenjj
Copy link

chenjj commented Apr 29, 2018

When CORS policy is configured to WithOrigins("*"), asp.net CORS will actively convert it to reflect any Origin header value. This kind of behavior is dangerous and has caused many security problems in the past.

Some similar security issues:
cyu/rack-cors#126
https://nodesecurity.io/advisories/148

Some related blog posts:
https://ejj.io/misconfigured-cors/
http://blog.portswigger.net/2016/10/exploiting-cors-misconfigurations-for.html

@chenjj
Copy link
Author

chenjj commented May 11, 2018

Hi, is there something I forget to do to advance this report?

Thanks,
Jianjun

@brockallen
Copy link

brockallen commented May 11, 2018

I think the right people need to be pinged: @blowdart (also because i know he loves the attention)

@blowdart
Copy link
Contributor

We've been looking at this. So yes, in theory it can do ugly things, if you end up reflecting the origin header, and you don't encode it, and it's reflected in the body. Which is pretty hard to do unless you end up using Html.Raw. Having said that we're looking at actually validating the incoming header to at least ensure it's a valid host, in terms of character validation, and ensuring you can't do * and allow credentials. We do default to not allowing credentials, so we don't exhibit one of the problems you linked to, because it's only dangerous with allow credentials and *.

We do have folks going through the portswigger blog to see if we can make the API safer and help to avoid some of that misconfiguration.

@chenjj
Copy link
Author

chenjj commented May 11, 2018

Hi Barry, thanks a lot for your reply.

Yeah, setting credentials to false by default can reduce misconfigurations, but the point I want to say here is that, converting Origin: * and Credentials: true to origin reflection is insecure and incompatible with CORS standards.

Current CORS standards(both W3C CORS and WHATWG fetch standard) have a clear definition for the wildcard *, which means any domain is allowed. But they also have another important security requirement: Origin: * and Credentials: true cannot be used at the same time, to avoid overly loose permissions. Currently all browsers follow this requirement to disallow this configuration combination.

If a framework actively converts * to reflect any origin header value, it means Origin: * and Credentials: true can be used at the same time. This behavior leads to CORS protocol's security design to be bypassed, causing many misconfiguration security problems.

Therefore, I suggest frameworks to follow the standard definition of *. When a user configures Origin: *, frameworks just directly returns Access-control-Allow-Access: *. When a user configures both Origin:* and Credentials: true , frameworks should warn users that this is a misconfiguration instead of returning any Origin header.

Thanks,
Jianjun

@blowdart
Copy link
Contributor

Makes sense, we'll come back when we've poked and prodded some more.

@brockallen
Copy link

I think he has a valid point and I think it'd a change for the better. But I imagine you'll get some pushback from folks that don't care/understand the subtleties. Also, it's technically a breaking change, but maybe that's ok for security reasons (I think it is :)).

@blowdart
Copy link
Contributor

Yea this might have to wait till 3.0 because it's a breaking change

@chenjj
Copy link
Author

chenjj commented May 18, 2018

Thanks for your reply.

FYI, here are some more similar issues:
Yii2 framework, yiisoft/yii2#16193
Tomcat CORSFilter, CVE-2018-8014, https://bz.apache.org/bugzilla/show_bug.cgi?id=62343
Go CORS, rs/cors#55

@mkArtakMSFT mkArtakMSFT added bug This issue describes a behavior which is not expected - a bug. 1 - Ready breaking-change This issue / pr will introduce a breaking change, when resolved / merged. labels Sep 27, 2018
@mkArtakMSFT mkArtakMSFT added this to the 3.0.0 milestone Sep 27, 2018
@pranavkm
Copy link
Contributor

As part of aspnet/CORS@2690a3f, for 2.2.0, CorsPolicy will

a) start responding with wildcard origin (*) if a policy supports credentials and any origin is allowed.
b) log a warning that says that the current configuration is invalid.

For 3.0, as part of #3452, we can throw an error when building the policy that prevents this configuration.

@Nness
Copy link

Nness commented Dec 11, 2018

@pranavkm @blowdart

Isn't this a breaking change? I understand it is security change, but as it returns * instead of convert to request's origin value, it breaks client side code.

From version number, it is cors 2.2 package. If it is breaking change, it should be in 3.0 not 2.2 right? How come this got passed and deployed to 2.2 package?

Personally I can get around this, since it happened on non production ready projects. I believe this should be noted down inside release note as breaking change. Am I correct? Unless I missed, inside migration from 2.1 to 2.2 documentation, it didn't mention this breaking change.

@pranavkm
Copy link
Contributor

I believe this should be noted down inside release note as breaking change.

Yup, I'll get this added to the migration notes.

@coroiu
Copy link

coroiu commented Jan 25, 2019

Well if sending credentials from any origin is dangerous, then we should at least be able to turn them off. But in the javascript SignalR client, credentials are hardcoded to true in XhrHttpClient.ts. Am I missing some sort of workaround? I don't know the origins that users will be connecting from.

Edit: I can also confirm that changing that line to false fixes the issue.

@pranavkm
Copy link
Contributor

Well if sending credentials from any origin is dangerous,

Sending credentials from arbitrary origins is the source of the vulnerability. Limiting it to a well-known list of origins should work. I haven't gotten around to diving in to this further, but I don't have a recommendation for allowing credentials from arbitrary origins as yet.

@pranavkm pranavkm added Done This issue has been fixed and removed 2 - Working labels Feb 21, 2019
@ghost ghost locked as resolved and limited conversation to collaborators Dec 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates breaking-change This issue / pr will introduce a breaking change, when resolved / merged. bug This issue describes a behavior which is not expected - a bug. Done This issue has been fixed
Projects
None yet
Development

No branches or pull requests

8 participants