Using path.join() with Unvalidated User Input
Applications use Node.js path.join() with user-controlled input believing it provides automatic security against path traversal: const filePath = path.join(baseDir, req.query.file). However, path.join() only normalizes path separators and resolves . and .. - it doesn't restrict traversal outside the base directory. Attackers provide input like '../../../etc/passwd' and path.join() produces valid traversal paths. Developers mistakenly think path.join() is a security function when it's purely for cross-platform path construction. Absolute paths passed to path.join() can completely replace the base path: path.join('/safe', '/etc/passwd') returns /etc/passwd on Unix. Even with path.join(), applications must validate the resulting path stays within intended boundaries.