Critical RubyGems Flaw Could Have Let Any Gem Publisher Run Code on the Registry
About 3 min read
securitysoftwarepayments
RubyGems.org, the primary repository for Ruby libraries, has patched a critical vulnerability that could have allowed any user with a push‑capable API key to execute code on the registry’s servers. The flaw let an attacker embed a malicious regular expression in a gem’s metadata, which the registry then compiled and ran without proper validation. The issue was disclosed in a security advisory last week and has now been mitigated.
The vulnerability stemmed from how RubyGems.org parsed gemspec metadata written in YAML. The validator that checks incoming metadata ignored the YAML tag !ruby/regexp, treating the field as ordinary text. When the Ruby YAML library Psych processed the data, it automatically converted the tag into a real regular expression object. The registry then compiled the supplied pattern before confirming that the uploading account owned the gem name. Because the check occurred after compilation, an attacker needed only a valid push‑capable API key, not ownership of a gem, to trigger the flaw.
In a controlled test, the RubyGems.org maintainers combined the metadata issue with a known memory‑corruption bug in Ruby’s regular‑expression engine. Running the test on Ruby 4.0.9, which contains seven related flaws in the regexp engine and string case conversion, they achieved remote code execution. The advisory does not specify which exact memory‑corruption bug was used, but the combination proved that an attacker could run arbitrary code with the privileges of the gem‑upload worker. Even on Ruby builds that are not vulnerable to code execution, compiling a malicious pattern could still crash the upload worker or exhaust its memory, causing denial‑of‑service conditions.
The security team examined production telemetry and reviewed 29,100 gems uploaded between 5 October and 4 November. Their analysis found no direct evidence that the flaw had been exploited in the wild. However, the review was limited because logs were not retained long enough and upload payloads were not recorded, meaning earlier attempts cannot be definitively ruled out. The advisory therefore cannot guarantee that the vulnerability was never abused before the fix.
The fix was introduced to the public RubyGems.org code repository on 4 November UTC, three weeks before the public disclosure. The updated validator now rejects any gemspec field that contains a regexp tag, returning an HTTP 422 error. Additionally, the registry now reads gem metadata with a restricted YAML loader that disallows aliases and permits only the classes required for a valid gemspec. As an extra safeguard, patterns used in OIDC access policies are limited to 255 characters before compilation, reducing the risk of memory‑intensive regular expressions.
The vulnerability is tracked as GHSA‑7h7w‑m82c‑x2xg and carries a CVSS score of 9.0, reflecting its high severity. No CVE identifier has been assigned. The flaw existed in the way the registry read YAML metadata, not in the RubyGems client software itself. Because the exploit required a push‑capable API key, the risk was primarily to accounts that had such keys, whether legitimate or compromised.
RubyGems.org hosts roughly 199,000 gems and reports more than 278 billion downloads, according to its statistics page. The potential impact of a successful exploit could have been significant, given the scale of the ecosystem. In the maintainers’ test, the code execution occurred with the privileges of the gem‑upload worker in a local environment. The advisory does not clarify whether an attacker who achieved this level of access could have subsequently altered published gems or obtained additional publishing credentials.
For users of RubyGems.org, no immediate action is required. The registry’s patch operates on the server side, and normal gem consumers do not need to update anything locally. Developers should continue to protect their API keys, especially those that allow gem pushes, and monitor any unusual activity on their accounts. The incident underscores the importance of rigorous input validation and the risks associated with complex data formats like YAML in security‑critical services.
A new technique called Weight2Shell has been disclosed by cybersecurity researchers, which allows artificial intelligence (AI) models to produce different behavior on different machines, eve…
Season 2: Legacy for Gears of War: E‑Day launches tomorrow, marking the franchise’s twentieth anniversary and offering a wave of new content for both veteran players and newcomers. The updat…
Hela: of Mice & Magic is set to launch on December 1, 2026 for Xbox Series X|S, and the title will be available on day one through Xbox Game Pass. The game presents an open‑world adventure i…