Skip to content

Do not expose Set-Cookie response headers to XMLHttpRequest - #1201

Merged
rbri merged 1 commit into
HtmlUnit:masterfrom
Vidya-m78:xhr-hide-set-cookie-headers
Nov 18, 2026
Merged

rbri merged 1 commit into
HtmlUnit:masterfrom
Vidya-m78:xhr-hide-set-cookie-headers

Conversation

@Vidya-m78

Copy link
Copy Markdown
Contributor

XMLHttpRequest exposes HttpOnly cookies through Set-Cookie
getResponseHeader() and getAllResponseHeaders() return every response header, so a page script can read an HttpOnly cookie by requesting any url that sets or refreshes it: xhr.getResponseHeader('Set-Cookie') returns session=secret; HttpOnly while document.cookie correctly hides it. fetch() is affected as well, the polyfill builds response.headers from getAllResponseHeaders(). Set-Cookie and Set-Cookie2 are forbidden response header names in the Fetch standard and browsers drop them in both methods, for same-origin and CORS responses.

XMLHttpRequest2Test.getResponseHeaderSetCookie fails on master for all browsers and passes with the change; the XMLHttpRequest, fetch and CodeStyle tests pass and checkstyle is clean. I also added a changes.xml entry.

@sonarqubecloud

Copy link
Copy Markdown

@rbri

rbri commented Nov 18, 2026

Copy link
Copy Markdown
Member

❤️

@rbri
rbri merged commit ff2185f into HtmlUnit:master Nov 18, 2026
8 checks passed
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.

2 participants