XSS using dynamically generated js file
A JavaScript endpoint reflected a user-supplied callback parameter into a dynamically generated script without sanitisation, and the script was served without a content-type sniffing protection header. An attacker could craft a page that loads the endpoint with a malicious callback value, causing script execution in the context of the victim site.
Published on medium.com
{{media:0}}
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 endpoint reflected the cb parameter into a dynamically generated JavaScript response without sanitisation, and the response lacked an X-Content-Type-Options: nosniff header, allowing the browser to execute the reflected input as script.
Impact
An attacker could execute arbitrary script in the context of the victim site, potentially bypassing cross-domain policy by injecting AJAX requests.
What the attacker needed
Victim visits attacker-controlled page; endpoint lacks nosniff header
The fix
The endpoint should sanitise or encode the cb parameter and serve responses with a nosniff header so reflected input cannot be executed as script.
How it was found
- Find the JavaScript endpoint while reviewing proxy traffic.
- Brute-force parameters on the endpoint and discover the cb parameter.
- Confirm the cb value is reflected into the generated script.
- Locate where the endpoint is included in the site's HTML or JavaScript.
- Craft a page that loads the endpoint with a malicious cb value and opens the page that includes 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 website had a JavaScript file that took a value from the URL and put it straight into the code it returned. Because the file was served in a way that browsers might treat as JavaScript, an attacker could make a victim's browser run their own code as if it came from the site. This is called cross-site scripting (XSS): running attacker code in another user's browser session.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.