#0401
A file-download endpoint accepts a filename parameter and serves the file from a designated base directory.
The handler naively concatenates the base directory with the user-supplied filename — no sanitisation is applied.
An attacker supplies ../../../etc/passwd as the filename, escaping the base directory entirely and reading arbitrary files from the server.
Path traversal is consistently in the OWASP Top 10. A single unsanitised filename parameter can expose /etc/passwd, SSH keys, environment files, and application secrets.
getSafePath so it rejects filenames that escape the base directory.'Path traversal detected' when the resolved path does not start with baseDir.getSafePath('/var/app/uploads', '../../../etc/passwd')// → throws Error('Path traversal detected')
getSafePath('/var/app/uploads', 'report.pdf')// → returns '/var/app/uploads/report.pdf'
.. segments manually or with path utilities; verify the result starts with baseDir.