Protect.Computer
NEWS

RubyGems.org Fixes Critical Flaw in Gem Upload Validation

· 2 min read · Got hacked
RubyGems.org Fixes Critical Flaw in Gem Upload Validation

RubyGems.org, the central registry for the Ruby community’s packages, has fixed a critical flaw in how it checks the metadata of an uploaded gem. In its security advisory (GHSA-7h7w-m82c-x2xg, scored 9.0 on CVSS, no CVE assigned) the maintainers say the upload validator ignored the !ruby/regexp YAML tag, so a field carrying it passed validation as plain text and was then turned into a real regular expression by Ruby’s YAML library. The pattern was compiled before the registry checked whether the account owned the gem name, so any account with a push-capable API key could reach it.

On its own that can crash an upload worker or exhaust its memory. The advisory says that on Ruby 4.0.9, chaining it with a memory-corruption bug in Ruby’s regexp compiler gave remote code execution with the privileges of the gem-upload worker, reproduced locally rather than against the live service. The test ran on Ruby 4.0.9, a version affected by the seven Ruby flaws patched on November 18 (our earlier post covers those), according to The Hacker News; the advisory does not say which memory bug the chain used. The maintainers reviewed production telemetry and the 29,100 gems published between October 5 and November 4 and found “no direct evidence of exploitation,” but say limited log retention and unlogged upload payloads mean earlier attempts cannot be ruled out. Neither the advisory nor The Hacker News says whether an attacker who reached code execution could have touched published gems or publishing credentials.

How to check if you’re affected

Affected products are self-hosted RubyGems.org deployments: the hosted service is already fixed, and the advisory says gem users do not need to take action. Operators of a self-hosted deployment should update to a commit that contains the fix. The validation change reached the project’s public repository on November 4 (UTC), according to The Hacker News.

  • The fix, per the advisory, makes schema validation reject regexp-tagged gemspec fields with an HTTP 422 error, reads gem metadata with a restricted YAML loader that refuses aliases and allows only the classes a valid gemspec uses, and caps OIDC access-policy patterns at 255 characters before they are compiled.
  • Separately, the seven Ruby runtime flaws patched on November 18 affect Ruby 3.3.13 and earlier, Ruby 3.4.0 through 3.4.12 and Ruby 4.0.0 through 4.0.9, per the Ruby project’s announcement; the fixed releases are 4.0.10, 3.4.13 and 3.3.14. Check application servers with ruby -v. Ruby 3.2 and earlier are end of life and get no fix.

Sources

Related reading