XSS on using the legacy "Graphie To Png" API
The legacy Graphie-to-PNG API accepted uploaded SVG and JSON data and served the result from a shared CDN path keyed only by a hash of the JavaScript. An attacker could overwrite an existing graphie with a malicious SVG containing an onload handler and JSON labels that inject script, giving cross-site scripting on any page that renders graphies.
- Triaged in 14 hours
- Fixed in 50 days
- Disclosed after 3 months
An attacker can can upload malicious graphies via (http://graphie-to-png.kasandbox.org/) and (http://graphie-to-png.khanacademy.systems/) that exploit the graphie renderer.
The attack targets any page that has a graphie (khanacademy.org!!), as well as cdn.kastatic.org and ka-perseus-graphie.s3.amazonaws.com
Proof of concept
Step 1: Uploading a malicious graphie
consider the following example where https://ka-perseus-graphie.s3.amazonaws.com/2122427aa8dc4ef2a59058bc1a7a934ba6ca6747.svg is used in an article, we will override it by uploading the same JS but with malicious SVG and JSON data (because the hash is a hash of the JS).
- Malicious SVG: The SVG is modified to include a malicious
onloadattribute.
<svg ... onload="alert('SIKN')">...</svg>
- Malicious JSON: A label is modified with
typesetAsMath: false, causing the graphie renderer to inject our code to DOM. This is what will targetkhanacademy.org
{
"labels": [
{
"content": "<script>alert('SIKN')</script>",
"typesetAsMath": false,
...
},
...
],
...
}
var form = new FormData();
form.append("js", ORIGINAL_JS);
form.append("svg", XSS_SVG);
form.append("other_data", JSON.stringify(XSS_JSON));
await fetch("http://graphie-to-png.kasandbox.org/svg", {
"method": "POST",
"body": form
}).then(r=>r.text())
Step 2: Wait patiently
Wait until cdn.kastatic.org updates its cache, for this example I had already prepared it by not caching the original graphie (https://cdn.kastatic.org/ka-perseus-graphie/2122427aa8dc4ef2a59058bc1a7a934ba6ca6747.svg)
As for the malicious JSON, using the devtools override feature to simulate an attack shows that it works:

Impact
XSS on pages that use graphies, potentially leading to account takeovers.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the upload endpoint trusted client-supplied SVG and JSON, stored them under a predictable hash-based path, and served them from a CDN without sanitising or validating the content.
Impact
Script execution on any page that renders the affected graphie, which could lead to account takeovers; the author notes the CDN cache must refresh before the malicious version is served.
What the attacker needed
Access to the legacy upload API; a graphie already used on a page; CDN cache refresh
How it was found
- Find an existing graphie SVG used in an article and note its hash-based URL.
- Build a replacement SVG that includes an onload handler.
- Build replacement JSON where a label has typesetAsMath set to false so the renderer injects the label content into the page.
- Upload the original JavaScript together with the malicious SVG and JSON to the graphie-to-png endpoint.
- Wait for the CDN cache to refresh so the malicious version is served.
- Load a page that uses the graphie to trigger the script.
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 report has not been written yet. The Original tab links to the source.
A graphie is a small drawing used in lessons. The legacy service that turns these drawings into images accepted uploads that could replace an existing drawing. Because the replacement was served from the same address as the real one, any page showing that drawing could run the attacker's code in the visitor'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.