Skip to content
Hacker Posts
VulnerabilityRCE

RubyGems.org regexp YAML flaw let any publisher run code (9.0)

A !ruby/regexp YAML tag in gem metadata reached Psych deserialization on RubyGems.org, enabling RCE from any push-capable API key. The hosted registry is fixed. GHSA-7h7w-m82c-x2xg.

Hacker Posts DeskPublished 3 min read

RubyGems.org's gem-push validator ignored the !ruby/regexp YAML tag in gem metadata, letting the registry deserialize an attacker-controlled regular expression — a path the maintainers chained to remote code execution in local testing. Any account with a push-capable API key could trigger it, with no gem of its own required. The advisory, GHSA-7h7w-m82c-x2xg, rates it CVSS v4 9.0 (CWE-502, no CVE assigned). The hosted registry is already fixed; self-hosting operators must act.

The primary source is the maintainers' GitHub Security Advisory, corroborated by reporting at The Hacker News.

What the bug does

The metadata validator's allowlist ignored the !ruby/regexp tag, so a gemspec field carrying it passed schema checks. Ruby's Psych library then compiled the attacker's regular expression. On Ruby 4.0.9, the maintainers chained this with a memory-corruption bug in Ruby's regexp compiler to reach code execution with the gem-upload worker's privileges. Critically, the gem-name ownership check runs after validation and deserialization, so the attacker needed no existing gem. Even on a non-vulnerable Ruby build, the attacker-controlled pattern could crash an upload worker or exhaust its memory.

Exploitation status

The maintainers reviewed production telemetry and the 29,100 gems published between October 5 and November 4 and "found no direct evidence of exploitation." They caveat that log retention was limited and upload payloads weren't recorded, so earlier attempts can't be ruled out. The RCE was reproduced locally against Ruby 4.0.9, not against the live service.

The fix

Per the advisory, the registry fix landed in the public repository on November 4 (UTC), roughly three weeks before disclosure:

  • Schema validation now rejects regexp-tagged gemspec fields with HTTP 422.
  • Metadata is read with a restricted safe_to_ruby loader that refuses YAML aliases and allows only the classes a valid gemspec needs.
  • OIDC string_matches patterns are capped at 255 characters before compilation.

Separately, the Ruby project patched the seven underlying runtime flaws in Ruby 4.0.10, 3.4.13, and 3.3.14 on November 18.

Action checklist

  1. Public RubyGems.org users: nothing to do. The hosted registry is patched.
  2. Self-hosted registry operators: update to a commit that includes the fix from the rubygems.org repo, then restart upload workers.
  3. Upgrade your Ruby runtime to 4.0.10, 3.4.13, or 3.3.14 to close the regexp-compiler flaws, especially on any host that parses untrusted gemspecs.
  4. Rotate push-capable API keys that are broadly scoped or shared across CI; least-privilege keys limit blast radius if one leaks.

Context

This is the second registry-side supply-chain scare in a week after the hex.pm unauthenticated deserialization RCE — both come down to a package index trusting serialized data it should have treated as hostile. The reassuring difference here is that the hosted registry fixed it quietly three weeks before telling anyone, and the telemetry review turned up nothing. The uncomfortable part is the same as always with deserialization: the ownership check that would have limited who could reach the sink ran one step too late.