Memory leak in gem decode logic can allow attacker to take down Rubygems.org application
The gem metadata decoding logic allowed arbitrary instance variables to be set, and because Ruby does not garbage collect symbols created this way, an attacker could exhaust server memory by sending many unique key-value pairs. An attacker with a valid API key could take down the Rubygems.org application.
Originally disclosed on HackerOne
- Fixed in 11 months
- Disclosed after 12 months
Summary by the program
The reporter discovered that pushing a gem via POST /api/v1/gems causes gem metadata to be decoded through Gem::Specification, which allows arbitrary instance variables to be set via instance_variable_set. Because Ruby doesn't garbage collect symbols created this way, an attacker with a valid API key could exhaust server memory by sending requests with a large number of unique key-value pairs in the gem metadata.
We've addressed this by restricting which instance variables can be set during metadata decoding. The fix is in this commit. Severity is Medium (6.5) given that exploitation requires a valid API key and the impact is confined to rubygems.org. Thanks to @mclaren650sspider for the clear, well-documented report including a working exploit script.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the metadata decoder used instance_variable_set on user-controlled keys without restricting which variables could be set, and Ruby never frees the symbols created for those variable names.
Impact
An attacker with a valid API key could exhaust server memory and take down the Rubygems.org application; the impact is confined to that site.
What the attacker needed
A valid API key
The fix
The issue was fixed by restricting which instance variables can be set during metadata decoding.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When you upload a gem, the server reads its metadata and creates internal variables from the keys. The bug let an attacker create unlimited new variable names, and Ruby keeps every name forever, so memory fills up. With a valid API key, someone could crash the site by sending many such requests.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.