Operating
Security
What the template protects against, and the checklist to run before production.
What the template does
| Protection | How |
|---|---|
| Content-Security-Policy | script-src 'self' with no inline script and no 'unsafe-eval'; frame-ancestors 'none'; form-action 'self'; object-src 'none'. |
| Other headers | nosniff, Referrer-Policy, Permissions-Policy, Cross-Origin-Opener-Policy. HSTS with includeSubDomains in production only. |
| CSRF | A 32-byte random token in an HttpOnly, SameSite=Lax cookie, echoed in X-CSRF-Token and compared in constant time on every non-safe request. |
| Cross-origin requests | Go's CrossOriginProtection rejects cross-site browser requests, as defence in depth. |
| Rate limits | Per client, strict in production: 20 requests a second with a burst of 60, and 5 mutations a second with a burst of 20. |
| Body size | 1 MiB on every request. |
| Timeouts | Read, write, idle and header timeouts on the server, and graceful shutdown. |
| Errors | Clients get a generic message. The details go to the server log with the request ID. |
| Config | An unknown GoEnv refuses to start instead of acting like development. |
Behind a proxy
The rate limiter counts per TCP peer address, and it ignores X-Forwarded-For, because a client can forge that header. Behind a reverse proxy or load balancer every visitor would then share the proxy's one bucket, and one busy user could lock everyone out. Choose one fix:
- Rate-limit at the proxy (nginx limit_req, Caddy, your CDN or load balancer), and loosen or remove the in-app limits.
- Or trust the forwarded address only from your proxy: add middleware in front of the rate limiter that replaces r.RemoteAddr with the client address from X-Forwarded-For, only when the request really comes from your proxy. Take the right-most address your proxy appended, never the left-most one the client sent.
Known limits
- Without --auth there is no sign-in. Every route is public, and nothing is tied to a user. With sign-in, authorisation is still yours: auth.RequireUser only checks that someone is signed in.
- There is no second factor (TOTP or passkeys) yet.
- The CSRF token is a double-submit cookie. With sign-in it is replaced at sign-in and sign-out, but it is not bound to the session.
- Rate limits live in memory, per process. Several instances each keep their own counters, so use the proxy or a shared store for a global limit.
- The app does not terminate TLS. Put a TLS-terminating proxy or platform in front of it.
Was this page helpful?
Be the first to answer.