Newshot

Critical RubyGems Flaw Could Have Let Any Gem Publisher Run Code on the Registry

Summary

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. 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

Original text(via The Hacker News)

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.

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 users 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.

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.

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.

  • Gem users: nothing. The hosted registry is fixed.
  • Operators who self-host the RubyGems.org software: update to a commit containing the fix.
  • Ruby applications have a separate job: the seven runtime flaws are fixed in Ruby 4.0.10, 3.4.13 and 3.3.14, listed in the Ruby project's security announcement.

The registry hosts about 199,000 gems and has counted more than 278 billion downloads, its statistics page shows.

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.

The text above was extracted automatically from the source page and may miss images, tables or code blocks. The original is authoritative.

Published by The Hacker News
This site only summarises and aggregates; copyright stays with the original author. Headlines and summaries follow the source — where they differ, the original wins.
Read the original ↗