[knightjs] Path Traversal allows to read content of arbitrary files
The Knightjs static file server does not sanitise the requested path before reading a file, so an attacker can use directory traversal to read any file on the server. The report demonstrates reading the system password file.
Originally disclosed on HackerOne
- Triaged in 10 days
- Fixed in 2 months
- Disclosed after 2 months
I would like to report Path Travelsal in Knightjs It allows attacker to read content of arbitary file on remote server.
Module
module name: Knightjs
version: 0.0.1
npm page: https://www.npmjs.com/package/knightjs
Module Description
knight is a simple static server without configuration on the top of Node.js.
Module Stats
~ 10-20 / month
Vulnerability
Vulnerability Description
There is no sanitation to the path provided from requests
fs.readFile(pathname, (err, data) => {
if (err) {
res.statusCode = 500
res.end(`Error getting the file: ${err}.`)
} else {
res.statusCode = 200
// based on the URL path, extract the file extention. e.g. .js, .doc, ...
const ext = path.parse(pathname).ext
// if the file is found, set Content-type and send data
res.setHeader('Content-type', mime[ext] || 'text/plain')
res.end(data)
}
})
and if the file exist they will print the data
Steps To Reproduce:
npm i knightjsnode node_modules/knightjs/bin/knightcurl --path-as-is http://localhost:4000/../../../../../../etc/passwd -v
F340872
Wrap up
- I contacted the maintainer to let them know: N]
- I opened an issue in the related repository: N
Impact
It allows attacker to read content of arbitary file on remote server.
Attachments

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
Impact
An attacker could read the contents of arbitrary files on the remote server.
What the attacker needed
Knightjs server is running and reachable
How it was found
- Install the knightjs package.
- Run the knight server.
- Send a request with a path that climbs out of the web root to a system file.
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 hands out files from a folder. If it takes the path from the web request and uses it directly to open a file, someone can ask for a path that climbs out of the folder, like asking for a file many levels up. That lets them read files they should not see, such as system files.
What is Path traversal?
Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.