mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 03:57:21 +00:00
Fileserver: Check for valid file paths
This commit is contained in:
parent
124b49456a
commit
a67b1b8bb5
@ -21,8 +21,12 @@ exports.handler = function(request,response,state) {
|
|||||||
fs = require("fs"),
|
fs = require("fs"),
|
||||||
util = require("util"),
|
util = require("util"),
|
||||||
suppliedFilename = decodeURIComponent(state.params[0]),
|
suppliedFilename = decodeURIComponent(state.params[0]),
|
||||||
filename = path.resolve(state.boot.wikiPath,"files",suppliedFilename),
|
baseFilename = path.resolve(state.boot.wikiPath,"files"),
|
||||||
|
filename = path.resolve(baseFilename,suppliedFilename),
|
||||||
extension = path.extname(filename);
|
extension = path.extname(filename);
|
||||||
|
// Check that the filename is inside the wiki files folder
|
||||||
|
if(path.relative(baseFilename,filename).indexOf("..") !== 0) {
|
||||||
|
// Send the file
|
||||||
fs.readFile(filename,function(err,content) {
|
fs.readFile(filename,function(err,content) {
|
||||||
var status,content,type = "text/plain";
|
var status,content,type = "text/plain";
|
||||||
if(err) {
|
if(err) {
|
||||||
@ -36,6 +40,9 @@ exports.handler = function(request,response,state) {
|
|||||||
}
|
}
|
||||||
state.sendResponse(status,{"Content-Type": type},content);
|
state.sendResponse(status,{"Content-Type": type},content);
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
state.sendResponse(404,{"Content-Type": "text/plain"},"File '" + suppliedFilename + "' not found");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
Loading…
Reference in New Issue
Block a user