SSRF Risk
User-controlled URLs passed to fetch in server code
warningSecurity
ssrf-riskWhy this matters
Server-side request forgery lets attackers make your server fetch internal resources (metadata APIs, databases, admin panels) by passing crafted URLs.
Example
app/api/proxy/route.tsexport async function GET(req: Request) {
const url = new URL(req.url);
const target = url.searchParams.get("url")!;
const res = await fetch(target);
return new Response(await res.text());
}app/api/proxy/route.tsconst ALLOWED_HOSTS = ["api.example.com"];
export async function GET(req: Request) {
const url = new URL(req.url);
const target = new URL(url.searchParams.get("url")!);
if (!ALLOWED_HOSTS.includes(target.hostname)) {
return new Response("Forbidden", { status: 403 });
}
const res = await fetch(target.toString());
return new Response(await res.text());
}How to fix
Validate and allowlist the hostname before making server-side requests. Block internal IPs (127.0.0.1, 169.254.x.x, 10.x.x.x) and cloud metadata endpoints.
Reference
- In the output
- Findings carry
"ruleId": "ssrf-risk"in--jsonand the same id in SARIF and in the terminal. - Silence one line
// prodlint-disable-next-line ssrf-risk- Silence a whole file
// prodlint-disable ssrf-riskat the top of the file- How it works
- Reads the syntax tree, with a text fallback for files that don't parse. Source on GitHub