Skip to content
nulltapE-reader edition

← All e-reader articles

Updated 5 min read

Rails Image Upload Flaw Lets Attackers Write Server Files

Untrusted Active Storage uploads can reach ImageMagick coders at attachment time. Check the processor and policy, upgrade Rails, and rotate Disk-service secrets.

Read on the standard site

A white image upload enters a steel server intake marked by a large ruby, evoking Rails attachment processing.

A file upload can reach beyond the image it carries in a Rails application that processes untrusted Active Storage attachments with ImageMagick. The Rails security advisory describes an unauthenticated arbitrary-file-write path; applications storing attachments with the Disk service may also expose files readable by the Rails process. Rails fixed the issue in activestorage 8.1.4.1 and 8.0.5.2 on November 4. Applications that use the :mini_magick processor need to check the installed MiniMagick version and how ImageMagick receives its security policy.

Active Storage analyzes an attachment as it is attached, so an attacker with access to an untrusted upload path can reach ImageMagick before any preview request. Rails writes, “Attaching the upload is sufficient; no variant, preview, or analyze call is required.” This is GHSA-f3w6-w445-fwh9, reported to Rails by HackerOne researcher ryotak. It is a separate ImageMagick coder issue from the earlier Rails Active Storage libvips disclosure, which involved a different image processor and fix.

Attachment analysis reaches ImageMagick coders

ImageMagick chooses a coder based on the content it receives. Some coders operate on files named inside an image rather than limiting their work to the uploaded image. Before this fix, Active Storage placed no restriction on those coders. A crafted upload can therefore ask ImageMagick to act on files available to the application server. Rails says one attack chain was reported to its maintainers and warns that other chains may exist; scope every deployment meeting the processing conditions.

Three conditions must coincide: the application accepts uploads from untrusted users; Active Storage uses ImageMagick via config.active_storage.variant_processor = :mini_magick; and the effective ImageMagick policy permits the relevant coders. The :mini_magick setting is the default for applications using load_defaults 6.1 or earlier, according to Rails. Rails specifically says the ImageMagick policies packaged by Debian and Ubuntu do not deny the coders involved. Inspect the deployed application’s configuration and the effective ImageMagick policy as seen by every web and attachment-processing worker process before deciding which deployments require a fix. Assess services running another variant processor against that processor’s own advisories.

With Active Storage’s Disk service, the same weakness may allow reads of files the application process can access, including secret_key_base and external-system credentials. Rails describes escalation to code execution or movement into connected systems as possible consequences of those secrets. For an affected application, review upload and attachment-processing records and downstream credential use. Rails reports one attack chain but provides no request signature; a clean request-log search cannot rule out credential exposure.

The fix depends on policy delivery

The fixed activestorage releases prepend a shipped policy directory to MAGICK_CONFIGURE_PATH via MiniMagick.cli_env. That applies the policy to every ImageMagick process MiniMagick launches, beyond Active Storage alone. The policy denies the MSL scripting coder, coders that read or delete other files, fetch references or display to a screen, the Ghostscript-backed coders and gs delegate, and @filename indirection. ImageMagick applies all policy.xml files on its search path, so the Rails policy adds restrictions alongside the host policy.

An application using :mini_magick also needs mini_magick 5.1 or later. Rails says older versions raise an exception during boot when the fix is applied. Inspect the resolved activestorage and mini_magick entries in Gemfile.lock, then start each updated web and worker process in a staging environment before release. For a supported series, plan to move to 8.1.4.1; Socket’s patch announcement says support for the 8.0 series ends on November 7. Applications on older branches need a supported upgrade plan and a check of the running version.

Custom MiniMagick wrappers need system policy

Rails says replacing MiniMagick.cli_env after boot, clearing the environment with MiniMagick.cli_prefix, or installing a custom MiniMagick::Shell prevents the shipped policy from reaching ImageMagick. Put the corresponding restrictions in the system ImageMagick policy in those deployments and verify the effective policy under the application’s runtime environment. GraphicsMagick does not read ImageMagick policies. Applications that render PDF or PostScript through ImageMagick may need host-policy changes to re-allow their required Ghostscript delegate and coders after the upgrade; test those legitimate conversions before promotion.

Move exposed secrets out of service

Upgrade exposed applications. For applications matching the upload, processor and permissive-policy conditions, upgrade activestorage to 8.1.4.1 or 8.0.5.2, and require mini_magick 5.1 or newer where :mini_magick is configured. Confirm the deployed gem versions, successful web and worker boot, and the effective ImageMagick policy in those processes. If custom MiniMagick integration bypasses the shipped policy, enforce its rules at the system policy instead. Rails also offers copying the fixed release’s activestorage/lib/active_storage/image_magick/policy.xml rules into the host ImageMagick policy as a workaround while upgrading.

Rotate exposed credentials. For Disk-service attachments, rotate every secret readable by the application process, including secret_key_base, the master key, everything in config/credentials.yml.enc, storage and database credentials, and third-party tokens. Rails explicitly advises removing exposed secrets from fallback configurations. Verify that the old values no longer authenticate and check access to the connected systems during the exposure period. This is recovery work alongside the code change: a fixed image pipeline cannot revoke a secret already copied out.

Socket offers a free Certified Patch as an interim option for teams that cannot upgrade immediately. Socket is describing its own product; that patch addresses this GHSA specifically, while Socket says the November 4 Rails updates also fix 20 other issues. Treat the complete Rails upgrade as the target. A useful release check is the combination of a fixed resolved activestorage version, compatible MiniMagick, a policy that reaches the actual ImageMagick processes, successful application boot and rejected old Disk-service credentials.

Corrections

  • : Clarified that Disk-service exposure calls for rotating every secret readable by Rails, including encrypted-credentials contents.

Primary sources