fix(security): validate resolved data path to prevent path traversal
Some checks failed
Code Analysis and Production Deploy / deploy-production (push) Has been cancelled
Code Analysis and Production Deploy / deploy-test (push) Has been cancelled
Code Analysis and Production Deploy / analyze (push) Has been cancelled

This commit is contained in:
Torsten Schulz (local)
2026-05-27 19:51:15 +02:00
parent 026e4ba3e4
commit 18a08b0e7a

View File

@@ -14,7 +14,15 @@ function getDataPath(filename) {
const cwd = process.cwd()
const dataDir = cwd.endsWith('.output') ? path.join(cwd, '../server/data') : path.join(cwd, 'server/data')
return path.join(dataDir, safeName)
// build candidate path and verify it's inside the expected data directory
const candidate = path.join(dataDir, safeName)
const resolved = path.resolve(candidate)
const resolvedDataDir = path.resolve(dataDir)
if (!resolved.startsWith(resolvedDataDir + path.sep) && resolved !== resolvedDataDir) {
throw new Error('Invalid data filename (outside data directory)')
}
return resolved
}
const LOG_FILE = getDataPath('password-reset.log.jsonl')