Login / Register
  • Home
  • Security
  • Critical RubyGems Vulnerability Could Have Enabled...
Security Critical RubyGems Vulnerability Could Have Enabled Remote Code Execution by Any Gem Publisher

Critical RubyGems Vulnerability Could Have Enabled Remote Code Execution by Any Gem Publisher

B bigmicko 3 days ago 4 views 0

RubyGems.org, the official package registry for Ruby developers, has patched a critical security vulnerability that could have allowed anyone holding a push-enabled API key to inject a malicious regular expression into gem metadata and potentially execute arbitrary code on the registry server.

According to a security advisory published last week, maintainers successfully demonstrated how the vulnerability could be combined with a memory corruption flaw in Ruby’s regular expression compiler to achieve remote code execution (RCE). The issue does not require action from users who install gems.

An analysis of production logs and 29,100 gems published between October 5 and November 4 revealed no direct evidence of exploitation, the advisory said. However, investigators acknowledged that the assessment was incomplete because logs were not retained long enough and upload payloads were not captured, leaving the possibility of earlier exploitation unresolved.

Tracked as GHSA-7h7w-m82c-x2xg, the vulnerability carries a CVSS score of 9.0 and has not been assigned a CVE identifier. The security issue stemmed from the registry’s handling of YAML-formatted metadata included in gem uploads.

The metadata validation process failed to properly account for the !ruby/regexp YAML tag, allowing tagged fields to bypass schema validation as ordinary text. Ruby’s YAML parser, Psych, subsequently interpreted the content as an actual regular expression and compiled the attacker-supplied pattern.

Because this processing occurred before the registry verified whether the uploading account had ownership rights over the gem name, an attacker with a push-capable API key could potentially exploit the flaw without owning or maintaining a gem.

The proof-of-concept was tested on Ruby 4.0.9, which was affected by a series of seven vulnerabilities involving the regular expression engine and string case-conversion functionality. The Ruby project addressed those flaws in security updates released on November 18. The RubyGems advisory does not identify which specific memory corruption vulnerability was used in the demonstration.

Even on Ruby versions that are not susceptible to remote code execution through the demonstrated chain, malicious regular expressions could still cause upload workers to crash or consume excessive memory, potentially disrupting registry operations.

To address the issue, RubyGems.org now rejects gemspec metadata containing regexp YAML tags during schema validation, returning an HTTP 422 response. The registry has also introduced a restricted YAML loader that blocks aliases and permits only approved classes required for valid gemspec processing. Additionally, regular expressions used in OIDC access policies are limited to 255 characters before compilation as another defensive measure.

The security fix was committed to the registry’s public repository on November 4 (UTC), approximately three weeks before the vulnerability was publicly disclosed, according to the commit history.

What users and administrators should do

  • Gem users: No action is required. RubyGems.org has deployed the fix.

  • Self-hosted RubyGems.org operators: Update to a revision that includes the security patch.

  • Ruby application developers: Upgrade to patched Ruby releases, including Ruby 4.0.10, 3.4.13, or 3.3.14, as outlined in the Ruby project's security announcement.

RubyGems.org currently hosts approximately 199,000 gems and has recorded more than 278 billion downloads, highlighting the potential significance of security issues affecting the ecosystem’s central package distribution platform.

The demonstrated code execution occurred in a local test environment and inherited the privileges of the gem-upload worker. The advisory does not clarify whether an attacker exploiting the vulnerability could have accessed published packages, sensitive registry data, or publishing credentials.

0 Comments

Comments (0)

Join the conversation

Sign in to comment

Join the conversation — it only takes a moment.

No comments yet. Be the first to comment.

B

Related Posts

More from Security

No related posts

There is nothing else in this category yet.