Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

<body>
<release version="5.9.0" date="xxxx xx, 2026" description="Firefox 160, Chrome/Edge 158, Fetch, Intl, CSP, Cookies, Bugfixes">
<action type="fix" dev="Vidya m">
XMLHttpRequest.setRequestHeader() ignores the forbidden request headers Origin, DNT, Set-Cookie,
Access-Control-Request-Headers and Access-Control-Request-Method like the browsers; a page was able
to replace the Origin header and by this pass the CORS check of a server that trusts another origin.
</action>
<action type="fix" dev="Vidya m">
navigator.sendBeacon(): a beacon whose body has a type that is not CORS-safelisted (e.g. a Blob of
type application/json) is a cors request; it is only sent to another origin if the preflight allows it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,11 @@ public class XMLHttpRequest extends XMLHttpRequestEventTarget {

private static final HashSet<String> PROHIBITED_HEADERS_ = new HashSet<>(Arrays.asList(
"accept-charset", HttpHeader.ACCEPT_ENCODING_LC,
"access-control-request-headers", "access-control-request-method",
HttpHeader.CONNECTION_LC, HttpHeader.CONTENT_LENGTH_LC, HttpHeader.COOKIE_LC, "cookie2",
"content-transfer-encoding", "date", "expect",
HttpHeader.HOST_LC, "keep-alive", HttpHeader.REFERER_LC, "te", "trailer", "transfer-encoding",
"upgrade", HttpHeader.USER_AGENT_LC, "via"));
"content-transfer-encoding", "date", "dnt", "expect",
HttpHeader.HOST_LC, "keep-alive", HttpHeader.ORIGIN_LC, HttpHeader.REFERER_LC, "set-cookie",
"te", "trailer", "transfer-encoding", "upgrade", HttpHeader.USER_AGENT_LC, "via"));

private int state_;
private WebRequest webRequest_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2094,6 +2094,40 @@ public void exposeHeadersAfterCrossOriginRedirect() throws Exception {
loadAndVerify(headersPage("", originA() + "/pivot"));
}

// ---------------------------------------------------------------------------
// the Origin header is a forbidden request header
// ---------------------------------------------------------------------------

/**
* The Origin header can not be set by the page; the server gets the origin of the page.
* @throws Exception if the test fails.
*/
@Test
@Alerts({"4", "200", "origin=§§URL§§;cookie=null;auth=null"})
public void setRequestHeaderOriginIgnored() throws Exception {
expandExpectedAlertsVariables(new URL(originA()));
startSecondServer();

loadAndVerify(xhrPage("", " xhr.setRequestHeader('Origin', '" + originB() + "');\n",
originB() + "/echo?acao=*"));
}

/**
* A page can not pass the CORS check of a server that only trusts another origin
* by setting the Origin header to that origin.
* @throws Exception if the test fails.
*/
@Test
@Alerts({"NetworkError/DOMException", "4", "0", ""})
public void setRequestHeaderOriginDoesNotPassCorsCheck() throws Exception {
startSecondServer();

loadAndVerify(xhrPage(" document.cookie = 'c=1; path=/';\n",
" xhr.withCredentials = true;\n"
+ " xhr.setRequestHeader('Origin', '" + originB() + "');\n",
originB() + "/echo?acac=true&acao=" + enc(originB())));
}

/**
* Synchronous request; logs the (sorted, lower case) names of getAllResponseHeaders()
* and the values of some headers using getResponseHeader().
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2380,10 +2380,11 @@ public void isAuthorizedHeader() throws Exception {
assertTrue(XMLHttpRequest.isAuthorizedHeader(HttpHeader.CONTENT_TYPE));

final String[] headers = {"accept-charset", HttpHeader.ACCEPT_ENCODING_LC,
"access-control-request-headers", "access-control-request-method",
HttpHeader.CONNECTION_LC, HttpHeader.CONTENT_LENGTH_LC, HttpHeader.COOKIE_LC, "cookie2",
"content-transfer-encoding", "date",
"expect", HttpHeader.HOST_LC, "keep-alive", HttpHeader.REFERER_LC,
"te", "trailer", "transfer-encoding", "upgrade",
"content-transfer-encoding", "date", "dnt",
"expect", HttpHeader.HOST_LC, "keep-alive", HttpHeader.ORIGIN_LC, HttpHeader.REFERER_LC,
"set-cookie", "te", "trailer", "transfer-encoding", "upgrade",
HttpHeader.USER_AGENT_LC, "via" };
for (final String header : headers) {
assertFalse(XMLHttpRequest.isAuthorizedHeader(header));
Expand Down
Loading