Skip to content

Commit 8bafc95

Browse files
committed
security fix
1 parent d171a77 commit 8bafc95

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

angular-http-server.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,19 @@ function requestListener(req, res) {
6363
// Attaches path prefix with --path option
6464
var possibleFilename = resolveUrl(url.slice(1)) || "dummy";
6565

66-
fs.stat(possibleFilename, function(err, stats) {
66+
var safeFileName = path.normalize(possibleFilename).replace(/^(\.\.[\/\\])+/, '');
67+
var safeFullFilename = path.join(__dirname, safeFileName);
68+
69+
fs.stat(safeFullFilename, function(err, stats) {
6770
var fileBuffer;
6871
if (!err && stats.isFile()) {
69-
fileBuffer = fs.readFileSync(possibleFilename);
70-
let ct = mime.lookup(possibleFilename);
71-
log(`Sending ${possibleFilename} with Content-Type ${ct}`);
72+
fileBuffer = fs.readFileSync(safeFullFilename);
73+
let ct = mime.lookup(safeFullFilename);
74+
log(`Sending ${safeFullFilename} with Content-Type ${ct}`);
7275
res.writeHead(200, { 'Content-Type': ct });
7376

7477
} else {
75-
log("Route %s, replacing with index.html", possibleFilename);
78+
log("Route %s, replacing with index.html", safeFullFilename);
7679
fileBuffer = returnDistFile();
7780
res.writeHead(200, { 'Content-Type': 'text/html' });
7881
}

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-http-server",
3-
"version": "1.4.3",
3+
"version": "1.4.4",
44
"author": "Simon Hampton",
55
"license": "ISC",
66
"description": "Simple http server for developers that supports apps with client side routing",
@@ -28,7 +28,7 @@
2828
}
2929
],
3030
"engines": {
31-
"node": ">=4.0.0"
31+
"node": ">=6.0.0"
3232
},
3333
"preferGlobal": true,
3434
"bin": {

0 commit comments

Comments
 (0)