#0403
A log-viewing API accepts a serviceName and a date parameter, then reads the file at logDir/serviceName/date.log.
Neither parameter is validated. An attacker sets serviceName to ../../etc and date to passwd.
The constructed path becomes logDir/../../etc/passwd.log — close enough to read sensitive files with predictable names.
Log viewers are a frequent target. Multi-segment paths where each segment is user-controlled multiply the attack surface — validating each component independently with an allowlist is the correct defence.
getLogPath so it validates both serviceName and date against the pattern ^[a-z0-9_-]+$.'Invalid log path' if either parameter fails validation.getLogPath('/var/log', '../../etc', 'passwd')// → throws Error('Invalid log path')
getLogPath('/var/log', 'auth-service', '2024-01-15')// → returns '/var/log/auth-service/2024-01-15.log'
^[a-z0-9_-]+$.