Issue 234
bug: Sign-in cookie lacks the Secure flag in production
Back to our planDone
bugauthpriority: high
Type
bug
Summary
The sign-in cookie is sent without the Secure flag in production, and the site sends no HSTS header.
Problem
Payload sets Secure on its auth cookie only when the Users collection has auth.cookies.secure: true; the default is false (found in the #231 review, confirmed in @payloadcms/next 3.91). Caddy serves HTTPS but sends no Strict-Transport-Security, so a first visit over plain HTTP (the IP on port 80 still answers) can carry the cookie in clear text. Same on main.
Proposed fix
- Set
auth.cookies.secureto true in production (fromNODE_ENVor the server URL being https), keeping local http dev working. - Add an HSTS header in Caddy (server config: needs its own
infraissue per AGENTS.md, with rollback steps).
Acceptance criteria
- Not done: In production the
payload-tokencookie hasSecure,HttpOnlyandSameSite=Lax. - Not done: A test pins the setting.
- Not done: Local sign-in over http still works.
Area
auth
Priority
high
Generated by Claude Code, opens in a new tab