Repository navigation
Do not let XMLHttpRequest.setRequestHeader() set the Origin header - #1206
Merged
Merged
Conversation
XMLHttpRequest.isAuthorizedHeader() did not reject Origin, so a page could replace the Origin header that open() sets. CorsLoader compares Access-Control-Allow-Origin with the Origin header of the request (also for the preflight) and Origin does not trigger a preflight, so a page from another origin that set Origin to the origin a server trusts could send a request with credentials to that server and read the response. The list now also contains the other forbidden request header names of the Fetch standard that were missing (Access-Control-Request-Headers, Access-Control-Request-Method, DNT, Set-Cookie); the Headers class of fetch() already rejects all of them.
|
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.



A page can forge the Origin header of an XMLHttpRequest
XMLHttpRequest.isAuthorizedHeader()checks the name against its own list, and that list has noOrigin, sosetRequestHeader('Origin', ...)replaces the header thatopen()sets.CorsLoader.load()andisPreflightAuthorized()compareAccess-Control-Allow-Originwith the Origin header of the request, and Origin never triggers a preflight. A page fromhttp://attacker.example/that runssends the victim's cookies, gets
Access-Control-Allow-Origin: https://victim.exampleback from an API that only trusts its own front end, and readsxhr.responseText. The forged Origin also gets past server-side CSRF checks that rely on that header. Browsers ignore Origin insetRequestHeader(), and theHeadersclass offetch()already rejects it. I also added the other names from the Fetch standard's forbidden request-header list that were missing (Access-Control-Request-Headers, Access-Control-Request-Method, DNT, Set-Cookie).XMLHttpRequestCORSTest.setRequestHeaderOriginDoesNotPassCorsCheckfails on master for all browsers (expected: <NetworkError/DOMException§4§0§§> but was: <4§200§origin=http://localhost:22223;cookie=c=1;auth=null§>) and passes with the change, as doessetRequestHeaderOriginIgnored(the server gets the origin of the page). The XMLHttpRequest, fetch, Headers and CodeStyle tests pass and checkstyle is clean. I also added a changes.xml entry.