Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,16 +522,34 @@ exports.Server = function Server(bsClient, workers, config, callback) {
response.end();
},
'_patch': function patchHandler(uri, body, request, response) {
var filePath = path.join(__dirname, uri);
logger.trace('_patch', filePath);

handleFile(filePath, request, response, true);
var root = __dirname;
try {
var absPath = path.resolve(root, '.' + uri);
var filePath = fs.realpathSync(absPath);
if (!filePath.startsWith(root)) {
sendError(response, 'Forbidden', 403);
return;
}
logger.trace('_patch', filePath);
handleFile(filePath, request, response, true);
} catch (err) {
sendError(response, 'Invalid path', 400);
}
},
'_default': function defaultHandler(uri, body, request, response) {
var filePath = path.join(process.cwd(), uri);
logger.trace('_default', filePath);

handleFile(filePath, request, response);
var root = process.cwd();
try {
var absPath = path.resolve(root, '.' + uri);
var filePath = fs.realpathSync(absPath);
if (!filePath.startsWith(root)) {
sendError(response, 'Forbidden', 403);
return;
}
logger.trace('_default', filePath);
handleFile(filePath, request, response);
} catch (err) {
sendError(response, 'Invalid path', 400);
}
}
};

Expand Down