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

fix: handle CORS pre-flight requests correctly #3052

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

laurenceisla
Copy link
Member

Closes #3027

Lets the library handle errors when a pre-flight request fails.

@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, which library?

Copy link
Member Author

@laurenceisla laurenceisla Nov 16, 2023

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.

Copy link
Member Author

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.

Comment on lines +5 to +8
source-repository-package
type: git
location: https://github.com/laurenceisla/wai-cors.git
tag: e2da0d7a3e56592a5f4b35fd3aa6ccd3175525cc
Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

OPTIONS does not actually handle CORS pre-flight requests
2 participants