[min-http-server] Stored XSS in the filename when directories listing
The min-http-server module lists directory contents in HTML without sanitising filenames, so a file with a crafted name containing HTML attributes can inject script. An attacker who can create such a file on the server can cause JavaScript to run in the browser of anyone who views the directory listing.
Originally disclosed on HackerOne
- Disclosed after 3 months
I would like to report Stored XSS in module "min-http-server".
It allows to inject malicious scripts in the file name, store them on the server, then execute these scripts in the browser via the XSS vulnerability.
# Module
**module name:** min-http-server
**version:** 1.0.6
**npm page:** `https://www.npmjs.com/package/min-http-server`
## Module Description
一个零�
�置、轻量级的 http 静态资源服务器 means
A zero-configuration, lightweight http static resource server
## Module Stats
[0] downloads in the last day
[4] downloads in the last week
[35] downloads in the last month
# Vulnerability
## Vulnerability Description
This XSS vulnerability occurs due to the module represents filename(s) in HTML without any sanitization in listing directory page. In a result, any malicious scripts which are injected and stored on the server, would be executed in the client's browser.
## Steps To Reproduce:
- Install the module
```
npm install -g min-http-server
```
- In the directory which will be served via min-http-server, create file with following names in directories ~/Desktop/:
```
" onmouseover=alert(1) "
```
{{media:0}}
- Run 'min-http-server in "~/Desktop" directory :
```
min-http-server
[tiny-http-server] static-server is starting at port 1138
[tiny-http-server] please enter localhost:1138 in the browser
```
- Open http://localhost:1138/
{{media:1}}
- When mouseover event is trigger, a message will be popup via XSS vulnerability.
{{media:2}}
## Patch
User input should be properly sanitized and filtered both at the client and server side. Dangerous characters such as < > ' " % ; ) ( & + should either be disallowed or HTML encoded before displaying them on screen.
## Supporting Material/References:
- Linux kali 4.15.0-kali2-amd64
- node 10.15.3
- npm 6.9
- Firefox ESR 60.5.1esr (64-bit)
# Wrap up
- I contacted the maintainer to let them know: N
- I opened an issue in the related repository: N
## Impact
It allows to inject malicious scripts in the file name, store them on the server, then execute these scripts in the browser via the XSS vulnerability.
## Attachments
{{media:3}}
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 directory listing page inserts filenames into HTML without escaping or sanitising them.
Impact
An attacker who can place a file with a crafted name on the server could execute script in the browser of anyone who views the directory listing.
What the attacker needed
Ability to create a file on the server; victim views the directory listing
The fix
Filenames should be HTML-encoded or dangerous characters disallowed before being displayed in the directory listing.
How it was found
- Install the min-http-server module globally.
- In the directory to be served, create a file whose name contains HTML attribute syntax.
- Start min-http-server in that directory.
- Open the server's address in a browser to view the directory listing.
- Trigger the mouseover event on the filename to see the script execute.
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 static file server shows a list of files in a folder as a web page. This server put the file's name directly into the page's HTML without cleaning it first. If a file is named with special characters that look like HTML code, the browser treats that name as part of the page and runs any script hidden in it. So someone who can put a file on the server can make visitors' browsers run their code.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.