[tianma-static] Security issue with XSS.
The tianma-static module serves uploaded files with a content type derived from the file extension, so an uploaded HTML file is returned as text/html and its scripts execute. It also reflects a manipulated pathname into the response without proper encoding, allowing HTML injection and reflected XSS.
- Disclosed after 16 months
I would like to report XSS in tianma-static It allows XSS and HTML Injection
First of all, It is my first report and I am sorry that I am not good at English T.T thank you.
Module
module name: tianma-static
version: 1.0.4
npm page: https://www.npmjs.com/package/tianma-static
Module Description
Provide a static file service.
Vulnerability
Vulnerability Description
- File content type
when I look a CVE-2018-16474(CVE-2018-16474, #403692), I think that's vulnerability need arbitrary file(name) upload.
If upload is possible, Attacker can upload html file. Also content type of the response header becomes text/html and it is possible to Stored XSS.

- HTML Injection (It can lead to reflected XSS)
when a send %2f in path (example: http://127.0.0.1:8080/%2f), resolve function make a normal path on the filesystem. but req.pathname will print out a manipulated path.
so I can insert any html.

Reflected XSS using HTML only is not easy bypass the modern browser. but if I can upload any file, Reflected XSS is possible Using load script.

Steps To Reproduce:
- File content type
- upload html file with XSS script.
- xss fired
- HTML Injection (reflected XSS)
- upload any file with XSS script.
- access
/%2f<script src='/[filename]'></script>- xss fired
Patch
- add content type header in response.
- change
decodeURItodecodeURIComponent. or denied malicious path.
Wrap up
- I contacted the maintainer to let them know: N
- I opened an issue in the related repository: N
Impact
If file upload is possible, XSS can occur.
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 server sets the response content type from the uploaded file's extension and reflects the decoded request path into the response without encoding.
Impact
If file upload is possible, an attacker could achieve stored or reflected cross-site scripting, though reflected XSS using only HTML is noted as not easy to bypass in modern browsers.
What the attacker needed
Ability to upload files; victim visits a crafted URL
The fix
The report suggests adding a content type header and changing decodeURI to decodeURIComponent or denying malicious paths, but does not state that a fix was applied.
How it was found
- Upload an HTML file containing a script.
- Access the uploaded file so the browser executes the script.
- Upload any file containing a script.
- Request a path containing an encoded slash followed by a script tag that loads the uploaded file.
- The script executes in the browser.
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.
This is a small web server that serves static files. If someone can upload an HTML file, the server tells the browser to treat it as a web page, so any script inside runs. Also, when a strange path is requested, the server puts that path into the page without cleaning it, letting an attacker insert HTML.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.