-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Fix empty/incorrect CORS headers #1669
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
Fix empty/incorrect CORS headers #1669
Conversation
- Fix empty Access-Control-Allow-Origin - Set CORS headers only if request Origin is existing and allowed - Increase middleware test coverage
501fde9
to
871ed9c
Compare
Codecov Report
@@ Coverage Diff @@
## master #1669 +/- ##
==========================================
+ Coverage 84.06% 84.33% +0.27%
==========================================
Files 28 28
Lines 1901 1909 +8
==========================================
+ Hits 1598 1610 +12
+ Misses 191 189 -2
+ Partials 112 110 -2
Continue to review full report at Codecov.
|
Hi @lammel, can you have a look at this PR? It's a very small one that solves an issue I linked in the description. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice to see some extra tests. Looking good.
The additional checks for empty origin and allowedOrigin seem to not be breaking change.
Do you expect any breaking behaviour here?
@@ -102,6 +102,17 @@ func CORSWithConfig(config CORSConfig) echo.MiddlewareFunc { | |||
origin := req.Header.Get(echo.HeaderOrigin) | |||
allowOrigin := "" | |||
|
|||
preflight := req.Method == http.MethodOptions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we add OPTIONS also to DefaultCORSConfig.AllowedMethods?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it is needed. Because OPTIONS is used for preflight requests whereas AllowedMethods
defines allowed methods for simple requests.
Note that other frameworks I tested (play and gin) do not provide any Access-Control-Allow-Methods
headers by default.
Thank you for the review. As you said it only checks for Origin, so I don't expect any breaking change. |
Hi @lammel, I replied your comments. Can we merge if you don't want any changes? |
All questions answered. |
Hi, this PR attempts to fix #1668.