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

[serve] Directory index of arbitrary folder available due to lack of sanitization of %2e and %2f characters in url

The serve module fails to sanitise encoded dot and slash characters in URLs, allowing directory traversal. An attacker can list the contents of any directory on the server, though not read files.

bl4de Follow

Originally disclosed on HackerOne

Critical 9.3 View original
  • Triaged in 19 hours
  • Fixed in 48 hours
  • Disclosed after 2 days

Hi,

This report is about Arbitrary Directory Listing vulnerability I found in serve module. Vulnerability does not allow to open arbitrary file due to send module which handles file reading and implements its own validation and protection against Path Traversal attacks.

However serve handles directory listing on its own and does not protect against listing of any directory on the remote server.

Module:

Serve is a module which allows to server static files and browse directories in the browser. The vulnerability exists in the latest available version (6.4.8)

Link to npm page: https://www.npmjs.com/package/serve

Summary:

Serve does not handle %2e (.) and %2f (/) and allows to use them in paths, which can be used do go up through directory tree and lists content of any directory.

Steps To Reproduce:

  • install serve

$ npm install serve

  • create simple application which uses http-pages for serving static files from local server:
JavaScript
const serve = require('serve')

const server = serve(__dirname, {
    port: 4444,
    ignore: []
})
  • run application:
$ node app.js
  • open the browser and go to http://localhost:4444 You should see all directories and files in the directory, where app.js was run:
1.png
1.png From the original on HackerOne
  • now, open the following url: http://localhost:4444/..%2f/..%2f/..%2f/..%2f/etc/ (please adjust the number of ..%2f/ to reflect your system). You'll be able to see the content of /etc directory:
2.png
2.png From the original on HackerOne

Supporting Material/References:

Configuration I've used to find this vulnerability:

  • macOS HighSierra 10.13.2
  • node 8.9.3
  • npm 5.5.1
  • curl 7.54.0

Wrap up

I hope this report will help to keep Node ecosystem more safe. If you have any questions about any details of this finding, please let me know in comment.

Thank you

Regards,

Rafal 'bl4de' Janicki

Impact

This vulnerability allows malisious user to list content of any directory on the remote machine, where serve runs. Although it's not enough to open and read arbitrary files, this still might expose some sensitive information which can be used in different attacks.

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

Likely the serve module does not decode and normalise URL-encoded path traversal sequences before using them to resolve directory paths for listing.

Impact

An attacker could list the contents of any directory on the server, potentially exposing sensitive information for use in further attacks, but cannot read files.

What the attacker needed

Serve module running; network access to the server

How it was found

  1. Install the serve module.
  2. Create a simple application that uses serve to serve static files from the current directory.
  3. Run the application.
  4. Open the browser and go to the local server address to see the directory listing.
  5. Open a URL with multiple encoded '../' sequences to navigate up the directory tree and list the contents of /etc.

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.

The serve tool shows files from a folder on a website. It did not properly block special encoded characters that mean 'go up a folder', so someone could browse folders outside the intended one and see what files are there, but not open them.

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.