GOTTH+
GitHub

Operating

Security

What the template protects against, and the checklist to run before production.

What the template does

ProtectionHow
Content-Security-Policyscript-src 'self' with no inline script and no 'unsafe-eval'; frame-ancestors 'none'; form-action 'self'; object-src 'none'.
Other headersnosniff, Referrer-Policy, Permissions-Policy, Cross-Origin-Opener-Policy. HSTS with includeSubDomains in production only.
CSRFA 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 requestsGo's CrossOriginProtection rejects cross-site browser requests, as defence in depth.
Rate limitsPer client, strict in production: 20 requests a second with a burst of 60, and 5 mutations a second with a burst of 20.
Body size1 MiB on every request.
TimeoutsRead, write, idle and header timeouts on the server, and graceful shutdown.
ErrorsClients get a generic message. The details go to the server log with the request ID.
ConfigAn 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.