RubyGems.org, the central registry for the Ruby community's gems, has fixed a critical flaw that let any account with a push-capable API key feed an attacker-controlled regular expression into the metadata of a gem upload.
Sources indicate that in local testing, the registry's maintainers chained the flaw with a memory corruption bug in Ruby's regexp compiler and reached remote code execution, they said in an advisory last week. Gem owners do not need to do anything.
A review of production telemetry and 29,100 gems published between October 5 and November 4 found "no direct evidence of exploitation," the advisory says. Gaps remain: logs were not kept long enough, and upload payloads were not recorded, so earlier attempts cannot be ruled out.
It has been revealed that the flaw is tracked as GHSA-7h7w-m82c-x2xg and scores 9.0 on the CVSS scale, with no CVE assigned. It sat in how the registry reads the metadata a gem carries as YAML.
In a recent development, the validator that screens that metadata ignored the !ruby/regexp YAML tag, so a field carrying the tag passed schema checks as plain text. Ruby's YAML library, Psych, then turned the field into a real regular expression, compiling whatever pattern the attacker supplied.
All of this ran before the registry checked whether the account owned the gem name, so an attacker needed no gem of their own, only a push-capable API key.
The test ran on Ruby 4.0.9, a version affected by the seven flaws in Ruby's regexp engine and string case conversion that the Ruby project patched on November 18. The advisory does not say which memory corruption bug the chain used.
Even on a Ruby build that is not vulnerable to code execution, compiling an attacker's pattern can crash an upload worker or exhaust its memory.
On the hosted service, schema validation now rejects regexp-tagged gemspec fields with an HTTP 422 error, according to the registry's security advisory. Gem metadata is also read with a restricted loader that refuses YAML aliases and allows only the handful of classes a valid gemspec uses. Patterns in OIDC access policies are capped at 255 characters before they are compiled, as an extra safeguard.
The validation change entered the registry's public code repository on November 4 (UTC), three weeks before the disclosure; its commit history shows.
The registry hosts about 199,000 gems and has counted more than 278 billion downloads, its statistics page demonstrates.
The code execution in the maintainers' test came with the privileges of the gem-upload worker, in a local environment. The advisory does not say whether an attacker who got that far could have reached published gems or publishing credentials.
Discover why SHA pinning alone isn't enough and learn how to close hidden security gaps in your GitHub Actions pipelines.
Learn what 6,000 real-world attacks reveal about MFA weaknesses and how to stop AI-driven phishing and account takeovers.
Get the latest news, expert insights, exclusive resources, and strategies from industry leaders, all for free.
