Skip to content
XSS Disclosed report Beginner CVE-2018-9863

XSS in express-useragent through HTTP User-Agent

The express-useragent middleware parses the User-Agent header and returns it without escaping or sanitisation, so a crafted header containing script markup is reflected into the output. An attacker could get script to run in a victim's browser, leading to cross-site scripting.

b9b86c2fc8409c628fb3de6 Follow

Originally disclosed on HackerOne

  • Triaged in 10 days
  • Disclosed after 30 days

Hello,

I would like to report an XSS in express-useragent module due a lack of validating User-Agent header. Please note I already created an Github issue and asked for CVE ( CVE-2018-9863). I did not know about Node.js third-party modules on hackerone.

Description

express-useragent is simple NodeJS/ExpressJS middleware exposing User-Agent details to your application and views. Basically it parses User-Agent and return it in structured JSON format.

The issue

while parsing User-Agent there are no escaping or sanitization mechanism. User-Agent header is controlled by the user. An attacker can craft a malicious script and inject it through the HTTP header.

Steps to reproduce

  • git clone https://github.com/biggora/express-useragent
  • cd express-useragent
  • node test/http.js (an HTTP server should listen on 3000 tcp)
  • curl "http://localhost:3000" -H 'User-Agent: <script>alert("XSS")</script>' > poc.html
  • open poc.html with your favorite web browser
  • you should see an alertbox popup

Proof of concept (screenshots)

Screenshot_from_2018-04-09_18-50-35_(1).png
Screenshot_from_2018-04-09_18-50-35_(1).png From the original on HackerOne
Screenshot_from_2018-04-09_18-51-21_(1).png
Screenshot_from_2018-04-09_18-51-21_(1).png

Proof of concept with a fix (video)

Mitigation

Correctly escape and sanitize user input ( HTTP User-Agent ). Please note I proposed a fix in the video

Impact

An attacker could execute javascript code that could lead to XSS.

The original report as published on HackerOne, by b9b86c2fc8409c628fb3de6. 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

The library reflects the user-controlled User-Agent header into output without escaping or sanitising it.

Impact

An attacker could execute JavaScript in a victim's browser, which could lead to cross-site scripting.

What the attacker needed

Victim visits a page rendering the parsed agent; attacker controls the User-Agent header

The fix

The library should correctly escape and sanitise the user-controlled User-Agent input before returning it.

How it was found

  1. Clone the express-useragent repository and enter its directory
  2. Run the bundled test HTTP server, which listens on port 3000
  3. Send a request with a User-Agent header containing script markup and save the response to a file
  4. Open the saved file in a browser
  5. Observe the alert box appear

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 website can read the User-Agent string your browser sends and show it back on a page. This library passed that text through without cleaning it, so if the text contained a script tag, the browser would run it as code. That lets an attacker run their own JavaScript in someone else's browser session.

What is XSS?

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

More from Node.js third-party modules

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.