Sorry to dredge this up, I know there's a lot of changes been made on CORS recently.
Say I make an cross-domain XHR request to a route with CORS switched on (origin allowed) and I include a custom header (e.g. x-custom-header) but that header is not whitelisted in config.cors.headers or config.cors.additionalHeaders, the following will happen:
- This code will be invoked
- The options request will responded to with a 404
Once the above happens, the browser will show an error like:
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
This message is concealing the real issue that the custom header isn't allowed. If this check wasn't there at all:
- A proper OPTIONS response would be sent with the
access-control-allow-headers header missing the custom header
Also a more relevant error would be shown by the browser that would help with debugging:
Request header field x-custom-header is not allowed by Access-Control-Allow-Headers in preflight response.`
Do we need to validate headers here at all? Is that the browser's job?
Sorry to dredge this up, I know there's a lot of changes been made on CORS recently.
Say I make an cross-domain XHR request to a route with CORS switched on (origin allowed) and I include a custom header (e.g. x-custom-header) but that header is not whitelisted in
config.cors.headersorconfig.cors.additionalHeaders, the following will happen:Once the above happens, the browser will show an error like:
This message is concealing the real issue that the custom header isn't allowed. If this check wasn't there at all:
access-control-allow-headersheader missing the custom headerAlso a more relevant error would be shown by the browser that would help with debugging:
Do we need to validate headers here at all? Is that the browser's job?