Concealing payloads in URL credentials
Browsers keep the credentials part of a URL in document.URL even though it is hidden from the address bar, and Firefox does not encode single quotes there. An attacker could hide a script payload in the credentials so it reaches a DOM XSS sink, or clobber the username and password properties of anchor elements.
portswigger.net
Published on portswigger.net
Last year Johan Carlsson discovered you could conceal payloads inside the credentials part of the URL. This was fascinating to me especially because the payload is not actually visible in the URL in both Chrome and Firefox.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the browser exposes the credentials portion of the URL through document.URL while hiding it in the address bar, and Firefox fails to URL-encode single quotes in that portion, so untrusted URL data reaches DOM sinks.
Impact
This could enable DOM XSS on Chrome and Firefox and let an attacker control anchor username and password properties; Safari discards URL credentials and Chrome blocks sub-resources from using them, which limits the technique.
What the attacker needed
Chrome or Firefox browser; A DOM sink that reads document.URL; Victim navigates to the crafted URL
How it was found
- Place a payload in the credentials part of a URL pointing at the target.
- Have the page read document.URL and write it into a script or HTML sink.
- On Firefox, use a single quote in the credentials to break out of the script string.
- Deliver the crafted URL by redirection or by getting the user to navigate to it.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
A web address can carry a username and password before the @ sign, and browsers hide that part from the address bar. The page's own script can still read it, so a hidden payload placed there can end up running as code. Firefox also leaves single quotes in that part unencoded, which makes it easier to break out of a script string.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.