Skip to content
SprecherEast
Issue 234

bug: Sign-in cookie lacks the Secure flag in production

Back to our plan
Done
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.secure to true in production (from NODE_ENV or the server URL being https), keeping local http dev working.
  • Add an HSTS header in Caddy (server config: needs its own infra issue per AGENTS.md, with rollback steps).

Acceptance criteria

  • Not done: In production the payload-token cookie has Secure, HttpOnly and SameSite=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

See it on GitHub, opens in a new tab