Skip to content

Instantly share code, notes, and snippets.

@glennblock
Created October 13, 2011 01:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glennblock/1283076 to your computer and use it in GitHub Desktop.
Save glennblock/1283076 to your computer and use it in GitHub Desktop.
paperboy patch
exports.filepath = function (webroot, url) {
var pathSep=process.platform ==='win32' ? '\\' : '/';
// Unescape URL to prevent security holes
url = decodeURIComponent(url);
// Append index.html if path ends with '/'
fp = path.normalize(path.join(webroot, (url.match(/\/$/)=='/') ? url+'index.html' : url));
// Sanitize input, make sure people can't use .. to get above webroot
if (webroot[webroot.length - 1] !== pathSep) webroot += pathSep;
if (fp.substr(0, webroot.length) != webroot)
return(['Permission Denied', null]);
else
return([null, fp.replace('/',pathSep)]);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment