Security Playbook
by Federico Tejedor Llorente
Learn
Learning path
Concepts
Breaches
Practice
Labs
Playground
Quiz
Work with me
🔥 0
⚡ 0
Playbooks
Playbooks
System Design
Security
●
Algorithms
Portfolio
↗
en
English
✓
Español
← All code reviews
Find the bug · 05/10
Easy
Download a CSV export
Users download reports generated for them.
routes/exports.ts
01 · Tap the vulnerable line
1
const EXPORTS = "/srv/app/exports";
2
3
app.get("/exports/download", requireUser, (req, res) => {
4
const file = path.join(EXPORTS, String(req.query.name));
5
if (!file.endsWith(".csv")) return res.status(400).end();
6
res.download(file);
7
});
02 · What's the problem?
Missing ownership check (IDOR)
Path traversal
Server-side request forgery (SSRF)
SQL injection
03 · How do you fix it?
Remove "../" from the name with replace("../", "")
The .csv check already prevents reading other files
Look the export up by ID for this user, or resolve the path and require it to start with EXPORTS + path.sep
Check answer