CVE-2022-21831

9.8 CRITICAL

📋 TL;DR

This is a critical code injection vulnerability in Ruby on Rails Active Storage that allows attackers to execute arbitrary code by manipulating image_processing arguments. It affects all applications using Active Storage v5.2.0 and later. Attackers can achieve remote code execution on vulnerable systems.

💻 Affected Systems

Products:
  • Ruby on Rails Active Storage
Versions: >= v5.2.0
Operating Systems: All operating systems running Ruby on Rails
Default Config Vulnerable: ⚠️ Yes
Notes: Affects all applications using Active Storage's image processing functionality. The vulnerability is in the Active Storage gem itself.

📦 What is this software?

⚠️ Risk & Real-World Impact

🔴

Worst Case

Full system compromise with attacker gaining complete control over the server, allowing data theft, lateral movement, and persistent access.

🟠

Likely Case

Remote code execution leading to application compromise, data exfiltration, and potential deployment of malware or ransomware.

🟢

If Mitigated

Limited impact with proper input validation and security controls, potentially resulting in denial of service or limited data exposure.

🌐 Internet-Facing: HIGH
🏢 Internal Only: MEDIUM

🎯 Exploit Status

Public PoC: ⚠️ Yes
Weaponized: LIKELY
Unauthenticated Exploit: ⚠️ Yes
Complexity: LOW

Exploitation requires the ability to upload or process images through Active Storage. Public proof-of-concept code exists in security advisories.

🛠️ Fix & Mitigation

✅ Official Fix

Patch Version: Rails 7.0.2.4, 6.1.4.6, 6.0.4.8, or upgrade to Active Storage gem v7.0.2.4, v6.1.6.1, v6.0.6.1

Vendor Advisory: https://github.com/advisories/GHSA-w749-p3v6-hccq

Restart Required: Yes

Instructions:

1. Update Rails gem to patched version. 2. Run 'bundle update rails' or 'bundle update activestorage'. 3. Restart application server. 4. Verify update with 'bundle show rails'.

🔧 Temporary Workarounds

Disable Active Storage image processing

all

Temporarily disable Active Storage's image processing functionality if not essential

# In config/application.rb or environment config
# config.active_storage.variant_processor = nil

Input validation for image parameters

all

Implement strict validation for image_processing parameters before passing to Active Storage

# In controller actions processing images
# Validate and sanitize all image processing parameters

🧯 If You Can't Patch

  • Implement strict input validation and sanitization for all image processing parameters
  • Deploy web application firewall (WAF) rules to block suspicious image processing requests

🔍 How to Verify

Check if Vulnerable:

Check Rails version with 'rails --version' or check Gemfile.lock for Active Storage version >=5.2.0

Check Version:

rails --version

Verify Fix Applied:

Verify Rails version is 7.0.2.4+, 6.1.4.6+, or 6.0.4.8+. Check Gemfile.lock shows patched Active Storage version.

📡 Detection & Monitoring

Log Indicators:

  • Unusual image processing requests with suspicious parameters
  • Errors in Active Storage logs related to image processing

Network Indicators:

  • HTTP POST requests to Active Storage endpoints with unusual image parameters
  • Requests containing shell commands in image processing parameters

SIEM Query:

source="rails.log" AND "ActiveStorage" AND ("image_processing" OR "variant") AND ("error" OR "exception")

🔗 References

📤 Share & Export