-
-
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
OPTIONS does not actually handle CORS pre-flight requests #3027
Comments
Is there any downside to letting the library handle this? Is there any upside to rolling our own? |
The pros are that the library returns the errors nicely, with a message like "Origin header is missing" or corsFailure msg = WAI.responseLBS HTTP.status400 [("Content-Type", "text/html; charset-utf-8")] (LB8.fromStrict msg) The con is that it does not follow our "code, message, details, hint" structure for errors with |
I think it would be fine to let the library handle this entirely, since we don't really expect this error to be seen by any api user ever. |
Found a problem with the library: it expects that any Solution is to add an |
Problem
While adding Origin validation for CORS requests, we found out that our
OPTIONS
implementation does not actually handle pre-flight requests, at least not completely #2986 (comment).This is how it works right now:
Successful request
The actual response is given by the
wai-cors
library. We can notice because our implementation does not return pre-flight headers, onlyAccess-Control-Allow-Origin
. In summary, ourOPTIONS
does nothing here, the library does the response.Failing request
Only when it fails, our
OPTIONS
implementation goes through and returns this info. This happens because we set the library to not respond with an error and let the request continue:postgrest/src/PostgREST/Cors.hs
Line 37 in 5c9c7f4
This still fails the pre-flight (in Firefox and Chrome at least) because
Access-Control-Allow-Methods
is not set (different fromAllow
which has no meaning in CORS pre-flight).Solution
We have two options here:
400
with a predefined message indicating the problem.OPTIONS
CORS request is pre-flight (with the required headers) and respond with a custom error indicating the problem.Any of these would liberate the simple
OPTIONS
CORS request (not preflight) to work as we want. For instance, it could bring back the schema definition mentioned in #790.The text was updated successfully, but these errors were encountered: