Repository navigation
Validate the cookie domain for document.cookie and public suffixes - #1200
Merged
Merged
Conversation
HttpClientConverter.parseCookie() (used by document.cookie and meta http-equiv set-cookie) never called CookieSpec.validate(), so the domain attribute was not checked against the page. A page from attacker.example could set a cookie with domain=victim.example and HtmlUnit sent it to victim.example. HttpClient does this check for Set-Cookie headers already. HtmlUnitDomainHandler.validate() now also rejects a domain that is a public suffix (e.g. co.uk) unless it is the host itself (RFC 6265 section 5.3, step 5).
|
Member
|
Great, many thanks for working on all these... |
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.



Repro: on a page from https://www.attacker.co.uk/ run
document.cookie = 'sid=x; domain=victim.example; path=/'. HtmlUnit stores the cookie and sends it with every request to victim.example.domain=co.ukis accepted the same way and is sent to every *.co.uk site.Cause:
HttpClientConverter.parseCookie(), the parser behind document.cookie and<meta http-equiv=set-cookie>, only callsCookieSpec.parse()and neverCookieSpec.validate(), so the domain-match check HttpClient runs for Set-Cookie headers is skipped.HtmlUnitDomainHandlerhas no public suffix check on either path (RFC 6265 section 5.3, steps 5 and 6).Fix: validate in
parseCookie(), and reject a multi-label public suffix domain inHtmlUnitDomainHandler.validate()unless it is the host itself. Single-label domains likecomkeep the existing handling inmatch(). The public suffix list bundled with httpclient 4.5.14 has no private-section entries such as github.io, so those are not covered.CookieManager2Test.documentCookieForeignDomainandHttpClientConverterTest.parseCookieDomainfail without the fix. CookieManager4Test/5Test need the htmlunit-dev.org hosts setup, which I could not run locally.