# Active Storage: Possible arbitrary file write and read in image analysis

Active Storage left ImageMagick coders unconstrained, so a crafted upload analyzed on attach could write arbitrary files and, with Disk service, read secrets like secret_key_base.

- Payout: Research
- Severity: critical
- Program: Rails Active Storage
- Found by: Ry0taK
- Disclosed: 2026-11-12
- CVE: CVE-2026-122006
- Write-up quality: 7/10
- Original: https://github.com/advisories/GHSA-f3w6-w445-fwh9
- Library page: https://bugbountylibrary.com/r/ghsa%3AGHSA-f3w6-w445-fwh9
- Tags: area:oss domain:oss domain:web impact:data-leak impact:rce kind:research platform:ghsa sev:critical tech:ruby technique:source-review vuln:file-upload vuln:path-traversal vuln:secrets-leak

**Target:** Active Storage image analyzer via ImageMagick/MiniMagick
**Root cause:** Active Storage did not constrain ImageMagick coders; ImageMagick selects a coder from file content and some coders (MSL, Ghostscript-backed, @filename indirection) act on files named inside the image. No security policy was shipped or applied to MiniMagick-spawned processes.
**Steps:**
1. Application uses `config.active_storage.variant_processor = :mini_magick` (default on load_defaults 6.1 or earlier) and accepts untrusted uploads.
2. Host ImageMagick policy does not deny the dangerous coders (Debian/Ubuntu packaged policies do not).
3. Attacker uploads a crafted image whose content selects a coder such as `MSL` that references other files.
4. Attaching the upload triggers the ImageMagick analyzer; no variant, preview, or `analyze` call needed.
5. Coder writes arbitrary files on the server and, with Disk service, reads files readable by the app process (e.g. `secret_key_base`, credentials).
**How found:** Reporter observed that ImageMagick picks a coder from file content and some coders operate on files named inside the image, and that Active Storage constrained none of them while the analyzer runs automatically on attach.
**Exploitation:** Unauthenticated attacker uploads a crafted file that ImageMagick's content-based coder selection resolves to a file-acting coder (e.g. MSL); the analyzer runs on attach, executing the coder to write arbitrary files and, under the Disk service, read arbitrary app-readable files such as secret_key_base and external credentials, enabling RCE or lateral movement.
**Escalation:** Stolen secret_key_base and credentials for external systems may allow escalation to remote code execution or lateral movement.
**Insight:** When a library delegates parsing to ImageMagick, the attack surface is the coder set, not the image format: content-based coder selection means any upload can invoke MSL, Ghostscript-backed coders, or @filename indirection unless a policy.xml explicitly denies them — and auto-running analyzers on attach removes the need for a preview/variant trigger.

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

**ImageMagick policy.xml workaround rules**

```
<policy domain="coder" rights="none" pattern="MSL"/>
<policy domain="delegate" rights="none" pattern="gs"/>
<policy domain="coder" rights="none" pattern="{PS,PS2,PS3,EPS,EPS2,EPS3,EPI,EPSF,EPSI,EPT,EPT2,EPT3,PDF,AI,EPDF,PDFA,POCKETMOD,XPS,PCL}"/>
```

