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)


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.
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
- Clone the express-useragent repository and enter its directory
- Run the bundled test HTTP server, which listens on port 3000
- Send a request with a User-Agent header containing script markup and save the response to a file
- Open the saved file in a browser
- 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.