[m-server] XSS reflected because path does not escapeHtml
The m-server static file server builds its directory listing HTML without escaping the request path, so a crafted URL containing HTML markup is reflected into the page. An attacker could get script to run in a victim's browser in the server's origin.
- Fixed in 52 days
- Disclosed after 54 days
I would like to report XSS in m-server It allows attacker can perform XSS in client side
Module
module name: m-server
version: 1.4.2
npm page: https://www.npmjs.com/package/m-server
Module Description
M-Server is a mini http static server that without any dependencies;
Module Stats
[1] weekly downloads 150
Vulnerability
XSS reflected because path does not escapeHtml
Vulnerability Description
in m-server/lib/utils.js line 59 and 64, html push does not escapeHtml for variable path.

By change path of URL via traversal, attacker can control this variable path.

Steps To Reproduce:
On server, run this: $ cd /home/vagrant/tmp/test $ m-server On client, issue requests:
GET /../../../../home/vagrant/tmp/test/<svg/onload=alert(document.domain)>/../../../test/ HTTP/1.1
Host: 192.168.57.105:3001
User-Agent: curl/7.54.0
Accept: */*
Connection: close
POC:
Patch
line 59 should use
html.push('<li><a href="' + escapeHtml(path) + '/' + escapeHtml(val) + '">' + escapeHtml(val) + '</a></li>');
line 64 should use
html.push('<li><a download href="' + escapeHtml(path) + '/' + escapeHtml(val) + '">' + escapeHtml(val) + '</a></li>');
Or strip path traversal
Supporting Material/References:
State all technical information about the stack where the vulnerability was found
- [OPERATING SYSTEM VERSION]
- [NODEJS VERSION]
- [NPM VERSION]
- [BROWSERS VERSIONS, IF APPLICABLE]
- [OTHER SOFTWARE USED TO EXPLOIT VULNERABILITY AND THEIR VERSIONS, IF APPLICABLE]
Wrap up
Select Y or N for the following statements:
- I contacted the maintainer to let them know: [Y/N] N
- I opened an issue in the related repository: [Y/N] N
Hunter's comments and funny memes goes here
Impact
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 directory listing code concatenates the request path into HTML without escaping it, and the path can be manipulated through traversal sequences.
Impact
An attacker could run script in the context of the m-server origin, though the report gives no further detail on what that script could reach.
What the attacker needed
Victim opens a crafted link; server reachable by the victim
The fix
The listing should HTML-escape the path and file names before inserting them, and path traversal should be stripped; the report proposes this patch but does not say it was applied.
How it was found
- Start the m-server static server in a test directory.
- Send a request whose path contains traversal segments and an SVG element with an onload handler.
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 small web server that lists files in a folder builds that listing page by pasting the requested URL path straight into the HTML. If the path contains HTML tags, the browser treats them as real page content, so an attacker can make a link that runs their own script when someone opens it. This is called reflected cross-site scripting, because the malicious input is echoed back in the response.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.