← All articles

Ruby on Rails vulnerability enables server file writes

Ruby on Rails vulnerability enables server file writes

A critical Ruby on Rails vulnerability can let an unauthenticated attacker, meaning someone who has not signed in, write arbitrary files to an application server by submitting a specially crafted upload. The path is exposed when a Rails application processes uploads with ImageMagick, software used to inspect and transform images. The Rails project fixed the flaw in versions 8.1.4.1 and 8.0.5.2 and strongly recommends upgrading as soon as possible. It assigned a CVSS score of 9.8 out of 10, a standard rating for vulnerability severity. The issue is tracked as GHSA-f3w6-w445-fwh9 and does not yet have a CVE identifier.

The flaw is in Active Storage, the Rails component responsible for file attachments and uploads. Its ImageMagick analyzer runs as soon as a file is attached, so an application does not need to create a variant, which is a transformed copy of an image, generate a preview or explicitly call the analyze function. According to the code change that fixed the issue, an uploaded SVG image could reach ImageMagick's MSL coder. A coder is the part of ImageMagick that handles a particular file format. MSL is a scripting coder capable of reading and writing files named in its instructions.

ImageMagick normally chooses a coder by examining a file's content. Some coders do more than process the uploaded image and can act on other files referenced inside it. Active Storage did not restrict which coders an upload could invoke, leaving the server's own ImageMagick security policy as the only barrier. Rails said one attack chain had been reported but warned that it could not assume this was the only possible chain. The advisory does not say whether attackers have exploited the vulnerability. It was reported through HackerOne by a researcher at GMO Flatt Security.

The consequences can extend beyond writing files. Applications using Active Storage's Disk service, which keeps attachments on the server's local disk, may also allow an attacker to read any file accessible to the application process. Rails said this commonly includes secret_key_base, the private value Rails uses to protect sensitive application data, as well as credentials for databases, storage services and other connected systems. Exposure of those files could lead to remote code execution, where an attacker makes the server run chosen commands, or lateral movement into other systems that trust the stolen credentials.

An application is affected only when three conditions are all present. It must use ImageMagick for Active Storage image processing, its ImageMagick security policy must not already block the relevant coders, and it must accept uploads from untrusted users. Rails notes that the policies shipped by Debian and Ubuntu do not block the coders involved. Administrators can check config.active_storage.variant_processor: the relevant setting is :mini_magick, which is the default for applications using load_defaults 6.1 or earlier. If the setting is absent, Rails defaults to :mini_magick before load_defaults 7.0 and :vips from 7.0 onward. This choice controls the library used to analyze uploads as well as the one used to produce image variants.

Every Active Storage version before 8.0.5.2 is affected, along with Rails 8.1 versions before 8.1.4.1. Release series older than 8.0 are unsupported and will not receive fixed releases. Rails 8.0 is scheduled to receive security fixes only until November 7, 2026. In July, Rails fixed a separate critical Active Storage issue, CVE-2026-66066, affecting applications that use libvips rather than ImageMagick. ImageMagick applications were outside that earlier attack path but may be exposed to the newly disclosed flaw.

The same Rails releases address another Active Storage vulnerability, GHSA-v924-7rp8-4mxh, rated high with a CVSS score of 8.8. Active Storage had passed uploads to ImageMagick and FFmpeg using temporary filenames that retained the uploaded extension. When file content does not reveal its format, those tools can select a decoder based on that extension. An attacker able to choose the filename and declared content type could therefore influence which decoder processed the upload. Rails says workarounds published for this second flaw alter only FFmpeg handling and do not protect ImageMagick.

Rails 8.1.4.1 and 8.0.5.2 fix 21 security issues in total and include a new ImageMagick policy. MiniMagick, the Ruby software package Active Storage uses to call ImageMagick, applies this policy to every ImageMagick command in its default configuration, not only Active Storage commands. The rules block MSL, coders that read or delete files other than the image, coders that fetch local or remote references or display them on a screen, all Ghostscript-backed coders, the gs helper program and @filename indirection, which tells ImageMagick to read options from another file. Applications using :mini_magick also require mini_magick 5.1 or later or they will fail during startup.

Administrators should verify that the policy loads by running bin/rails runner 'puts MiniMagick.identify { |i| i.list "policy" }', as described in the Active Storage guide. It will not reach applications that replace MiniMagick.cli_env after startup, clear the environment through MiniMagick.cli_prefix or install a custom MiniMagick::Shell. Those applications must add the rules to ImageMagick's system policy. GraphicsMagick does not read ImageMagick policies, so applications using it receive no protection from the policy bundled with Rails.

The server's existing ImageMagick policy also needs review because the Rails policy supplements rather than replaces it. An existing allow rule, including a wildcard such as pattern="*", overrides a bundled block for that coder. Applications that render PDF or PostScript through ImageMagick may need to re-enable the gs helper and required coders in the server's policy.xml. If an immediate upgrade is impossible, Rails advises copying activestorage/lib/active_storage/image_magick/policy.xml into the system policy, such as /etc/ImageMagick-7/policy.xml, or applying its published patches for Rails 8.1 and 8.0. At minimum, MSL, Ghostscript coders and the gs helper should be blocked. Older Rails releases can use this workaround or move to version 8.0 or later.

Any affected application using Disk storage should replace secret_key_base and every other secret readable by the application, including the master key, values in config/credentials.yml.enc, database and storage credentials, and third-party tokens. An exposed value should not remain configured as a fallback. The advisory does not provide a method for determining whether an application was already targeted. For organizations reviewing this kind of exposure, AEU-I provides security-first IT, infrastructure and consulting.

Also available in: DeutschItalianoShqip