Skip to content

Commit

Permalink
Thrift-4647: Node.js Filesever webroot fixed path
Browse files Browse the repository at this point in the history
Updates the node.js fileserver to have a fixed based webroot which can
not be escaped by end users.
  • Loading branch information
jfarrell authored and jeking3 committed Oct 11, 2018
1 parent d566da7 commit 2a2b72f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/js/test/server_http.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const ThriftTestSvcOpt = {
};

const ThriftWebServerOptions = {
files: '.',
files: __dirname,
services: {
'/service': ThriftTestSvcOpt
}
Expand Down
2 changes: 1 addition & 1 deletion lib/js/test/server_https.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const ThriftTestSvcOpt = {
};

const ThriftWebServerOptions = {
files: '.',
files: __dirname,
tls: {
key: fs.readFileSync('../../../test/keys/server.key'),
cert: fs.readFileSync('../../../test/keys/server.crt')
Expand Down
10 changes: 9 additions & 1 deletion lib/nodejs/lib/thrift/web_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,15 @@ exports.createWebServer = function(options) {

//Locate the file requested and send it
var uri = url.parse(request.url).pathname;
var filename = path.join(baseDir, uri);
var filename = path.resolve(path.join(baseDir, uri));

//Ensure the basedir path is not able to be escaped
if (filename.indexOf(baseDir) != 0) {
response.writeHead(400, "Invalid request path", {});
response.end();
return;
}

fs.exists(filename, function(exists) {
if(!exists) {
response.writeHead(404);
Expand Down

0 comments on commit 2a2b72f

Please sign in to comment.