Skip to content
This repository has been archived by the owner on Jul 22, 2019. It is now read-only.

Commit

Permalink
Fix path traversal
Browse files Browse the repository at this point in the history
  • Loading branch information
tnantoka committed Feb 15, 2018
1 parent c5c1410 commit eae8ad8
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions bin/public
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ switch (args[0]) {
}
}
}
var root = path.resolve(dir);

if (path) {
http.createServer(function(req, res) {
Expand All @@ -75,6 +76,13 @@ if (path) {
var base = filePath.replace(dir, ''); // Base path for browser link
var abs = path.resolve(filePath);
console.log(new Date().toString(), abs);

if (abs.indexOf(root) !== 0) {
res.writeHead(403, { 'Content-Type': 'text/plain' });
res.end('Forbidden\n');
return;
}

fs.readFile(filePath, function(err, data) {
if (err) {
res.writeHead(200, { 'Content-Type': 'text/html' });
Expand Down

0 comments on commit eae8ad8

Please # to comment.