[gem server] Stored XSS via crafted JavaScript URL inclusion in Gemspec
The homepage field of a Gemspec is rendered as a link in the built-in gem server web interface without validating the URL scheme, so a gem author can supply a javascript: URL. When a user clicks the [www] link for that gem, the attacker's script runs in the gem server's origin.
- Triaged in 3 months
- Fixed in 3 months
- Disclosed after 3 months
Summary by the researcher
A JavaScript URL injection in the homepage field of a Gemspec file can lead to stored XSS within the gem server web UI. A similar issue was identified in the Gem in a Box and Gemirro gems.
The report
Hi,
A JavaScript URL injection in the homepage field within a Gemspec file can be leveraged to achieve stored XSS on the default gem server web interface, referenced here.
When you install RubyGems, it adds the gem server command to your system. This is the fastest way to start hosting gems.
As such, a carefully crafted Ruby gem can be installed to exploit this vulnerability against the gem server.
Prerequisite steps
First, please create a new Gemspec file (e.g. "securitytest.gemspec") with the following contents:
Gem::Specification.new do |s|
s.name = 'securitytest'
s.version = '0.1.0'
s.date = '2017-11-10'
s.summary = "This is a proof-of-concept gem"
s.description = "Select the WWW hyperlink."
s.authors = ["Author Name"]
s.homepage = 'javascript:confirm(document.domain)'
end
After saving this Gemspec file, please execute gem build securitytest.gemspec and locate the resultant Gem file ahead of the following steps.
Steps to reproduce
- Please install the newly created Gem ("securitytest-0.1.0.gem") on your system.
- Next, execute
gem serverto launch the built-in hosting interface. - Access the RubyGems Documentation Index via the applicable port.
- Finally, locate the
securitytestgem and select the[www]link to execute the JavaScript payload.
Supporting evidence

Please let me know if you require any additional information regarding this issue.
Thanks
Yasin
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 gem server renders the Gemspec homepage value directly into an anchor href without restricting the URL scheme, allowing javascript: URLs.
Impact
A user viewing the gem server index who clicks the crafted link could have attacker-supplied script run in the gem server's origin, though the exploit requires the victim to click the link.
What the attacker needed
Ability to install a crafted gem; gem server running; victim clicks the [www] link
How it was found
- Build a gem from a Gemspec whose homepage is a javascript: URL.
- Install the crafted gem on the system.
- Run gem server to start the built-in hosting interface.
- Open the RubyGems Documentation Index on the relevant port.
- Find the gem and click its [www] link to run the script.
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.
A gem is a Ruby package, and its metadata file (the Gemspec) includes a homepage link. The gem server turns that link into a clickable [www] link without checking that it points to a normal web address, so it can be made to run code instead. Anyone who clicks the link runs the gem author's script in their browser on the gem server's page.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.