Commit 0c2e9a8
fix(templates): prevent unauthenticated draft-mode access in website preview route (#17472)
## What?
Fixes the auth bypass in the website template's preview route
(`templates/website/src/app/(frontend)/next/preview/route.ts`).
Backport of #17205 (bf2d96e) from `main` to `3.x`. Closes #17204
## Why?
`payload.auth()` always resolves to a truthy object — `{ user,
permissions, responseHeaders }` — even when the request is
unauthenticated (in which case `user` is `null`). The route assigned
that whole object to `user`, so the `if (!user)` guard was dead code and
never returned 403.
The practical impact: anyone who knows `PREVIEW_SECRET` (which is only
meant to block crawlers, not authorize users) could enable Next.js draft
mode and read unpublished content without logging in.
## How?
Destructure `user` off the auth result so the guard checks the actual
user rather than the always-truthy wrapper object.
Co-authored-by: Nate Lentz <nlentz@Nates-MacBook-Pro-2.local>1 parent 981b282 commit 0c2e9a8
1 file changed
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| |||
0 commit comments