Path sanitizing on NodeJS

JS
S
JavaScript

Prevents directory traversal attacks by sanitizing file paths in Node.js applications, ensuring safer file system operations.

1const path = require('path');
2
3//  joins all given path segments together
4const staticPathBack = path.posix.join('/', 'var', 'log', '..'); // /var
5const staticPath = path.posix.join('/', 'var', 'log'); // /var/log
6const messedPath = path.normalize('/var/log//nginx/asdf/quux/..'); // /var/log/nginx/asdf
7

Created on 2/21/2018