← All articles

RubyGems Vulnerability Put Gem Upload Workers at Risk

RubyGems Vulnerability Put Gem Upload Workers at Risk

The RubyGems vulnerability allowed an attacker-controlled regular expression to enter gem metadata and reach the RubyGems.org upload process. Registry maintainers chained the flaw with a memory corruption bug in Ruby’s regular expression compiler and achieved remote code execution in local testing. RubyGems.org has fixed the registry issue, and gem users do not need to take action.

The flaw is tracked as GHSA-7h7w-m82c-x2xg and has a CVSS score of 9.0, a rating that indicates a critical security risk. No CVE has been assigned. The problem was in the way the registry read metadata attached to an uploaded gem as YAML, a data format often used to store structured settings.

RubyGems.org’s metadata validator did not properly handle the !ruby/regexp YAML tag. As a result, a field containing that tag passed the schema checks as ordinary text. Ruby’s Psych YAML library then converted the field into a real regular expression and compiled the pattern supplied by the attacker. A regular expression is a pattern used to search or match text, but compiling a malicious pattern can trigger deeper flaws in the runtime handling it.

This processing happened before RubyGems.org checked whether the account owned the gem name. An attacker therefore did not need to control an existing gem. The required access was a push-capable API key, which is an access credential that permits uploads to the registry.

The maintainers tested the attack chain on Ruby 4.0.9. That version was affected by seven flaws in Ruby’s regular expression engine and string case conversion, which means the code responsible for matching patterns and changing letter case. The Ruby project patched those runtime flaws on November 18. Its security announcement lists Ruby 4.0.10, 3.4.13 and 3.3.14 as fixed versions. The registry advisory does not identify which of the seven memory corruption bugs was used in the test.

Remote code execution means that input supplied through a service can make the service run commands chosen by an attacker. In this case, the test code ran with the privileges of the gem-upload worker in a local environment. The advisory does not establish whether an attacker reaching that stage could access published gems or publishing credentials. Even when the underlying Ruby build cannot be pushed to code execution, compiling an attacker’s pattern can still crash an upload worker or consume enough memory to exhaust it.

RubyGems.org reviewed production telemetry and 29,100 gems published between October 5 and November 4. The registry advisory reported no direct evidence of exploitation. However, the available records were incomplete: logs were not retained long enough, and upload payloads were not recorded. Earlier attempts therefore cannot be ruled out.

The hosted registry now rejects gemspec fields carrying regexp tags during schema validation and returns an HTTP 422 error. A gemspec is the metadata file describing a gem. RubyGems.org also reads gem metadata with a restricted loader that refuses YAML aliases and permits only the small set of classes used by a valid gemspec. As an additional safeguard, patterns in OpenID Connect, or OIDC, access policies are limited to 255 characters before compilation. OIDC is a method for exchanging identity information between services.

The validation change was added to the registry’s public code repository on November 4 UTC, three weeks before disclosure, according to its commit history. Operators running their own RubyGems.org installation should update to a commit containing the fix. Ruby application owners have a separate task because the registry fix does not replace the Ruby runtime updates: applications using affected Ruby releases should move to Ruby 4.0.10, 3.4.13 or 3.3.14.

RubyGems.org hosts about 199,000 gems and its statistics page records more than 278 billion downloads, making the integrity of its upload pipeline important to the wider Ruby ecosystem. Gem users of the hosted registry do not need to change anything, but teams operating Ruby applications or a self-hosted registry should verify which component they run and apply the relevant update.

For organisations managing related infrastructure, AEU-I provides security-first IT, infrastructure and consulting, which can help teams address the operational side of maintaining self-hosted systems.

Practical protection starts with identifying whether your organisation runs its own RubyGems.org installation, rather than assuming the hosted service and self-hosted software are maintained in the same way.

Also available in: DeutschItalianoShqip