Skip to content
XSS Disclosed report Beginner

[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.

ysx Follow

Originally disclosed on HackerOne

  • 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

  1. Please install the newly created Gem ("securitytest-0.1.0.gem") on your system.
  2. Next, execute gem server to launch the built-in hosting interface.
  3. Access the RubyGems Documentation Index via the applicable port.
  4. Finally, locate the securitytest gem and select the [www] link to execute the JavaScript payload.

Supporting evidence

Gem_Server_XSS.png
Gem_Server_XSS.png From the original on HackerOne

Please let me know if you require any additional information regarding this issue.

Thanks

Yasin

The original report as published on HackerOne, by ysx. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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

  1. Build a gem from a Gemspec whose homepage is a javascript: URL.
  2. Install the crafted gem on the system.
  3. Run gem server to start the built-in hosting interface.
  4. Open the RubyGems Documentation Index on the relevant port.
  5. 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.

More by ysx

View all

25 more disclosed reports, best first.

More from RubyGems

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.