Make Redirects.urlPrefix actually gate which route a code resolves under

resolveAndTrackRedirect() now filters on urlPrefix in addition to code,
with each route.ts passing its own literal prefix — previously the field
was admin-display-only, so a code marked "/sticker" in Payload silently
kept resolving under /r/<code> too.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G5mssdCBir9kyXTmqBjV3h
This commit is contained in:
Marco
2026-08-28 13:15:41 +00:00
parent d02707a212
commit 31e4f907f2
3 changed files with 21 additions and 13 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ import { resolveAndTrackRedirect } from "../../lib/payload";
// non-cacheable client-side since the target can change at any time.
export async function GET(_request: NextRequest, { params }: { params: Promise<{ code: string }> }) {
const { code } = await params;
const targetPath = await resolveAndTrackRedirect(code);
const targetPath = await resolveAndTrackRedirect(code, "/r");
// Defense in depth — Redirects.targetPath is already validated in Payload
// to start with "/", same open-redirect guard as api/preview/route.ts.