Fix redirect target comes from the caller in Next.js

The destination of a redirect is taken from the request without being checked. An attacker can send a link that starts with your domain and ends on theirs, which is what makes a phishing page credible - and in an OAuth callback it hands the authorisation code to whoever asked. Resolve the target against your own origin and refuse anything else.

medium likely Next.js CWE-601 / OWASP A01:2021

The vulnerable pattern in Next.js

MEDIUM likely Redirect target comes from the caller A01:2021 app/api/proxy/route.ts:50:5 48 │ // open-redirect 49 │ if (next) { 50 │ redirect(next) │ ~~~~~~~~~~~~~~ destination chosen by the caller 51 │ }

This finding comes from the Next.js fixture in the owlwarden test suite, in /api/proxy. The whole redirect target comes from the request, so a link to this endpoint can send a visitor anywhere. The URL they click genuinely belongs to you, which is what makes the page they land on convincing - and on an OAuth callback the authorisation code goes with them.

The corrected handler

Validate before calling redirect(); request.nextUrl.origin is the base.

import { redirect } from 'next/navigation'

const next = request.nextUrl.searchParams.get('next')
redirect(safeRedirect(next, request.nextUrl.origin))

If you are not using Next.js

Resolve the target against your own origin and refuse anything that lands elsewhere. Do not use a startsWith('/') check: '//evil.com' passes it and leaves the site.

Check your own repository

npx owlwarden scan
npx owlwarden explain open-redirect

Runs on your machine. No account, no telemetry, no network unless you ask. In CI, SARIF uploads to code scanning and the exit code is the gate.

Other Next.js checks

Rules with a tested Next.js example.

open-redirect for every framework / All rules / owlwarden