⚡ The main thing in 60 seconds (TL;DR)

⏱ ~ 6 мин чтения
  • Rails fixes a critical Active Storage bug that allows arbitrary files to be written via ImageMagick loads and files to be read by Disk Service applications.
  • The Rails project discovered a bug in the recommendation and fixed it in versions 8.1.4.1 and 8.0.5.2. The flaw lies in Active Storage, the part of Rails that handles file uploads.
  • Some applications store downloaded files using the Active Storage disk service, which stores them on the server's disk.
Critical Rails bug allows attackers to write server files using specially crafted ImageMagick downloads

A critical bug in Ruby on Rails could allow an unauthenticated attacker to write arbitrary files to the application server by uploading a crafted file if the application handles uploads using ImageMagick. The Rails Project discovered a bug in the recommendation and fixed it in versions 8.1.4.1 and 8.0.5.2.

The flaw lies in Active Storage, the part of Rails that handles file uploads. Some applications store downloaded files using the Active Storage disk service, which stores them on the server's disk. In these applications, an attacker can also read any file that the application can read.

According to Rails, these files typically include the application's secret_key_base and its credentials for other systems. Reading them, in turn, could allow remote code execution or lateral movement into those systems.

Rails scores the flaw at 9.8 out of 10 on the CVSS scale. It is tracked as GHSA-f3w6-w445-fwh9 and does not yet have a CVE ID.

ImageMagick selects the format handler that the encoder calls based on the contents of the file. Some programmers work with other files specified within the image rather than the image itself. Active Storage places no restrictions on which encoders can be used when loading, so the only limitation was the server's own ImageMagick policy.

Cybersecurity

The ImageMagick analyzer in Active Storage runs when a file is attached. It is enough to attach the download to get to the vulnerability. The application does not need to make a variant (a converted copy of the image) or a preview, or call analysis.

The uploaded SVG file entered the ImageMagick MSL encoder through this parser, according to the commit that fixed the bug. MSL is a script encoder that reads and writes files named in its script.

Rails said it had been informed of one chain of attacks, but the company "does not believe it is the only one in existence." The message does not say whether this vulnerability was exploited.

The vulnerability was reported via HackerOne by RyotaK, a researcher at GMO Flatt Security.

Which Rails applications are affected

The application is only affected if all three conditions are true:

  • It uses ImageMagick to process Active Storage images. This is the default config.active_storage.variant_processor = :mini_magick setting for applications version load_defaults 6.1 or earlier.
  • Its ImageMagick security policy does not yet block the programmers involved. Rails claims that the policies supplied by Debian and Ubuntu are not true.
  • It accepts file downloads from untrusted users.

To check the first condition, look at config.active_storage.variant_processor. If it is not set, the default value depends on load_defaults: :mini_magick before version 7.0 and :vips since version 7.0. The same parameter determines which library parses downloads, not just which one creates variants.

All Active Storage versions prior to 8.0.5.2 are affected, as are 8.1 versions prior to 8.1.4.1. Release series older than 8.0 are no longer supported, and Rails will not release fixed versions for them.

In July, Rails fixed another critical Active Storage flaw, CVE-2026-66066, which affected applications using libvips instead of ImageMagick. Applications using ImageMagick have not been affected by this flaw, but they may be susceptible to it.

The same releases fixed a second Active Storage flaw, GHSA-v924-7rp8-4mxh, which Rails ranks highly with a CVSS score of 8.8. Active Storage passed downloads to ImageMagick and FFmpeg under temporary filenames that preserved the downloaded file extension.

These tools can select a decoder from an extension if the file's contents do not match its format. Thus, an attacker who chose the name of the uploaded file and declared its content type could select the decoder that processes it.

What to do

Rails strongly recommends upgrading as soon as possible. A total of 21 security issues have been fixed over the two releases.

Patched versions come with ImageMagick security policy. MiniMagick is a Ruby gem that Active Storage uses to call ImageMagick. With the default setting, every ImageMagick command you run applies the policy, not just the commands from Active Storage.

Cybersecurity

Policy blocks MSL encoder; encoders that read or delete non-image files; encoders that retrieve remote or local references or display them on the screen; every programmer supported by Ghostscript, along with a gs delegate; and @filename indirection.

  • Update Rails to version 8.1.4.1 or 8.0.5.2. Applications on :mini_magick also require mini_magick 5.1 or later or they will fail when loading. Rails 8.0 will only receive security patches until November 7, 2026, per its maintenance policy.
  • Verify that the application loads the new policy as described in the Active Storage Guide by running bin/rails runner 'puts MiniMagick.identify { |i| i.list "policy" }'.
  • Check whether the sent policy reaches the application at all. It does not reach an application that replaces MiniMagick.cli_env after loading, cleans up the environment with MiniMagick.cli_prefix or installs its own MiniMagick::Shell. Such an application must include rules in the ImageMagick system policy.
  • Applications that use GraphicsMagick do not receive protection from the supplied policy because GraphicsMagick does not read ImageMagick policies.
  • Check the server's own ImageMagick policy. The policy supplied complements it, not replaces it. A rule that allows an encoder, including a wildcard such as pattern="*", overrides the blocking of the set policy for that encoder.
  • If your application renders PDF or PostScript files using ImageMagick, re-enable delegate gs and the encoders it uses in server-side policy.xml.
  • If you are unable to upgrade yet, copy the rules from the supplied policy activestorage/lib/active_storage/image_magick/policy.xml to the ImageMagick system policy, such as /etc/ImageMagick-7/policy.xml. At a minimum, block the MSL encoder, Ghostscript encoders, and the gs delegate. Rails has also published a fix in the form of patches for 8.1 and 8.0.
  • Applications in releases older than 8.0 can use this workaround or upgrade to version 8.0 or later.
  • The Rails workarounds for the second flaw only change the way FFmpeg is used. None of them cover ImageMagick.
  • If your app stores attachments in the Drive service, change secret_key_base and any other secrets that the app process can read. This includes the master key, anything stored in config/credentials.yml.enc, storage and database credentials, and third-party tokens. Don't keep a revealed secret as a backup plan.

The recommendation does not explain how to check if an application has already been attacked.

Found this article interesting? Follow us on Google News, Twitter and LinkedIn to read more exclusive content we post.

#SLM #LocalAI