Any Publisher Could Run Code. RubyGems Trusted the Pattern.

Any Publisher Could Run Code. RubyGems Trusted the Pattern.

RubyGems.org is the front door to the Ruby world. Every gem a Ruby developer installs — every library, every framework, every tiny helper — passes through it. This week its maintainers disclosed a flaw that could have let any publisher run code on the registry itself. Not on a gem. On the registry.

The flaw is tracked as GHSA-7h7w-m82c-x2xg and scores 9.0 on the CVSS scale. No CVE was assigned. The registry has fixed it, and gem users need do nothing. But the mechanism is worth understanding, because it is a reminder of how much trust a package registry places in the metadata it reads — and how thin the line is between reading data and running it.

A pattern hidden in the metadata

Every gem upload carries metadata: the gemspec, a small description of the package written in YAML. Before a gem is accepted, the registry validates that metadata against a schema. The problem was what the validator chose not to see.

The schema check ignored the !ruby/regexp YAML tag. A gemspec field carrying that tag sailed through validation looking like plain text. But Ruby’s YAML library, Psych, reads the tag literally: it turned the field into a real regular expression and compiled whatever pattern the attacker supplied. The attacker did not need a clever parser bypass or a stolen credential. Any account with a push-capable API key could embed an attacker-controlled regular expression in an upload’s metadata, and the registry would compile it.

Before the ownership check

The ordering made it worse. All of this ran before the registry checked whether the uploading account actually owned the gem name. An attacker needed no gem of their own — no package to publish, no reputation to build. A push-capable API key was enough to get the registry to compile a pattern of their choosing.

In local testing, the maintainers chained the flaw with a memory-corruption bug in Ruby’s regular-expression compiler and reached remote code execution. The test ran on Ruby 4.0.9, a version affected by seven flaws in the regexp engine and string case conversion that the Ruby project patched on November 18. The advisory does not say which of those bugs the chain used.

The code execution came with the privileges of the gem-upload worker, in a local test environment. The advisory does not say whether an attacker who got that far could have reached published gems or publishing credentials. That is an open question, not a reassurance.

Four gaps lined up into one break-in: the ignored YAML tag, Psych compiling the pattern, no ownership check yet, and a regexp memory bug — leading to remote code execution.
Four gaps lined up into one break-in. The validator ignored the tag, Psych compiled the pattern, and the ownership check came too late.

Even without code execution, it still hurts

The flaw did not need the chain to cause damage. On any Ruby build, compiling an attacker’s pattern can crash an upload worker or exhaust its memory — a denial of service against the upload pipeline is a real outcome on its own.

The registry hosts about 199,000 gems and has counted more than 278 billion downloads. That scale is why a flaw in the upload path matters more than a flaw in any single gem: the registry is the one place every Ruby project trusts, and its upload workers sit upstream of all of it.

No direct evidence — with a caveat

The maintainers reviewed production telemetry and the 29,100 gems published between October 5 and November 4. They found no direct evidence of exploitation. But the advisory is careful about what that does not prove: logs were not kept long enough, and upload payloads were not recorded, so earlier attempts cannot be ruled out. Absence of evidence here is a limit of the evidence, not a clean bill of health.

Package registries keep learning this lesson. Hex.pm showed the same shape of risk days earlier, when a flaw in the Elixir registry’s upload path let an attacker compromise six servers in minutes.

What changed

The fixes are layered, and each one closes a different door. Schema validation now rejects regexp-tagged gemspec fields outright, with an HTTP 422 error. Gem metadata is read with a restricted loader that refuses YAML aliases and allows only the handful of classes a valid gemspec actually uses. And 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 — three weeks before the disclosure.

What changed and what you do now: regexp-tagged gemspec fields are rejected with HTTP 422, a restricted YAML loader refuses aliases, OIDC patterns are capped at 255 characters; gem users do nothing, self-hosters update, Ruby apps upgrade to 4.0.10, 3.4.13 or 3.3.14.
What changed — and what you do now. The registry rejects the pattern outright; self-hosters and Ruby apps still have updates to make.

What to do

If you use gems, nothing. The hosted registry is fixed, and there is no action for gem users.

If you self-host the RubyGems.org software, update. Move to a commit containing the fix — the hosted service is patched, but your own deployment is not until you update it.

If you run Ruby applications, upgrade Ruby. The seven runtime flaws in the regexp engine and string handling are fixed in Ruby 4.0.10, 3.4.13, and 3.3.14. Close both — the maintainers’ proof of concept chained them together.

If you operate a registry or an upload pipeline of any kind, audit what your validators ignore. This flaw lived in a gap between two components: a schema check that treated a tagged field as text, and a YAML loader that treated it as code. The pattern was not smuggled past the defenses. It walked through the front door, in a field the validator had decided not to look at.

Comments

This site uses Akismet to reduce spam. Learn how your comment data is processed.