Skip to content
XSS Disclosed report Intermediate

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.

sikn Follow

Originally disclosed on HackerOne

Critical View original
  • 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).

  1. Malicious SVG: The SVG is modified to include a malicious onload attribute.
HTML
<svg ... onload="alert('SIKN')">...</svg>
  1. Malicious JSON: A label is modified with typesetAsMath: false, causing the graphie renderer to inject our code to DOM. This is what will target khanacademy.org
JSON
{
	"labels": [
		{
			"content": "<script>alert('SIKN')</script>",
			"typesetAsMath": false,
			...
		},
		...
	],
	...
}
JavaScript
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:

POC.png
POC.png From the original on HackerOne

Impact

XSS on pages that use graphies, potentially leading to account takeovers.

The original report as published on HackerOne, by sikn. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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

  1. Find an existing graphie SVG used in an article and note its hash-based URL.
  2. Build a replacement SVG that includes an onload handler.
  3. Build replacement JSON where a label has typesetAsMath set to false so the renderer injects the label content into the page.
  4. Upload the original JavaScript together with the malicious SVG and JSON to the graphie-to-png endpoint.
  5. Wait for the CDN cache to refresh so the malicious version is served.
  6. 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.

More from Khan Academy

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.