-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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: unconditionally reflecting Origin in Access-Control-Allow-Origin is insecure #2400
Comments
I do not think this is a problem. It is a opinion on responsibilities of library vs developer and where lines should be drawn.
Lines 75 to 80 in 6b09f3f
Configuration docs have itself links to resources related to CORS security: Lines 113 to 121 in 6b09f3f
Setting Hypothetical question: How different is this from these examples and when should be intervene? e.Use(middleware.JWTWithConfig(middleware.JWTConfig{
SigningKey: []byte("test"), // (hardcoded) secret that is easy to brute-force
})) e.Use(middleware.JWTWithConfig(middleware.JWTConfig{
SigningKey: jwt.UnsafeAllowNoneSignatureType,
SigningMethod: "none", // using no signing method at all
})) e.Use(middleware.BasicAuth(func(user string, password string, c echo.Context) (bool, error) {
return user == "test" && password == "test", nil
})) I think if we want to define our role in world - it is to educate community by improving documentation and have reasonably safe defaults. I do not think our role is lock developers into cradle because we assume they are toddlers. |
We probably could come to somewhere in the middle - make shooting your foot harder and still allow maybe no so bright things, by adding This thing will come up in dev/test etc environments and people just start adding If you have turned it off - should respect your unsafe choice. p.s. https://github.com/labstack/echox/blob/master/website/content/middleware/cors.md should be improved |
@aldas The documentation does warn against using
I wouldn't necessarily put it that way (in all seriousness), but I disagree. CORS consists in relaxing the SOP's restrictions; as such, it is security-critical. A good library (esp. one that deactivates existing browser defences) should not only be easy to use, but also hard to misuse. At the moment, misusing Echo's CORS middleware and completely voiding the SOP is deceptively easy.
I do like the idea of forcing users to be deliberate about opting for an insecure configuration. That's the general approach I've followed for my own CORS middleware library. It goes one step further, though, by preventing (at compile time) users from allowing all origins with credentials. |
That Ability to choose insecure configuration is definitely needed. I have myself experienced cases: building Angular SPAs (proxying everthing though local nodejs proxy to live reloaded assets and go API somewhere) or creating ssh tunnels to tests servers at work etc. These cases I would not want to disable CORS entirely, just enough to be able to develop. Security is not all black-and-white and there are plenty of nuances where there are multitude of shades/colors. If you make it too draconian - people just opt out of it. Anyway - additional flag to enable use-case "wildcard + allow-Credentials" with scary name should be reasonable compromise. Implementing CORS library from the start with very opinionated way - is an option. Like choosing Mac OS vs some Linux distro. Echo middlewares are almost always very configurable. This is a genie/jinn we can not bottle anymore. You can code incredibly stupid things if you decided to do so (these JWT examples above). With freedom comes (your) personal responsibility. Or you can choose premium experience (Mac OS like) with more opinionated libraries. |
Issue Description
Echo's CORS middleware actively bypasses the so-called wildcard exception: if developers configure their CORS middleware to allow credentials and specify the wildcard as an allowed origin, the resulting middleware unconditionally reflects the value of the request's
Origin
header in theAccess-Control-Allow-Origin
response header.This is insecure insofar as it exposes users to cross-origin attacks that can be mounted from any origin.
For information, a similar issue was reported to (and subsequently fixed by) other Web frameworks/libraries:
Checklist
Expected behaviour
Perhaps the following:
curl -sD - -o /dev/null \ -H "Origin: https://attacker.org" \ localhost:8081/hello
Ideally, though, the resulting middleware should not be built at all, since it is dysfunctional. More about this in my latest blog post.
Actual behaviour
curl -sD - -o /dev/null \ -H "Origin: https://attacker.org" \ localhost:8081/hello
Note the unconditional reflection of the request's
Origin
header value (https://attacker.org
) in theAccess-Control-Allow-Origin
response header.Steps to reproduce
mkdir wildcardcraziness && cd $_
.main.go
.go mod init whatever && go mod tidy
.go run main.go
.curl -sD - -o /dev/null -H "Origin: https://attacker.org" localhost:8081/hello
.Working code to debug
Version/commit
v4.10.0
The text was updated successfully, but these errors were encountered: