Skip to content
Path traversal Disclosed report Beginner CVE-2018-16475

[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.

abdilahrf_ Follow

Originally disclosed on HackerOne

High 8.6 View original
  • 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 knightjs
  • node node_modules/knightjs/bin/knight
  • curl --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

knightjs-path-traversal.PNG
knightjs-path-traversal.PNG From the original on HackerOne

The original report as published on HackerOne, by abdilahrf_. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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

  1. Install the knightjs package.
  2. Run the knight server.
  3. 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.

More by abdilahrf_

View all

5 more disclosed reports, best first.

More from Node.js third-party modules

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Path traversal and file inclusion

The lesson behind this report.

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.