SSRF Risk

User-controlled URLs passed to fetch in server code

warningSecurityssrf-risk

Why this matters

Server-side request forgery lets attackers make your server fetch internal resources (metadata APIs, databases, admin panels) by passing crafted URLs.

Example

Flaggedapp/api/proxy/route.ts
export 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());
}
Fixedapp/api/proxy/route.ts
const 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 --json and 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-risk at 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