One Push Key Was All It Took to Run Code on RubyGems.org
RubyGems.org fixed a CVSS 9.0 flaw that let any push-capable API key feed a hostile regex into gem metadata; maintainers chained it to code execution in testing but found no exploitation.
RubyGems.org has fixed a critical flaw that let anyone holding a push-capable API key slip an attacker-chosen regular expression into a gem’s metadata and get the registry to compile it, according to The Hacker News. In local testing, the registry’s maintainers chained it with a memory-corruption bug in Ruby’s regex engine and reached code execution on the upload worker. They found no direct evidence it was used, but say they can’t rule out earlier attempts because logs weren’t kept long enough.
For defenders
| Advisory | GHSA-7h7w-m82c-x2xg, no CVE assigned |
| CVSS | 9.0 |
| Affected | The RubyGems.org registry software (the hosted service is fixed; self-hosted copies need a commit with the fix) |
| Exploitation | None found. Maintainers reviewed production telemetry and 29,100 gems published Oct. 5 to Nov. 4; upload payloads weren’t recorded, so older attempts can’t be excluded |
| Fix landed | Nov. 4 (UTC) in the public repository, three weeks before disclosure |
How it worked: the validator that screens gemspec metadata ignored the !ruby/regexp YAML tag, so a tagged field passed schema checks as text. Ruby’s YAML library (Psych) then built a real regex from it. All of this ran before the registry checked whether the uploader owned the gem name, so an attacker needed only a push-capable key, not a gem of their own. The maintainers’ code-execution test ran on Ruby 4.0.9, which is affected by the seven regex and string flaws Ruby patched on Nov. 18; the advisory doesn’t say which bug the chain used. On a non-vulnerable Ruby, a hostile pattern could still crash a worker or exhaust its memory.
What changed: regexp-tagged gemspec fields now get an HTTP 422, metadata is read with a restricted loader that refuses YAML aliases and allows only the classes a valid gemspec needs, and patterns in OIDC access policies are capped at 255 characters.
Open question: the advisory doesn’t say whether code running as the upload worker could have reached published gems or publishing credentials.
What it means for you
If you install Ruby gems, you don’t need to do anything about the registry bug; it’s fixed on the server. It matters because RubyGems.org hosts about 199,000 gems with more than 278 billion downloads, and a takeover of the place that hands out code would put every one of those downloads at risk. The separate Ruby language fixes from Nov. 18 are a different job and do need your attention if you run Ruby apps.
Do this now
- Gem users: nothing to do for this advisory.
- If you self-host the RubyGems.org application, update to a commit that includes the Nov. 4 validation fix.
- Upgrade Ruby itself to 4.0.10, 3.4.13 or 3.3.14 to close the seven regex and string flaws from the Nov. 18 security announcement.
- Review who holds push-capable RubyGems API keys in your organization, and scope or rotate any that aren’t needed.