Skip to content

Instantly share code, notes, and snippets.

@mykiimike
Last active August 29, 2015 14:23
Show Gist options
  • Save mykiimike/a162541761df6fd54f48 to your computer and use it in GitHub Desktop.
Save mykiimike/a162541761df6fd54f48 to your computer and use it in GitHub Desktop.
NodeJS Prevent Local File Inclusion and NULL byte attack
String.prototype.safe = function() {
var s = this.toString().split("/"), r = [];
for(var a in s) {
if(s[a] != "..")
r.push(s[a]);
}
r = r.join("/");
var i = r.indexOf("\0");
if(i > 0)
r = r.substr(0, i);
return(r);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment