# XSS by file (Active Storage `Proxying`)

Active Storage ProxyController serves uploaded files inline with attacker-controlled Content-Disposition, so an uploaded SVG executes JavaScript when fetched via the proxy URL.

- Payout: $500
- Severity: medium
- Program: Ruby on Rails
- Found by: ooooooo_q
- Disclosed: 2020-09-01
- Write-up quality: 7/10
- Original: https://hackerone.com/reports/949513
- Library page: https://bugbountylibrary.com/r/h1%3A949513
- Tags: area:web domain:web impact:integrity kind:bounty platform:hackerone sev:medium tech:ruby technique:incomplete-fix technique:source-review vuln:xss

**Target:** Ruby on Rails ActiveStorage::Blobs::ProxyController / SetHeaders concern
**Root cause:** set_content_headers_from sets Content-Disposition to inline (or params[:disposition]) regardless of blob content type, and the proxy endpoint streams the file with its original content type, so SVG/HTML is rendered and executed in the app origin.
**Steps:**
1. Create Rails app on master with active_storage:install and a model with has_one_attached :image
2. Upload `alert.svg` containing `<svg xmlns='http://www.w3.org/2000/svg' onload="javascript:alert(location)">`
3. Capture the redirect URL `/rails/active_storage/blobs/redirect/<signed_id>/alert.svg`
4. Replace `redirect` with `proxy` in the path and open the URL directly in a browser
5. SVG renders inline and onload JavaScript executes in the app origin
**How found:** Noticed prior similar reports (#407319, #429868) and reviewed the new Proxying file-serving strategy commit; reading set_headers.rb revealed Content-Disposition is set to inline regardless of file type, and proxy_controller streams the blob directly.
**Exploitation:** Attacker uploads a malicious SVG through any feature that accepts Active Storage attachments, then shares the proxy URL (redirect path rewritten to proxy) with a victim; the browser renders the SVG inline and executes script in the application's origin, bypassing CSP because the SVG response lacks the CSP header.
**Escalation:** CSP bypass noted: the SVG response does not include the Content-Security-Policy header, so even apps with CSP configured are vulnerable.
**Insight:** When a framework adds a new file-serving strategy, check whether Content-Disposition/Content-Type are derived from the blob's actual type; also check whether security headers (CSP) are applied to non-HTML responses like SVG, which browsers still render as active content.

## Proof of concept (copied exactly from the original report)

**Malicious SVG payload with onload alert**

```
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns='http://www.w3.org/2000/svg' width="200px" height="200px" onload="javascript:alert(location)">
</svg>
```

**Proxy URL triggering XSS**

```
http://localhost:3000/rails/active_storage/blobs/proxy/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBCZz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--ed4ee8109834f4dd747bfb68d7a7ddc2e43e8f69/alert.svg
```

