Skip to content

Commit

Permalink
Fixed path vulnerability
Browse files Browse the repository at this point in the history
  • Loading branch information
AlgoRythm-Dylan committed May 17, 2019
1 parent 7763b4f commit bcfe9d4
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions httpserv.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Stream-based KISS HTTP(S) server

const url = require("url");
const pathlib = require("path")
const fs = require("fs");

// A small database of MIME associations
Expand Down Expand Up @@ -32,7 +33,7 @@ var MIMES = {
".zip": "application/zip"
}

var servePath = "serve";
var servePath = "serve/";
function doStream(request, response, filePath, stats, MIME){
let responseOptions = {};
let streamOptions = {};
Expand Down Expand Up @@ -82,7 +83,11 @@ module.exports.serve = function(request, response){
MIME = MIMES[fileType];
}
// Serve the actual file
var filePath = servePath + path;
var filePath = pathlib.join(servePath, path);
if(filePath.indexOf(servePath) !== 0){
response.end();
return;
}
let handler = handlers[path];
if(handler !== undefined){
if(handler.requestTypes === null || handler.requestTypes.indexOf(request.method) != -1){
Expand Down

0 comments on commit bcfe9d4

Please # to comment.