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 · 04/10
Medium
Import avatar from a URL
Runs on a cloud VM inside the company network.
app/api/avatar/route.ts
01 · Tap the vulnerable line
1
export async function POST(req: Request) {
2
const session = await requireUser();
3
const { url } = await req.json();
4
const image = await fetch(url, { redirect: "follow" });
5
if (!image.headers.get("content-type")?.startsWith("image/")) {
6
return Response.json({ error: "Not an image" }, { status: 400 });
7
}
8
await storage.put(`avatars/${session.userId}.png`, await image.arrayBuffer());
9
return Response.json({ ok: true });
10
}
02 · What's the problem?
Server-side request forgery (SSRF)
Cross-site scripting (XSS)
Cross-site request forgery (CSRF)
Path traversal
03 · How do you fix it?
Check that the URL starts with https://
Resolve the host, reject private/link-local IPs, connect to that IP and don't follow redirects (or allowlist hosts)
The content-type check already blocks non-images, so it's fine
Check answer