News Application Security

RubyGems.org fixes critical deserialization flaw in its gem push path

A GitHub Security Advisory describes a critical flaw in RubyGems.org's gem upload path, where an attacker-controlled regular expression was deserialized from YAML before the ownership check ran. Maintainers reproduced code execution in local testing, the hosted service is fixed, and they report no direct evidence of exploitation.

Application and infrastructure security, over a decade in the field Published
Minimal line-art banner of a gem being pushed into a registry box, with the headline about the RubyGems.org deserialization flaw

Key takeaways

  • RubyGems.org's gem push validator ignored the !ruby/regexp YAML tag, so an attacker regex was compiled before the ownership check.
  • Any account with a push-capable API key could reach the flaw, with no existing gem required.
  • Code execution was reproduced in local testing, not on the live service, and maintainers found no direct evidence of exploitation.
  • The hosted service is fixed, but self-hosted RubyGems.org operators must update themselves.
  • The fix switches to safe YAML loading with a restricted class loader and rejects the tag outright.

The RubyGems.org maintainers have disclosed and fixed a critical unsafe deserialization flaw in the registry's gem push endpoint. The advisory, GHSA-7h7w-m82c-x2xg, was published on 26 November in the rubygems/rubygems.org repository. It is rated Critical, classified as CWE-502 (Deserialization of Untrusted Data), and has no CVE assigned.

What went wrong #

When a gem is pushed to POST /api/v1/gems, the service validates the gemspec YAML. According to the advisory, the validator ignored the !ruby/regexp YAML tag. Psych then deserialized that field into an attacker-controlled regular expression, which was compiled before the gem-name ownership check ran.

Two details make this serious:

  • It was exploitable by "any authenticated user with a push-capable API key". The attacker did not need to own an existing gem.
  • Maintainers chained it with a memory corruption bug in Ruby's regexp compiler to reach code execution with the privileges of the gem-upload worker process. The advisory does not name that Ruby bug.

Precision matters here. The advisory says code execution was reproduced locally, not against the live service. Even on builds not vulnerable to code execution, it adds, regexp compilation could crash a worker or exhaust its memory.

Was it exploited? #

The maintainers reviewed production telemetry and 29,100 gems published between 5 October and 4 November and found "no direct evidence of exploitation". They also note that log retention limits and unlogged upload payloads mean earlier attempts cannot be ruled out.

The fix #

  • !ruby/regexp was removed from the validator's ignored tags, so pushes carrying the tag are now rejected with HTTP 422.
  • to_ruby was replaced with safe_to_ruby, using a restricted Psych class loader and a visitor that disallows aliases.
  • OIDC access policy string_matches patterns are capped at 255 characters.
  • A RegexpError during token exchange now becomes an access error.

What to do #

Gem users need no action, because the hosted service is fixed. Operators of a self-hosted RubyGems.org deployment should update to a commit containing the fix.

For everyone else, this is a clean lesson in parser trust boundaries. Untrusted YAML reached object construction before authorization. If your application loads YAML from users, use a safe loader with an explicit class allowlist, reject unknown tags instead of ignoring them, and run authorization checks before parsing anything expensive. A package registry is a single point of trust for a language ecosystem, which is why a bug in the upload path deserves this much attention.

Sources

  1. Authenticated remote code execution in RubyGems.org gem pushes via !ruby/regexp gemspec tags, GitHub Security Advisory (rubygems/rubygems.org)
  2. Critical RubyGems Flaw Could Have Let Any Gem Publisher Run Code on the Registry, The Hacker News

Questions this raises

Do I need to update my gems or Bundler?
No. The flaw is in the RubyGems.org service, not in client tooling. The advisory says gem users need no action because the hosted service is fixed.
Was RubyGems.org compromised?
The maintainers report no direct evidence of exploitation after reviewing production telemetry and 29,100 published gems. They add that log retention and unlogged upload payloads do not rule out earlier attempts.
Is there a CVE for this issue?
No. The advisory lists no known CVE. Track it by its GitHub advisory ID, GHSA-7h7w-m82c-x2xg.

rubygemsdeserializationsupply-chain