# XSS in image with user-controlled src

Canvas broken-image handler made jQuery XHR to attacker URL; server returned application/javascript, executing stored XSS in Rich Content for viewers.

- Payout: $300
- Severity: medium
- Program: Instructure Canvas
- Found by: sesamestrong
- Disclosed: 2021-08-04
- Write-up quality: 7/10
- Original: https://bugcrowd.com/disclosures/be7a6ce0-a09a-4e7e-9cbe-44f469550dbe/xss-in-image-with-user-controlled-src
- Library page: https://bugbountylibrary.com/r/bc%3A6fbe09ba-112c-44dd-b06c-31eeb8305e9a
- Tags: area:web domain:web impact:ato kind:bounty platform:bugcrowd sev:medium technique:chained technique:source-review vuln:xss

**Target:** Rich Content Editor broken-image handler
**Root cause:** Canvas used jQuery vulnerable to CVE-2015-9251; the broken-image handler issued an XHR to the image src, and jQuery executed responses served with Content-Type application/javascript.
**Steps:**
1. Set up attacker server that inspects the Accept header.
2. If Accept indicates an image, wait a few seconds then return 404.
3. If Accept indicates XHR, respond with `Content-Type: application/javascript` and JS payload.
4. Insert an image into Rich Content Editor with `src` pointing to attacker server URL and post it.
5. When a victim views the post, the broken-image handler XHRs the URL and jQuery executes the payload.
**How found:** Noticed Canvas used an old jQuery version vulnerable to CVE-2015-9251 (XHR responses with application/javascript executed), then found the broken-image handler made a jQuery XHR to the image URL to check status code, providing a controllable sink.
**Exploitation:** Attacker hosts a header-conditional server, embeds an image in Rich Content; victim's browser loads it, broken-image handler XHRs the URL, server returns JS with application/javascript, jQuery evals it, achieving stored XSS in victim context.
**Escalation:** Could change grades, read quiz answers, take over teacher accounts, or worm across the school system.
**Insight:** When a target ships an old jQuery, look for app code that XHRs user-controlled URLs (image error handlers, status checks) and pair it with a server that switches response Content-Type based on the Accept header to turn image loads into script execution.

