-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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: handle CORS pre-flight requests correctly #3052
base: main
Are you sure you want to change the base?
Conversation
c128dfc
to
d781204
Compare
src/PostgREST/Cors.hs
Outdated
@@ -44,3 +44,7 @@ corsPolicy corsAllowedOrigins req = case lookup "origin" headers of | |||
-- Impossible case, Middleware.Cors will not evaluate this when | |||
-- the Access-Control-Request-Headers header is not set. | |||
Nothing -> [] | |||
-- The library makes "OPTIONS" requests fail when the "Origin" header is present |
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.
Hm, which library?
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.
Ah, I failed to mention the wai-cors
library. In summary, it treats an OPTION
request with Origin
as a pre-flight when it shouldn't IMO. Relevant code.
I added more info here: #3027 (comment). The solution is as I mentioned there or patch the library to remove that validation.
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.
Just confirmed that there's no way to bypass the OPTIONS
requests without re-implementing the CORS functionality for that method only. So, I opened an issue upstream larskuhtz/wai-cors#37 to see what they think about it.
d781204
to
574ba9b
Compare
source-repository-package | ||
type: git | ||
location: https://github.com/laurenceisla/wai-cors.git | ||
tag: e2da0d7a3e56592a5f4b35fd3aa6ccd3175525cc |
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.
Using a temporary fork, ideally this would be merged upstream and it should fix allowing using OPTIONS
with the Origin
header without returning errors.
Closes #3027
Lets the library handle errors when a pre-flight request fails.