How I got XSS’d by my ad network
A reflected cross-site scripting flaw existed in an ad network's script that rendered the original URL into a JavaScript context without encoding quotes. An attacker could craft a URL that, when visited, executed arbitrary JavaScript in the context of the victim site.
troyhunt.com
Published on troyhunt.com
It’s a JavaScript prompt and no, it’s not meant to be there. Someone had successfully mounted an XSS attack against this very website!
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 ad network's script failed to properly encode user-controlled input from the URL before inserting it into a JavaScript context.
Impact
An attacker could execute arbitrary JavaScript in the context of the victim site, potentially compromising visitors; however, the author could not reproduce it himself and the reporter had to disable Internet Explorer's XSS protection.
What the attacker needed
Victim clicks a crafted link; third-party ad script loads; browser XSS protection disabled (in one case)
The fix
The ad provider paused the offending ads until the issue was resolved.
How it was found
- A request is made to the site with a query string containing a JavaScript payload.
- The site embeds the ad provider's script, which makes requests to DoubleClick with the full URL as referrer.
- DoubleClick writes an iframe pointing to adsafeprotected.com, passing the referrer.
- The response from adsafeprotected.com renders the original URL into JavaScript without encoding, 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.
Cross-site scripting (XSS) is when a website lets an attacker sneak in code that runs in a visitor's browser. Here, a third-party ad script took part of the web address and put it into a script without cleaning it, so a specially crafted link could make the browser run the attacker's code.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.