Fix the static server code for Windows
This commit is contained in:
parent
adc9a292ed
commit
a6c471edf9
1 changed files with 2 additions and 1 deletions
|
@ -310,6 +310,7 @@ There is still one problem - the leak of "server.js" file. We can add a conditio
|
|||
var fs = require("fs");
|
||||
var mime = require("mime-types");
|
||||
var path = require("path");
|
||||
var os = require("os");
|
||||
var port = 8080;
|
||||
var server = http.createServer(function (req, res) {
|
||||
var urlObject = new URL(req.url, "http://localhost");
|
||||
|
@ -327,7 +328,7 @@ There is still one problem - the leak of "server.js" file. We can add a conditio
|
|||
filename = filename.replace(/\\/g,"/").replace(/\/\.\.?(?=\/|$)/g,"/").replace(/\/+/g,"/"); //Poor mans URL sanitizer
|
||||
if(filename == "./") filename = "./index.html";
|
||||
var ext = path.extname(filename).substr(1); //path.extname gives "." character, so we're using substr(1) method.
|
||||
if(filename == "./" + path.basename(__filename)) {
|
||||
if(filename == ("./" + path.basename(__filename)) || (os.platform() == "win32" && filename.toLowerCase() == ("./" + path.basename(__filename)).toLowerCase())) {
|
||||
//Prevent leakage of server source code
|
||||
res.writeHead(403, "Forbidden", {
|
||||
"Content-Type": "text/plain"
|
||||
|
|
Reference in a new issue