Skip to content

Commit

Permalink
Fixed traversal vulnerability
Browse files Browse the repository at this point in the history
  • Loading branch information
KoryNunn committed Apr 24, 2017
1 parent 87de3f1 commit 99b0b40
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ function serveFile(request, response, path, info){
var router = beeline.route({
'/`path...`': function(request, response, details){
var path = process.cwd() + '/' + details.path;

if(~pathHelpers.relative(process.cwd(), path).indexOf('..')) {
response.writeHead(401);
response.end('Unauthorized');
return;
}

fs.stat(path, function(error, info){
if(error){
serverError(response, error);
Expand Down
22 changes: 22 additions & 0 deletions test/traversal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Author: Liang Gong
* (colors dep removed)
*/
(function() {
var http = require('http');
var content;
var url = 'http://localhost:8080/../../confidential.txt';

console.log('\t[directory traversal attack]: ' + url);

var content = '';

http.get(url, (res) => {
res.on('data', (chunk) => {
content += chunk.toString('utf-8');
});
res.on('end', () => {
console.log('\t[directory traversal request response]: ' + content.toString('utf-8'));
});
});
})();

0 comments on commit 99b0b40

Please sign in to comment.