XSSing Google Code-in thanks to improperly escaped JSON data
User-supplied text in comments and other fields was placed inside a JSON script block without escaping the sequence that ends the script element, allowing an attacker to break out and inject a script. Because the frontend used AngularJS, the injected markup could bypass the Content Security Policy and execute JavaScript for anyone viewing the comments page.
websecblog.com
Published on websecblog.com
Google Code-in is an online programming competition for students hosted by Google that takes place every year.
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 backend serialised user data into a JSON script element without escaping the sequence that terminates the script element, so user input could break out of the JSON context.
Impact
An attacker could execute arbitrary JavaScript in the browser of anyone viewing the comments page, such as mentors or site admins, though the site's CSP would have blocked a plain script element and was bypassed only because of the AngularJS frontend.
What the attacker needed
A Google Code-in account; victim views the comments page
The fix
The issue was fixed the following day by the development team.
How it was found
- Sign up for Google Code-in and enter a payload into all text fields.
- Submit the form and observe that the payloads execute on every page visited.
- Submit a task comment containing the payload.
- Reload the page and confirm the payload still executes.
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 put user comments into a special data block on the page. The code that built that block did not escape a character sequence that tells the browser the block has ended, so a comment could close the block early and add its own script. The site also used a JavaScript framework that could run code from the page, which let the attacker get around the site's script-blocking protection.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.