Open Redirect
User input passed directly to redirect()
warningSecurity
open-redirectWhy this matters
Open redirects let attackers craft URLs on your domain that redirect to phishing sites. Users trust your domain, so they click — and land on a credential-stealing page.
Example
app/go/route.tsexport async function GET(req: Request) {
const url = new URL(req.url);
const next = url.searchParams.get("next") ?? "/";
redirect(next);
}app/go/route.tsexport async function GET(req: Request) {
const url = new URL(req.url);
const next = url.searchParams.get("next") ?? "/";
// Only allow relative paths
const safe = next.startsWith("/") &&
!next.startsWith("//") ? next : "/";
redirect(safe);
}How to fix
Validate redirect targets are relative paths on your own domain. Reject absolute URLs, protocol-relative URLs (//), and any input that doesn't start with a single slash.
Reference
- In the output
- Findings carry
"ruleId": "open-redirect"in--jsonand the same id in SARIF and in the terminal. - Silence one line
// prodlint-disable-next-line open-redirect- Silence a whole file
// prodlint-disable open-redirectat 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