Rails Active Storage and ImageMagick: One Crafted Upload Can Write Files on Your Server — the CVSS 9.8 Flaw Is Fixed in 8.0.5.2 and 8.1.4.1
Rails Active Storage and ImageMagick: One Crafted Upload Can Write Files on Your Server — the CVSS 9.8 Flaw Is Fixed in 8.0.5.2 and 8.1.4.1
The Rails project has disclosed a critical flaw in Active Storage, its file-upload framework, that lets an unauthenticated attacker write arbitrary files to an app's server by uploading a crafted file — no exploit chain gymnastics required, just an app that processes uploads with ImageMagick. The advisory, GHSA-f3w6-w445-fwh9, is rated CVSS 9.8 by Rails and does not yet have a CVE identifier. Fixes shipped in 8.1.4.1 and 8.0.5.2, and the flaw was reported through HackerOne by researcher RyotaK of GMO Flatt Security. Every Active Storage version before those releases is affected; release series older than 8.0 are out of support and will not get a fix.
The mechanics run through ImageMagick's format handling. ImageMagick selects a handler — a "coder" — based on the file's content, and some coders act on other files named inside the image rather than the image itself. Active Storage imposed no limits on which coders an upload could invoke, so the server's ImageMagick security policy was the only line of defense — and Rails notes that the policies Debian and Ubuntu ship do not block the coders involved. The ImageMagick analyzer in Active Storage runs the moment a file is attached, so an app does not need to generate variants or previews to be vulnerable — attaching the upload is enough. The fixing commit traces the demonstrated path: an uploaded SVG file reached ImageMagick's MSL scripting coder, which reads and writes files named in its script. Rails says this chain was reported to it but "does not assume it is the only one that exists."
For apps using Active Storage's Disk service, the damage extends beyond writing: the attacker can also read any file the app can read — which typically means the app's secret_key_base and its credentials for other systems, assets that Rails itself warns may enable remote code execution or lateral movement. An app is affected only if all three conditions hold: it uses ImageMagick for Active Storage image processing (the :mini_magick variant processor — the default on load_defaults 6.1 and earlier, while apps on 7.0+ default to libvips), its ImageMagick policy does not block the dangerous coders, and it accepts uploads from untrusted users. The advisory does not say whether the flaw has been exploited in the wild.
The same releases also fix a second Active Storage flaw, GHSA-v924-7rp8-4mxh (CVSS 8.8): Active Storage passed uploads to ImageMagick and FFmpeg under temporary file names that preserved the uploaded filename's extension. Those tools pick a decoder from the extension when the content does not identify its own format — so an attacker who chose the filename and declared its content type chose the decoder that processed it. An FFmpeg build with AviSynth support will treat an .avs upload as a script and evaluate it, which can disclose files readable by the app process or load a native library the attacker also uploaded, potentially reaching code execution inside FFmpeg. In July, Rails fixed the libvips counterpart of this bug, CVE-2026-66066 — that one never touched ImageMagick apps, and this one never touches libvips apps.
What Should You Do?
- Upgrade Active Storage immediately to 8.1.4.1 or 8.0.5.2 — and treat unsupported pre-8.0 apps with untrusted uploads as exposed until you can plan a migration.
- Check your variant processor. Look at
config.active_storage.variant_processor::mini_magickmeans ImageMagick analyzes every upload;:vips(the 7.0+ default) is not on this bug's path. - Harden the ImageMagick policy regardless of patch level. At a minimum deny the MSL coder, the Ghostscript coders, and the gs delegate — the advisory includes the exact policy XML — and deny coders that read or delete other files.
- Review upload endpoints for signs of probing. Files written under unexpected paths, SVGs with embedded script elements, and odd extension/content-type mismatches are the fingerprints this class of attack leaves behind.
The WAF Angle
Upload handling is the front door to server-side code execution, and this flaw is the genre's purest recent specimen: a "file upload" that was really a request for the image library to write arbitrary files, from a coder that treats filenames inside an image as instructions. A WAF in front of an affected Rails app sees a perfectly ordinary multipart POST — the payload is an SVG that looks like an image — which is why the decisive control here is server-side: the ImageMagick coder policy, exactly the same defense-in-depth layer that saved (or would have saved) every ImageMagick-connected incident since the dawn of ImageTragick. Two practical WAF-tier moves still help: block or flag SVG uploads on endpoints that only need raster formats, and treat extension/content-type mismatch as a high-risk signal, since the companion flaw is literally an extension-trust attack. This lands in the same family as Next.js's AVIF image-optimizer RCE and PolyShell's Magento upload-to-RCE path — image processing on untrusted input is a code-execution boundary, and it deserves the same policy discipline as your SQL layer.
Sources
- Rails — GHSA-f3w6-w445-fwh9: Possible arbitrary file write and read in Active Storage image analysis
- Rails — GHSA-v924-7rp8-4mxh: Possible arbitrary file read and remote code execution in Active Storage video previews, analysis and image processing
- The Hacker News — Critical Rails Flaw Lets Attackers Write Server Files via Crafted ImageMagick Uploads