Skip to content

Do not send the credentials of the page url in the Referer and Origin headers - #1203

Merged
rbri merged 1 commit into
HtmlUnit:masterfrom
Vidya-m78:referer-origin-strip-credentials
Nov 19, 2026
Merged

rbri merged 1 commit into
HtmlUnit:masterfrom
Vidya-m78:referer-origin-strip-credentials

Conversation

@Vidya-m78

Copy link
Copy Markdown
Contributor

The credentials of the page url leak through Referer and Origin
WebRequest.setRefererHeader() and the origin helpers UrlUtils.getUrlWithProtocolAndAuthority() / getUrlWithoutPathRefQuery() copy URL.getAuthority(), which includes the user info. A page loaded from http://admin:s3cret@intranet.example/app/ that submits a form to http://evil.example/collect sends Referer: http://admin:s3cret@intranet.example/app/ and Origin: http://admin:s3cret@intranet.example. The same happens for every link, image, script, stylesheet, iframe, ping and sendBeacon the page triggers, and the credentials also end up in document.referrer of the target page, in MessageEvent.origin of postMessage and in the Origin of WebSocket handshakes. The Fetch standard strips username and password from the referrer ("strip url for use as a referrer") and an origin has no user info, so browsers never send them. Urls without user info produce exactly the same string as before.

WebRequestTest.refererHeaderWithoutCredentials and the new UrlUtilsTest cases fail on master and pass with the change. I also checked the form submit case end to end with a MockWebConnection: both headers now carry only http://intranet.example. The WebRequest, UrlUtils, anchor/form/image/link/script, Location, Window, XMLHttpRequest, WebSocket, WebClient and CodeStyle tests show no new failures (only the existing DNS-dependent and timing-sensitive ones that fail here on master too), and checkstyle and pmd are clean. I also added a changes.xml entry.

WebRequest.setRefererHeader() and the origin helpers
UrlUtils.getUrlWithProtocolAndAuthority() / getUrlWithoutPathRefQuery()
copied URL.getAuthority(), which includes the user info. A page loaded
from http://user:password@host/ sent the credentials in the Referer
and Origin headers to every site it referenced, and they showed up in
document.referrer, MessageEvent.origin and the WebSocket Origin.

The referrer is stripped of username and password (Fetch standard,
strip url for use as a referrer) and an origin has no user info.
@sonarqubecloud

Copy link
Copy Markdown

@rbri
rbri merged commit d1dae33 into HtmlUnit:master Nov 19, 2026
7 of 8 checks passed
@rbri

rbri commented Nov 19, 2026

Copy link
Copy Markdown
Member

made a new snapshot build available

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