A critical unsafe-deserialization defect in the RubyGems.org gem-publishing pipeline let any account with a push-capable API key reach attacker-controlled regexp compilation.
In local testing on Ruby 4.0.9, chaining it with a regexp-compiler memory corruption bug produced remote code execution. The flaw is tracked as GHSA-7h7w-m82c-x2xg, has no CVE, and is classified under CWE-502.
The defect sits in the POST /api/v1/gems upload path. GemValidator::Package checks the gemspec YAML abstract syntax tree against a schema, then calls gemspec_ast.to_ruby to build Ruby objects.
RubyGems.org Gem Push Flaw
GemValidator::NodeInfo::IGNORED_TAGS contained !ruby/regexp, so GemValidator::NodeInfo.read_tag returned nil for any node carrying that tag.
A field such as summary: !ruby/regexp /…/ therefore passed schema validation as an ordinary untagged scalar. Psych then deserialized it into a live Regexp object and compiled the attacker’s pattern inside the upload process.
Our coverage of software supply-chain attacks shows how often registry ingestion code becomes the weakest link.
Validation and deserialization run before the Pusher component enforces gem-name ownership. An attacker needs only a RubyGems.org account and an API key with push scope, with no ownership of any existing package.
The advisory’s CVSS v4 vector is CVSS:4.0/AV:N/AC:H/AT:P/PR:L/UI:N/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H. That means network reachability, high attack complexity, present attack requirements, low privileges, no user interaction, and high confidentiality, integrity, and availability impact on both the vulnerable and subsequent systems.
Maintainers reproduced code execution on Ruby 4.0.9 by pairing the unrestricted regexp deserialization with a memory corruption bug in Ruby’s regexp compiler. Execution ran with the privileges of the gem-upload worker process.
On Ruby builds without that compiler bug, hostile patterns can still trigger catastrophic backtracking or memory exhaustion, crashing workers and degrading publishing availability. Related remote code execution cases show that deserialisation gadgets in trusted build services often lead to wider compromise.
The testing used a local Ruby 4.0.9 environment, not the live service. Maintainers reviewed production telemetry and 29,100 gems published between 5 October and 4 November 2026. They found no direct evidence of exploitation. They also warned that limited log retention and unlogged upload payloads cannot rule out earlier attempts.
Because the worker handles every inbound package, a successful compromise could expose registry secrets, signing material or adjacent infrastructure. That is why this class of defect draws attention from defenders tracking package registry abuse.
Maintainers removed !ruby/regexp from GemValidator::NodeInfo::IGNORED_TAGS. Schema validation now rejects regexp-tagged fields before deserialization and returns HTTP 422 with the message expected no tag, but got ‘!ruby/regexp” for path /summary.
They also replaced unrestricted to_ruby calls in GemValidator::Package with safe_to_ruby. That method uses Psych::ClassLoader::Restricted and Psych::Visitors::NoAliasRuby to refuse YAML aliases and block Ruby classes in checksums.yaml.
It permits only the classes a valid gemspec needs: Gem::Specification, Gem::Version, Gem::Requirement, Gem::Dependency, Gem::Version::Requirement, Symbol, Time and Date.
As defence in depth, OIDC::AccessPolicy string_matches patterns are now capped at 255 characters before compilation. RegexpError raised during token exchange is converted into an AccessError, which blocks regexp-compiler exhaustion through trusted publishing policies. Credit for the remediation goes to colby-swandale and dkw-oss, and the entry is listed in the GitHub Advisory Database.
RubyGems.org is a hosted service, so gem consumers need no action. The advisory lists no patched package version because the fix ships as service code. Operators of self-hosted RubyGems.org deployments must update to a commit containing these changes.
They should also audit upload-worker logs for gemspec metadata containing !ruby/regexp tags, unexpected HTTP 422 spikes on /api/v1/gems, and worker crashes or memory exhaustion events.
Teams should rotate API keys with push scope, enforce least-privilege scoping, and require MFA on publishing accounts. Any code that calls YAML.load, Psych.unsafe_load or to_ruby on untrusted input should move to safe_load with explicit permitted classes.
Ruby 4.0.9 users should track upstream fixes for the regexp-compiler memory corruption bug, since it is the second link in the chain. Broader CWE-502 activity remains heavy, with thousands of deserialization advisories in the database.
FAQ
Does this flaw have a CVE? No, it is tracked only as GHSA-7h7w-m82c-x2xg with Critical severity.
Do gem users need to patch? No, RubyGems.org is hosted, and only self-hosted operators must update to a fixed commit.
Was it exploited in the wild? Maintainers found no direct evidence after reviewing telemetry and 29,100 gems, though they can’t fully rule out earlier attempts.
What access does an attacker need? A RubyGems.org account with a push-capable API key, with no ownership of any gem.