CVE-2022-21831: Possible code injection vulnerability in Rails / Active Storage
Active Storage in Rails allowed untrusted input to be passed as image transformation method or arguments, leading to possible code injection. An attacker could achieve remote code execution if the application used such vulnerable code patterns.
- Triaged in 23 hours
- Fixed in 15 days
- Paid in 15 days
- Disclosed after 45 days
Summary by the program
[CVE-2022-21831] Possible code injection vulnerability in Rails / Active Storage
There is a possible code injection vulnerability in the Active Storage module of Rails. This vulnerability has been assigned the CVE identifier CVE-2022-21831.
Versions Affected: >= 5.2.0 Not affected: < 5.2.0 Fixed Versions: 7.0.2.3, 6.1.4.7, 6.0.4.7, 5.2.6.3
Impact There is a possible code injection vulnerability in the Active Storage module of Rails. This vulnerability impacts applications that use Active Storage with the image_processing processing in addition to the mini_magick back end for image_processing.
Vulnerable code will look something similar to this:
<%= image_tag blob.variant(params[:t] => params[:v]) %> Where the transformation method or its arguments are untrusted arbitrary input.
All users running an affected release should either upgrade or use one of the workarounds immediately.
Releases The fixed releases are available at the normal locations.
Workarounds To work around this issue, applications should implement a strict allow-list on accepted transformation methods or arguments. Additionally, a strict image magick security policy will help mitigate this issue.
ImageMagick – Security Policy 70
Patches To aid users who aren’t able to upgrade immediately we have provided patches for the two supported release series. They are in git-am format and consist of a single changeset.
5-2-active-storage-code-injection.patch - Patch for 5.2 series 6-0-active-storage-code-injection.patch - Patch for 6.0 series 6-1-active-storage-code-injection.patch - Patch for 6.1 series 7-0-active-storage-code-injection.patch - Patch for 7.0 series Please note that only the 7.0.Z, 6.1.Z, 6.0.Z, and 5.2.Z series are supported at present. Users of earlier unsupported releases are advised to upgrade as soon as possible as we cannot guarantee the continued availability of security fixes for unsupported releases.
Credits Thanks to @gquadros_ for reporting this and Zack Deveau of Shopify for writing the patches
Link to Security Advisory: https://discuss.rubyonrails.org/t/cve-2022-21831-possible-code-injection-vulnerability-in-rails-active-storage/80199 Link to GHSA: https://github.com/advisories/GHSA-w749-p3v6-hccq
The report
Original report: https://hackerone.com/reports/1154034 Rails advisory: https://discuss.rubyonrails.org/t/cve-2022-21831-possible-code-injection-vulnerability-in-rails-active-storage/80199 Blogpost: https://blog.convisoappsec.com/en/cve-2022-21831-overview-of-the-security-issues-we-found-in-railss-image-processing-api/
If the report is eligible for a bounty, please split it equally between me and @rsilva, if possible.
Impact
Vulnerable code patterns could allow the attacker to achieve RCE.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the application passed untrusted user input directly as the transformation method or arguments to image_processing with the mini_magick back end, without validating or restricting the allowed values.
What the attacker needed
Rails >= 5.2.0; Active Storage with image_processing; mini_magick back end; untrusted input for transformation
The fix
The vulnerability was fixed in versions [redacted], [redacted], [redacted], and [redacted]; as a workaround, applications should implement a strict allow-list on accepted transformation methods or arguments and use a strict ImageMagick security policy.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Active Storage is a Rails feature for handling uploaded files like images. If a website lets a user choose how an image is resized or processed without checking the input, an attacker may be able to inject code. This is called code injection, and it could potentially let the attacker run commands on the server.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.