Skip to content

Do not let document.cookie create or replace HttpOnly cookies - #1195

Merged
rbri merged 2 commits into
HtmlUnit:masterfrom
Vidya-m78:document-cookie-httponly
Nov 16, 2026
Merged

rbri merged 2 commits into
HtmlUnit:masterfrom
Vidya-m78:document-cookie-httponly

Conversation

@Vidya-m78

Copy link
Copy Markdown
Contributor

document.cookie can overwrite HttpOnly cookies

WebClient.addCookie(String, URL, Object) (used by document.cookie and <meta http-equiv=set-cookie>) passed every parsed cookie to CookieManager.addCookie(), which drops any stored cookie with the same name/domain/path. So document.cookie = 'JSESSIONID=attacker; path=/' replaced the server's HttpOnly session cookie with a script-readable one that is sent on the next request, an expired write deleted it, and 'x=1; HttpOnly' from script was stored as HttpOnly. Browsers ignore both cases (RFC 6265 5.3, steps 10 and 11), and the check sits in addCookie() so both non-HTTP callers get it. CookieManagerTest.httpOnlyNotWritableFromJs fails without the change and passes with it.

@rbri
rbri merged commit 8186ed5 into HtmlUnit:master Nov 16, 2026
5 checks passed
@sonarqubecloud

Copy link
Copy Markdown

@rbri

rbri commented Nov 16, 2026

Copy link
Copy Markdown
Member

Many thanks

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