fix an issue in the path handling that allowed directory traversal

pull/2593/head
Tom Hunkapiller 2015-04-10 19:25:52 -05:00
parent be0a96af6e
commit 3ebb19d8a2
1 changed files with 6 additions and 2 deletions

View File

@ -23,6 +23,7 @@ exports.expressCreateServer = function (hook_name, args, cb) {
}); });
var rootTestFolder = path.join(npm.root, "..", "/tests/frontend/");
var url2FilePath = function(url){ var url2FilePath = function(url){
var subPath = url.substr("/tests/frontend".length); var subPath = url.substr("/tests/frontend".length);
if (subPath == ""){ if (subPath == ""){
@ -30,8 +31,11 @@ exports.expressCreateServer = function (hook_name, args, cb) {
} }
subPath = subPath.split("?")[0]; subPath = subPath.split("?")[0];
var filePath = path.normalize(npm.root + "/../tests/frontend/") var filePath = path.normalize(path.join(rootTestFolder, subPath));
filePath += subPath.replace("..", ""); // make sure we jail the paths to the test folder, otherwise serve index
if (filePath.indexOf(rootTestFolder) !== 0) {
filePath = path.normalize(path.join(rootTestFolder, "index.html"));
}
return filePath; return filePath;
} }