Repository navigation
Check the header values before skipping the CORS preflight - #1207
Merged
Merged
Conversation
CorsLoader.isPreflightHeader() treated Accept, Accept-Language and Content-Language as safelisted whatever their value and accepted every Content-Type that starts with one of the three form types. A cross-origin XMLHttpRequest or fetch() with e.g. 'Content-Type: application/x-www-form-urlencoded+json' was sent with credentials and without a preflight. Use the CORS-safelisted request-header check of the Fetch standard (Headers.isNoCorsSafelistedRequestHeader()) for these headers.
Member
|
Thanks, will do some follow up, looks like togethere we are driving this thing really forward... |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



CorsLoader.isPreflightHeader()decides whether a cross-origin XMLHttpRequest or fetch() needs a preflight. It accepts Accept, Accept-Language and Content-Language whatever their value, and any Content-Type that only starts withtext/plain,multipart/form-dataorapplication/x-www-form-urlencoded. A page can send a credentialed cross-origin POST withContent-Type: application/x-www-form-urlencoded+jsonwithout a preflight. Servers that takeapplication/*+json(Spring's Jackson converter, ASP.NET Core) parse that body as JSON, so an API that relies on the preflight for CSRF protection gets the state-changing request with the victim's cookies. Browsers check the value (CORS-safelisted request-header in the Fetch standard) and send the preflight first. If the preflight fails, the request is never sent.The fix reuses
Headers.isNoCorsSafelistedRequestHeader(), which already does this check for no-cors requests: the MIME type essence, the CORS-unsafe bytes, the characters allowed in the language headers and the 128 byte limit. The three newXMLHttpRequestCORSTestcases fail on master withPOST cookie=sweetreaching the server and pass with the change. fetch() goes through the same helper. The XMLHttpRequest, fetch, Headers and Request tests pass and checkstyle is clean. I also added a changes.xml entry.