/00 — boot sequence

Hello.

Article

KindaRails2Shell CVE-2026-66066: Critical Rails RCE via Active Storage

August 5, 20266 min read
security cve-2026-66066 ruby-on-rails active-storage rce kindaRails2shell

KindaRails2Shell: CVE-2026-66066 Lets Attackers Read Any File and Execute Code on Rails Apps

A critical vulnerability in Ruby on Rails Active Storage lets unauthenticated attackers read arbitrary server files and escalate to remote code execution. The flaw affects Rails 7 and 8 default configurations and was independently discovered by two research teams using AI-assisted analysis.

Vulnerability Details

CVE-2026-66066 (nicknamed KindaRails2Shell) is an arbitrary file read vulnerability in Active Storage's variant processing that can chain to remote code execution. The vulnerability carries a CVSS 9.5 score and affects Ruby on Rails applications using the default :vips variant processor with libvips.

The root cause lies in a disagreement between two libraries: libvips (which routes file processing by sniffing magic bytes) and libmatio (which actually parses MATLAB files). An attacker can craft a file that libvips identifies as a MATLAB 5.0 file, but libmatio parses as an HDF5-based MATLAB 7.3 file containing an external dataset reference. When libvips processes this file to generate a thumbnail, libmatio follows the external reference and reads any file the attacker specifies.

Impact Assessment

Affected Versions

Rails Version RangeImpactConfiguration RequiredPatched Version
6.0.0 - 6.1.7.10AffectedNon-standard Active Storage config7.2.3.2
7.0.0 - 7.2.3.1AffectedActive Storage enabled (default)7.2.3.2
8.0.0 - 8.0.5AffectedActive Storage enabled (default)8.0.5.1
8.1.0 - 8.1.3AffectedActive Storage enabled (default)8.1.3.1

Who Is at Risk

Your Rails application is vulnerable if all of these conditions are true:

  1. Active Storage is used with file uploads enabled (default in Rails 7+)
  2. Variant processor is :vips (the Rails 7+ production default)
  3. libvips is built with libmatio support (true for Debian/Ubuntu packages, official Rails Docker images, and most stock installations)
  4. Untrusted loaders are not blocked (Active Storage did not set VIPS_BLOCK_UNTRUSTED by default)

This covers a massive portion of production Rails deployments: GitHub, Shopify, Basecamp, and countless self-hosted applications running on standard Rails 7 or 8 stacks.

What Attackers Can Access

When exploited, the vulnerability allows reading any file accessible to the Rails worker process, including:

  • config/master.key and config/credentials.yml.enc (enabling credential decryption)
  • SECRET_KEY_BASE and RAILS_MASTER_KEY from /proc/self/environ
  • Database credentials, API keys, and third-party service tokens
  • Source code, configuration files, and SSH keys
  • /etc/passwd, /etc/shadow, and other system files

With secret_key_base exposed, attackers can forge signed Active Storage variation keys and exploit a related issue (CVE-2025-24293) in the :vips transformer to achieve arbitrary code execution via instance_eval injection.

Affected Systems

Default Configurations That Are Vulnerable

  • Official Rails Docker images (rails new generated Dockerfiles)
  • Debian/Ubuntu packages with libvips42 (links libmatio13)
  • Heroku, Render, Fly.io default Ruby buildpacks
  • Kamal/Capistrano deployments using standard base images
  • Any Rails 7+ app that hasn't explicitly switched to ImageMagick or blocked untrusted loaders

Configurations That Are NOT Affected

  • Rails apps using ImageMagick as the variant processor (config.active_storage.variant_processor = :mini_magick)
  • Rails 6.0-6.1 apps with standard Active Storage configuration
  • Systems where libvips < 8.13 but VIPS_BLOCK_UNTRUSTED is set (requires libvips 8.13+)
  • Apps that disable Active Storage entirely or don't accept user uploads

Mitigation & Patching

Immediate Action Required: Upgrade Rails

Upgrade to the patched versions immediately:

ruby

Then run:

bash

Rotate All Credentials

After patching, assume credentials may have been compromised and rotate:

bash

Workaround: Block Untrusted Loaders (If Upgrade Is Delayed)

If you cannot upgrade immediately and have libvips 8.13+ with ruby-vips 2.2.1+, add an initializer:

ruby

Alternatively, set the environment variable:

bash

Note: This blocks processing of BMP, ICO, PSD, SVG, JPEG XL, JPEG 2000, Netpbm, FITS, NIfTI, Radiance, and OpenSlide formats. Test thoroughly.

Switch to ImageMagick (Alternative Mitigation)

ruby

Add gem "image_processing", "~> 1.12" and gem "mini_magick" to your Gemfile. This avoids the libvips/libmatio chain entirely.

Detection

Forensic Investigation Toolkit

The Rails team released official forensic tooling at rails/rails-forensics-CVE-2026-66066. It provides two agent skills:

  1. kr2s-was-i-vulnerable - Determines the exposure window (when the app was vulnerable)
  2. kr2s-was-i-exploited - Analyzes whether exploitation occurred and what data was accessed
bash

The Detector

The repository includes lib/crafted_mat_file.rb which identifies the crafted MATLAB files by reading two header fields in the first 128 bytes. The scanner (bin/kr2s_scan_active_storage_blobs.rb) can classify objects from ranged reads without full downloads.

Key Artifacts of Exploitation

The attack leaves three forensic artifacts of increasing strength:

  1. Variant records in the database showing unexpected transformations
  2. Processed variants in object storage (S3, GCS, Azure) containing stolen bytes as pixel values
  3. Access logs showing representation requests with harvested variation keys

The strongest evidence is the rendered variant itself, which holds the exfiltrated file contents as pixel data in your own object store.

WAF Detection

Akamai and other WAF vendors have deployed rules targeting the KindaRails2Shell attack pattern. However, **WAF is not a substitute for patching: the attack surface includes multiple code paths (attach-then-render, analyzers, custom transform endpoints) that may bypass WAF inspection.

Key Takeaways

  1. **Patch immediately: Upgrade to Rails 7.2.3.2, 8.0.5.1, or 8.1.3.1 today. This is not a theoretical risk; working exploits exist and are circulating.

  2. **Rotate all credentials: Assume secret_key_base, database passwords, API keys, and storage credentials are compromised. The file read primitive makes credential theft trivial.

  3. **Run the forensic tools: Use rails/rails-forensics-CVE-2026-66066 to determine your exposure window and check for signs of exploitation.

  4. **Default Rails 7+ config is vulnerable: The :vips processor with libmatio-enabled libvips is the shipped default. Most production Rails apps are affected unless they explicitly switched to ImageMagick.

  5. **AI-accelerated vulnerability research is here: Two independent teams used different Claude models to discover the same chain. Expect more complex, multi-library confusion vulnerabilities to surface rapidly.

  6. **Defense in depth matters: The fix (blocking untrusted libvips loaders) is a defense-in-depth measure that breaks the chain at the library level, not just the application level.

Conclusion

CVE-2026-66066 (KindaRails2Shell) represents a sophisticated vulnerability chain that exploits a disagreement between two widely-used libraries (libvips and libmatio) routed through Rails Active Storage's trust in client-declared content types. The result is an unauthenticated arbitrary file read that escalates to remote code execution on default Rails 7+ configurations.

The vulnerability was discovered through AI-assisted source code analysis by two independent teams, signaling a shift in how complex vulnerability chains are found. For Rails developers, the message is clear: upgrade now, rotate credentials, and run the forensic investigation to understand your exposure.

The Rails team's rapid response (fix shipped within days of disclosure) and release of forensic tooling set a strong example for framework vulnerability response. But the window for safe patching is closing: exploit code is public, Metasploit modules are emerging, and the attack requires only a single crafted file upload.


Sources:

Automated Transmission

This entry was synthesized and populated dynamically using native API integrations.

Resources & Links