Skip to content

Vulnerabilities & Patches

RubyGems.org fixes critical flaw letting API keyholders run code on the registry

The registry logs the flaw as GHSA-7h7w-m82c-x2xg, rates it 9.0 on CVSS, and has assigned no CVE.

https://breach-signal.com/vulnerabilities/rubygems-api-key-remote-code-execution-flaw/

Share

Key facts

  • The registry tracks the issue as GHSA-7h7w-m82c-x2xg, rates it 9.0 on CVSS, and has assigned no CVE.
  • The validator screening that metadata overlooked the !ruby/regexp YAML tag, allowing a tagged field to pass schema checks as plain text.
  • Psych, Ruby's YAML library, converted the field into an actual regular expression and compiled the attacker-supplied pattern.
  • The registry did not keep logs long enough and did not record upload payloads, so earlier exploitation attempts cannot be ruled out.

RubyGems.org fixed a critical flaw in its hosted registry that allowed anyone holding a push-capable API key to insert hostile regular expressions into gem metadata, and commit history shows the fix reached the public code repository on Nov. 4 in Coordinated Universal Time, three weeks prior to disclosure. The maintainers laid out the chain in the advisory. The Hacker News reported on the advisory.

The registry logs the issue under GHSA-7h7w-m82c-x2xg. It rates the flaw 9.0 on CVSS, a vulnerability severity scoring system, and has assigned no CVE to the flaw.

The problem lay in how the registry handles gem metadata carried as YAML, a data-serialization format. The validator that screens that metadata missed the !ruby/regexp YAML tag. As a result, a tagged field passed schema checks as plain text.

Psych, the YAML library for Ruby, turned the field into a real regular expression and compiled the attacker’s pattern. The registry processed the metadata before checking who owned the gem name. An attacker required just a push-capable API key and no gem of their own.

Maintainers connected the metadata weakness to a memory corruption flaw in Ruby’s regular-expression compiler during lab tests and obtained remote code execution. Testing ran on Ruby 4.0.9. The code execution ran under the privileges of the upload worker. That worker handles gem uploads.

The advisory leaves the exact memory corruption bug in the chain unnamed. It also does not say if someone who reached that point could get to published gems or publishing credentials. Building an attacker-supplied pattern can take down an upload worker or drain memory on a Ruby build that is otherwise safe from code execution.

Ruby 4.0.9 is affected by seven flaws in its regular-expression engine and string case conversion. The Ruby project issued patches for those seven flaws on Nov. 18. Its security announcement names Ruby 4.0.10, 3.4.13 and 3.3.14 as the fixes for those seven runtime flaws.

The advisory says a review of production telemetry covering 29,100 gems published between Oct. 5 and Nov. 4 found no direct sign of exploitation. The registry did not retain logs long enough and never recorded upload payloads. Earlier intrusion attempts cannot be ruled out.

The hosted registry‘s schema validation now turns away gemspec fields that carry regexp tags, answering with an HTTP 422 error. A separate loader handles gem metadata, rejects YAML aliases and allows only the limited classes found in a valid gemspec, the metadata file for a gem. It also limits patterns in OIDC access policies to 255 characters before compiling them.

People who use gems do not need to do anything because the hosted registry has been fixed. Anyone running their own copy of the RubyGems.org software must apply a commit containing the fix. The statistics page counts roughly 199,000 hosted gems and more than 278 billion downloads.

Was this helpful?

Join the discussion

Please read our Comment Policy before commenting. First-time comments are held for moderation. By posting a comment you agree to our Terms of Use and Privacy Policy, which explain how your name, email address and comment are used.

Your email address will not be published. Required fields are marked *