Critical RubyGems.org Flaw Allowed Attacker-Controlled Regex in Gem Metadata Leading to Potential RCE

RubyGems.org has patched a critical vulnerability that permitted any account holding a push-capable API key to inject an attacker-controlled regular expression into gem metadata during upload. The registry's maintainers demonstrated remote code execution by chaining the flaw with a memory corruption issue in Ruby's regexp compiler during local testing. The issue stemmed from the YAML metadata validator ignoring the !ruby/regexp tag, allowing Psych to deserialize and compile arbitrary patterns before ownership checks occurred. No evidence of exploitation was found in a review of 29,100 gems published between October 5 and November 4, though logging limitations prevent ruling out earlier attempts. The flaw, tracked as GHSA-7h7w-m82c-x2xg with a CVSS score of 9.0, has been mitigated through stricter schema validation and a restricted YAML loader. Self-hosted operators must update their instances, while Ruby users should apply patches in versions 4.0.10, 3.4.13, and 3.3.14 to address related runtime issues.

The Hacker NewsTranslated from English

Read at source

RubyGems.org, the central registry for Ruby gems, has fixed a critical flaw that allowed any account with a push-capable API key to feed an attacker-controlled regular expression into gem metadata during upload.

In local testing, maintainers chained the issue with a memory corruption bug in Ruby's regexp compiler and achieved remote code execution. Gem users require no action as the hosted service is now secured. A review of production telemetry covering 29,100 gems published between October 5 and November 4 found no direct evidence of exploitation, though gaps in logging and payload recording leave earlier attempts unruled out.

The vulnerability, tracked as GHSA-7h7w-m82c-x2xg and scoring 9.0 on CVSS, resided in how the registry processed YAML metadata from gems. The validator overlooked the !ruby/regexp YAML tag, permitting fields to pass schema checks as plain text. Ruby's YAML library Psych then converted the field into a real regular expression, compiling any pattern supplied by the attacker before ownership verification of the gem name.

The test environment used Ruby 4.0.9, affected by seven flaws in the regexp engine and string case conversion patched on November 18. Even without code execution, compiling malicious patterns could crash upload workers or exhaust memory. Schema validation now rejects regexp-tagged gemspec fields with an HTTP 422 error, and metadata is processed with a restricted loader that disallows YAML aliases.

Additional safeguards include capping patterns in OIDC access policies at 255 characters. The fix was committed to the public repository on November 4. Self-hosted operators must update to a patched commit, while Ruby applications should migrate to Ruby 4.0.10, 3.4.13, or 3.3.14.

Meridian digestThe week's most consequential security stories, distilled into one briefing.See the digest

More in Supply Chain & OSS

Q-Dir and DesktopOK Utilities Compromised to Deliver Python RAT via Official Channels
Supply Chain Attack Trojanizes Official Q-Dir and DesktopOK Installers to Deploy Python RAT
SAP Confirms Security Incident After Attackers Breach GitHub Environment and Modify Source Code