Critical RubyGems.org flaw let any gem publisher slip a malicious regex into the registry
Maintainers chained the bug with a Ruby regexp memory-corruption flaw to reach code execution in testing. They found no direct evidence of exploitation, but logs were incomplete.
RubyGems.org, the main registry for Ruby packages, has fixed a critical flaw in how it processed gem metadata. The advisory, GHSA-7h7w-m82c-x2xg, rates it 9.0 on the CVSS scale. No CVE has been assigned.
How it worked
Anyone holding an API key with push rights could include an attacker-controlled regular expression in a gem upload. The registry's validator ignored YAML's regexp tag, so the field looked like plain text and passed schema checks, and Ruby's Psych YAML library then compiled the pattern. The check ran before the registry confirmed the uploader owned the gem name, so an attacker did not need a gem of their own.
From regex to code execution
In local testing, maintainers combined the issue with a memory-corruption bug in Ruby's regexp compiler to run code. Their test used Ruby 4.0.9, which is affected by seven regexp and string-handling flaws the Ruby project patched on November 18. The advisory does not say which of those bugs was used.
Was it exploited?
Maintainers reviewed production telemetry and about 29,100 gems published between October 5 and November 4 and found no direct evidence of exploitation. They caution that logs were short-lived and upload payloads were not stored, so earlier abuse cannot be ruled out.
Fixes
- The validation fix reached the public code on November 4.
- The hosted service now rejects regexp-tagged gemspec fields, loads metadata with a restricted loader, and caps the length of OIDC policy patterns.
Who's affected
Operators of self-hosted RubyGems.org instances and Ruby application owners running unpatched Ruby versions. Ordinary gem users need not act for the registry fix itself.
What to do
Update self-hosted RubyGems.org deployments to a commit with the fix, and move Ruby applications to Ruby 4.0.10, 3.4.13 or 3.3.14 to close the related regexp memory bugs.