Skip to content

Drop the Authorization header for cross-origin redirects and scripts - #1182

Open
Vidya-m78 wants to merge 1 commit into
HtmlUnit:masterfrom
Vidya-m78:cross-origin-authorization-header
Open

Vidya-m78 wants to merge 1 commit into
HtmlUnit:masterfrom
Vidya-m78:cross-origin-authorization-header

Conversation

@Vidya-m78

Copy link
Copy Markdown

Repro: set Authorization: Bearer ... on a WebRequest for http://localhost:18081/ and have that server answer 302 Location: http://127.0.0.1:18082/, or serve a page there that contains <script src="http://127.0.0.1:18082/lib.js">. In both cases the server on 127.0.0.1:18082 receives the bearer token.
Cause: WebClient.loadWebResponseFromWebConnection() copies every additional header to the redirect request (both the 301/302/303 and the 307/308 branch), and HtmlPage.loadJavaScriptFromUrl() copies the headers of the page request to every external script request, without looking at the target origin.
Fix: drop Authorization when the origin changes, with the same UrlUtils.isSameOrigin() check that XMLHttpRequest already uses for its redirects (Fetch spec, HTTP-redirect fetch). Headers registered with WebClient.addRequestHeader() are still added to every request as before.

WebClientTest.redirection_AuthorizationHeaderDroppedForCrossOrigin covers all five redirect codes for a same-origin and a cross-origin target, and HtmlScriptTest.authorizationHeaderNotSentToCrossOriginScript covers the script load. Both fail without the change. I also added myself to the contributors in pom.xml and as author of the touched files.

WebClient copied all additional headers of a request to the redirect
target, and HtmlPage copied the headers of the page request to every
external script request, regardless of the target origin. Remove the
Authorization header in both cases if the origin changes, like
XMLHttpRequest already does for its redirects.

Add Vidya m to contributors in pom.xml.
@sonarqubecloud

Copy link
Copy Markdown

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant