79% vs 51%: independent neobanks lag on app security. Read the report

Deep Dive

Deep Dive

RubyGems.org Gem Push RCE (GHSA-7h7w-m82c-x2xg)

Any RubyGems.org account with a push-capable API key could pass a !ruby/regexp gemspec field that Psych compiled; the hosted registry is fixed.

TL;DR

  • A gem-push validator ignored the !ruby/regexp YAML tag, and Psych then compiled the attacker's pattern inside the upload worker. On Ruby 4.0.9 the maintainers chained this to code execution in local testing.
  • Self-hosted RubyGems.org deployments whose code predates the fix are affected. The hosted rubygems.org service is fixed. The attacker needs an account and a push-capable API key, not ownership of a gem.
  • GitHub rates it Critical, CVSS v4.0 9.0. Reviewing 29,100 gems published from 2026-10-05 to 2026-11-04 found no direct exploitation evidence. No CVE is assigned, so no CISA KEV entry exists as of 2026-11-30.
  • Gem users need to do nothing. Self-hosted operators update to a commit containing the fix. Ruby applications should also install Ruby 4.0.10, 3.4.13 or 3.3.14 for the separate regexp flaws.

Am I affected?

A deployment is exposed when it runs the RubyGems.org server code and accepts gem pushes from accounts that hold a push-capable API key. All of these conditions must hold:

  • You operate a self-hosted deployment of the RubyGems.org software.
  • The self-hosted code predates the fix, which entered the public repository on 2026-11-04.
  • The deployment accepts gem pushes from accounts with push-capable API keys.
  • For the code-execution outcome, the deployment runs a Ruby build affected by the regexp compiler flaws, such as Ruby 4.0.9. Other builds can still lose an upload worker to a crash or memory exhaustion.

The hosted rubygems.org service is fixed. Gem users who only install gems from rubygems.org have nothing to change. The remaining risk is for organisations that run their own copy of the registry software.

Deployment Affected versions Fixed version
Hosted rubygems.org Before the service fix Fixed server-side, 2026-11-04 validation change
Self-hosted RubyGems.org Commits before 2026-11-04 A commit containing the fix

Check a self-hosted checkout for the vulnerable validator and the old deserialisation call:

grep -Rn '"!ruby/regexp"' lib app
grep -Rn 'safe_to_ruby' lib/gem_validator
git log -1 --format='%H %cs'

A checkout that still lists "!ruby/regexp" in GemValidator::NodeInfo::IGNORED_TAGS, or that has no safe_to_ruby in the validator, predates the fix. A fixed checkout removes the tag from the ignore list and routes gemspec deserialisation through safe_to_ruby.

Gem users can confirm which registry their client uses, though the hosted service needs no action:

gem sources --list

How do I fix it?

The fix is server-side for registry operators and a Ruby upgrade for application owners. Gem users who install from the hosted service take no action.

  1. Gem users: do nothing. The hosted registry rejects regexp-tagged gemspec fields before deserialisation.
  2. Self-hosted registry operators: update to a commit containing the fix and restart the web and worker processes. The validation change entered the public repository on 2026-11-04. There is no fixed release version to name, so pin a commit on or after that date and confirm it carries safe_to_ruby.
  3. Ruby application owners: install Ruby 4.0.10, 3.4.13 or 3.3.14. These releases fix the separate regexp and string case conversion flaws that the maintainers used to turn regexp compilation into code execution.
  4. If you cannot update a self-hosted registry yet, restrict push-capable API keys to accounts you trust and run the upload workers on a Ruby build that has the regexp fixes. That lowers the chance that a compiled pattern becomes code execution, but it does not stop the pattern from reaching the compiler.

The registry fix also caps OIDC access-policy patterns at 255 characters before compilation and turns a RegexpError during token exchange into an access error. Those are defence-in-depth changes, not the main fix.

What is the root cause?

The push validator removed YAML tags before schema validation. It still deserialised the same AST into Ruby objects afterwards, so a tag it ignored could carry a Ruby class into the loader. The validator has a list of tags it treats as plain scalars, and in the affected code that list included !ruby/regexp:

module GemValidator::NodeInfo
  IGNORED_TAGS = Set[
    "!", "!binary", "!str", "tag:yaml.org,2002:null",
    "!timestamp", "!int:Fixnum", "!ruby/regexp"
  ].freeze

  def self.read_tag(node)
    tag = node.tag
    return nil if IGNORED_TAGS.include?(tag)
    TAG_ALIASES[tag] || tag
  end
end

When a gemspec field arrived as summary: !ruby/regexp /.../, read_tag returned nil, so the schema validator saw an untagged scalar and accepted it. The push pipeline then converted the AST with gemspec_ast.to_ruby, which asked Psych to instantiate the tagged object. Psych built a Regexp from the attacker's pattern and compiled it.

The order matters. Validation and deserialisation run before Pusher checks whether the account owns the gem name. An attacker therefore does not need to own a gem, only to hold a key that can push one. The compiled pattern reaches Ruby's regexp engine with the upload worker's privileges.

How is it exploited?

The attack is an authenticated gem push with a crafted gemspec field. It needs an account and a push-capable API key, and it runs before the registry checks ownership.

  1. Create a RubyGems.org account and mint a push-capable API key.
  2. Build a gem whose gemspec carries a string field tagged as a regexp, for example summary: !ruby/regexp /.../.
  3. Send the gem to the registry with POST /api/v1/gems.
  4. The schema validator ignores the !ruby/regexp tag and accepts the field as a plain scalar.
  5. gemspec_ast.to_ruby turns the field into a Regexp and compiles the attacker's pattern in the upload worker, before the ownership check.
  6. On Ruby 4.0.9, a pattern that triggers the regexp compiler memory corruption can execute code as the worker. On other Ruby builds the same input can crash the worker or exhaust its memory.

The advisory reports that the maintainers reproduced the code-execution outcome locally against Ruby 4.0.9. It does not publish a payload, and it does not say whether an attacker who reached code execution could read published gems or signing credentials.

How does the attack flow?

An authenticated gem push carries a regexp-tagged field past schema validation, and the deserialiser compiles it in the upload worker before any ownership check.

flowchart LR A["Push-capable API key"] --> B["POST /api/v1/gems with regexp-tagged field"] B --> C["Validator ignores !ruby/regexp"] C --> D["Schema accepts plain scalar"] D --> E["to_ruby compiles attacker pattern"] E --> F["Worker crash or memory exhaustion"] E --> G["Code execution on Ruby 4.0.9"]

What can an attacker do?

An attacker with a push-capable API key can make the registry compile an arbitrary regular expression in its upload worker. The verified outcome depends on the Ruby build:

  • On Ruby 4.0.9, the maintainers chained the compiled pattern with a memory corruption bug in the regexp compiler and reached code execution with the upload worker's privileges in local testing.
  • On a Ruby build without that memory corruption, the same input can crash an upload worker or exhaust its memory, which disrupts pushes.
  • The advisory does not state whether code execution on the worker would let an attacker read published gems, modify them, or reach publishing credentials.

The conditions are the ones in "Am I affected?". The attacker needs a self-hosted deployment that predates the fix and an account with a push-capable key. The code-execution outcome also needs a Ruby build whose regexp compiler the pattern can corrupt. The hosted service is not exposed to this path.

Why does the fix work?

The fix removes !ruby/regexp from the ignored tags and replaces the unrestricted deserialiser with a loader that only instantiates the classes a valid gemspec uses. The two changes are visible in the fixed validator:

 module GemValidator::NodeInfo
   IGNORED_TAGS = Set[
     "!", "!binary", "!str", "tag:yaml.org,2002:null",
-    "!timestamp", "!int:Fixnum", "!ruby/regexp"
+    "!timestamp", "!int:Fixnum"
   ].freeze
   def spec
-    gemspec_ast.to_ruby.tap do |s|
+    GemValidator::Package.safe_to_ruby(gemspec_ast).tap do |s|
       s.reset_nil_attributes_to_default
       s.flatten_require_paths
     end
   end

The schema validator now sees the !ruby/regexp tag and rejects the field with HTTP 422 and the message expected no tag, but got "!ruby/regexp" path: /summary. The safe_to_ruby loader uses a restricted class loader and refuses YAML aliases, so a tag that slips past the schema cannot instantiate an arbitrary class.

The fix is complete for this path. It does not fix the separate Ruby regexp compiler flaws. That is why the advisory also points application owners at Ruby 4.0.10, 3.4.13 and 3.3.14.

How do I check if I was compromised?

On a self-hosted registry, search the application and reverse-proxy logs for requests that carried the tag. The fixed validator logs a rejection that names it:

grep -R '!ruby/regexp' /var/log /path/to/rubygems/log 2>/dev/null

Look for POST /api/v1/gems requests from accounts that do not own the gem name they pushed. That combination is the precondition the bug removes. Check upload worker restarts, out-of-memory kills and crash reports for the period before the fix:

journalctl -u rubygems --since "2026-10-05" | grep -Ei "regexp|out of memory|killed process"

The advisory reports no indicators of compromise. It also warns that log retention and unlogged upload payloads do not rule out earlier attempts, so an absence of hits is not proof that nobody tried.

Timeline

  • 2026-10-05 to 2026-11-04: The maintainers review 29,100 gems published in this window and find no direct evidence of exploitation.
  • 2026-11-04: The validation change enters the public RubyGems.org repository.
  • 2026-11-18: The Ruby project releases fixes for seven regexp and string flaws in Ruby 4.0.10, 3.4.13 and 3.3.14.
  • 2026-11-26: RubyGems.org publishes advisory GHSA-7h7w-m82c-x2xg.

Timeline from the review window to the advisory
Figure 1: The validation change landed three weeks before the public advisory. Source: GHSA-7h7w-m82c-x2xg and The Hacker News, checked November 30, 2026

FAQ

Do I need to change anything if I only install gems?

No. The hosted rubygems.org service is fixed, and gem users take no action. The advisory's remaining action is for operators who run their own copy of the registry software.

Does this affect the gem client?

No. The flaw is in the RubyGems.org server-side push validator and upload worker, not in the gem command or in installed gems.

Why does the advisory call it remote code execution if the attacker needs an API key?

The attacker needs an account and a push-capable API key, which is an authenticated position. The code execution happens on the registry's upload worker, in a service the attacker reaches over the network. The severity reflects the worker's access, not an unauthenticated entry point.

Is the Ruby regexp flaw the same issue?

No. The Ruby flaws are separate defects in the regexp compiler and string case conversion, fixed on 2026-11-18. The registry bug let an attacker reach that compiler with a chosen pattern. A patched Ruby build removes the code-execution chain but does not fix the registry's deserialisation bug.

Was anyone exploited?

The maintainers found no direct evidence of exploitation in the 29,100 gems published from 2026-10-05 to 2026-11-04. They also say log retention and unlogged upload payloads do not rule out earlier attempts.

Inventory the open-source dependencies you ship with Ostorlab

Ostorlab's software composition analysis inventories the open-source packages and versions your teams build and ship. It shows what a registry compromise would reach. Use it to map the gems and runtimes in your applications before you assess the impact of a push-path flaw.

References

  • RubyGems.org security advisory GHSA-7h7w-m82c-x2xg, "Authenticated remote code execution in RubyGems.org gem pushes via !ruby/regexp gemspec tags" (checked November 30, 2026): https://github.com/rubygems/rubygems.org/security/advisories/GHSA-7h7w-m82c-x2xg
  • RubyGems.org gem validator source, lib/gem_validator/node_info.rb (checked November 30, 2026): https://github.com/rubygems/rubygems.org/blob/master/lib/gem_validator/node_info.rb
  • RubyGems.org gem validator source, lib/gem_validator/package.rb (checked November 30, 2026): https://github.com/rubygems/rubygems.org/blob/master/lib/gem_validator/package.rb
  • Ruby security announcement, "Multiple vulnerabilities in regexp and string" (checked November 30, 2026): https://www.ruby-lang.org/en/news/2026/11/18/multiple-vulnerabilities-in-regexp-and-string/
  • RubyGems statistics page (checked November 30, 2026): https://rubygems.org/stats
  • The Hacker News, "Critical RubyGems Flaw Could Have Let Any Gem Publisher Run Code on the Registry" (checked November 30, 2026): https://thehackernews.com/2026/11/critical-rubygems-flaw-could-have-let.html

Free scan

Scan your own app for free

or book a demo

Keep reading

Related articles

Browse the blog