When a Link Becomes JavaScript (Stored XSS via javascript: URL)
A news feature stored a user-supplied URL and rendered it directly into a link's href attribute, escaping only HTML tags. An attacker could submit a javascript: URL so that anyone clicking the stored link would run attacker-controlled script in the page context.
medium.com
Published on medium.com
The original lives on medium.com
We do not hold its text, 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
The application escaped HTML special characters but did not validate or restrict the URL scheme before placing user input into an href attribute.
Impact
Anyone who clicks the stored link could have script run in their session, which could lead to session hijacking, account takeover or admin compromise.
What the attacker needed
Ability to submit a news item; victim clicks the stored link
The fix
The application should validate the URL scheme and only allow http and https, rejecting everything else, with a Content-Security-Policy as defence in depth.
How it was found
- Open the News submission feature that accepts a title and a URL.
- Submit a news item whose URL uses the javascript: scheme instead of http or https.
- The application stores the URL and later renders it inside an anchor's href attribute.
- A user who clicks the stored link triggers the script in the current page context.
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 let people save a web address for a news item and then put that address straight into a clickable link. The site only blocked angle brackets, which stop script tags, but it did not check what kind of address it was. A link starting with 'javascript:' runs code when clicked, so the saved link could run the attacker's code in the victim's browser.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.