RubyGems Fixes Critical Flaw That Let Any Publisher Push Code Execution Into the Registry
RubyGems.org, the central registry for Ruby gems, has fixed a critical flaw that let any account holding a push-capable API key feed an attacker-controlled regular expression into the metadata of a gem upload. Maintainers said in an advisory that gem users do not need to take any action.
The problem sat in how the registry reads the YAML metadata a gem carries. The validator that screens this data ignored the !ruby/regexp YAML tag, so a field carrying it passed checks as plain text. Ruby's YAML library, Psych, then turned the field into a real regular expression and compiled whatever pattern the attacker supplied. All of this happened before the registry checked who owned the gem name, so an attacker needed no gem of their own, only a push-capable key.
In local testing, the maintainers chained the flaw with a memory corruption bug in Ruby's regexp compiler and reached remote code execution, running with the privileges of the gem-upload worker. The test used Ruby 4.0.9, which was affected by seven regexp and string conversion flaws the Ruby project patched on November 18. The advisory does not say which bug was used, or whether an attacker could have reached published gems or publishing credentials. Even without code execution, a malicious pattern could crash an upload worker or exhaust its memory.
A review of production telemetry and 29,100 gems published between October 5 and November 4 found no direct evidence of exploitation. However, logs were not kept long enough and upload payloads were not recorded, so earlier attempts cannot be ruled out. The flaw is tracked as GHSA-7h7w-m82c-x2xg, scores 9.0 on CVSS and has no CVE. The hosted service now rejects regexp-tagged fields with an HTTP 422 error, reads metadata with a restricted loader, and caps OIDC policy patterns at 255 characters.
Why it matters
The flaw shows that the barrier to attacking a package registry can be as low as one push-capable API key, because the dangerous parsing ran before any ownership check. Organisations that publish gems are exposed through those keys, and they cannot rely on the registry's logs to prove nothing happened earlier, since retention was too short and payloads were not recorded. It also forces a decision on whether leaked or stale publishing keys are treated as a path to the registry itself, not just to their own gems.
What to do
- Review and revoke unused or over-broad push-capable RubyGems API keys in your organisation.
- Update Ruby to a build that includes the November 18 regexp engine patches if you run your own Ruby services.
- Audit your own gem metadata handling for code that loads YAML with unrestricted classes.
- Check your RubyGems account activity for unexpected uploads or key use from October 5 onward.