Skip to content

Instantly share code, notes, and snippets.

@shiawuen
Created September 1, 2011 17:46
Show Gist options
  • Save shiawuen/1186754 to your computer and use it in GitHub Desktop.
Save shiawuen/1186754 to your computer and use it in GitHub Desktop.
prevent access /etc/passwd
var path = require('path')
var userPath = path.normalize('/var/www/app/abc/../../../../../../../../../../etc/passwd')
if (userPath.indexOf(__dirname) == 0 ) {
// Valid path
} else {
// Invalid path
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment