Bypassing Origin Checks Using Trailing Dot Trick
A JavaScript origin check compared the hostname exactly against a fixed domain, so a URL with a trailing dot on the hostname bypassed the check and allowed execution of a javascript: URL. An attacker could craft a link that runs arbitrary script in the context of the vulnerable page.
medium.com
Published on medium.com
During a recent web security challenge designed by Shahrokh, I encountered an interesting scenario involving JavaScript URL execution, which was guarded by a hostname origin check. The challenge’s core was a simple but strict validation of the domain name before allowing the execution of potentially dangerous…
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 hostname check did not normalise the trailing dot, so a hostname with a trailing dot was treated as different from the same hostname without it.
Impact
An attacker could execute arbitrary JavaScript in the context of the vulnerable page, potentially leading to XSS.
What the attacker needed
Victim clicks a crafted link
The fix
The hostname should be normalised by removing any trailing dot before comparison.
How it was found
- Craft a URL with the target hostname followed by a trailing dot and a javascript: payload in the url parameter.
- Visit the URL in a browser.
- The page's script compares window.location.hostname (which includes the trailing dot) to the expected hostname without the dot, so the check fails.
- The script then sets window.location.href to the javascript: URL, executing the payload.
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 website used a simple string comparison to check if the current domain matched a specific name. Because the browser includes a trailing dot in the hostname when present, an attacker could add a dot to the domain and trick the check into failing, allowing malicious JavaScript to run.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.