Security Best Practices Summary
OWASP-oriented checklist for Go HTTP and gRPC APIs.
Search across all documentation pages
OWASP-oriented checklist for Go HTTP and gRPC APIs.
Apply these rules in service templates, code review, and CI so every Go API fails closed and ships with measurable supply-chain hygiene.
ReadHeaderTimeout on every production http.Server. Blocks slow header attacks before handlers execute.ReadTimeout, WriteTimeout, and IdleTimeout per SLO. Prevents hung connections and descriptor leaks.tls.Config.MinVersion to TLS 1.2 or higher on TLS listeners. Documents acceptable protocol floor for audits.NotAfter dates. Incomplete chains cause client failures; expiry causes outages.InsecureSkipVerify on production outbound clients. Disables certificate and hostname verification.http.Client instances with timeouts; never http.DefaultClient in handlers. Default client has no deadline.alg values. Prevents algorithm confusion attacks.role: user is present./metrics, /debug, and admin routes with the same auth rigor as APIs. Attackers scan defaults.http.MaxBytesReader before decode. Rejects oversized payloads early.DisallowUnknownFields on strict public APIs when appropriate. Surfaces client bugs and probing.html/template, not text/template. Auto-escapes content in HTML context.HttpOnly, Secure, and appropriate SameSite. Reduces XSS exfiltration and cross-site cookie abuse.Origin values. Open CORS plus cookies enables data theft.X-Content-Type-Options, frame ancestors) on all responses including errors. Headers must not depend on success paths only.X-Forwarded-For only from known load balancers. Prevents client IP spoofing for rate limits and audit logs.crypto/subtle.ConstantTimeCompare. Reduces timing side channels.golang.org/x/crypto. Never store or compare plaintext passwords.govulncheck ./... in CI and fail on actionable reachable findings. Catches known CVEs in your import graph.go.sum and run go mod verify in CI. Detects module tampering at download.go.mod. Security patches land in Go patch releases.replace directives and private forks as first-party code. Bypass normal module provenance checks.Tier A transport and auth failures, reachable govulncheck findings without approved exceptions, and missing secrets at startup should block deploy.
Tier B browser controls may phase in per client type.
Broken auth maps to section B; unsafe input to C; SSRF and excessive data exposure to C and handler design; misconfiguration to A and D; inventory and logging to F and observability practices.
Yes, with TLS credentials and interceptors replacing HTTP middleware for auth, limits, and metadata validation.
Dedicated mux, server timeouts, TLS min version, auth middleware, body limits, parameterized SQL, govulncheck in CI, and configured outbound clients.
Apply lighter limits or per-service quotas still.
Compromised workloads inside the mesh generate abusive east-west traffic too.
Encode items in arch unit tests, custom golangci-lint wrappers, and deployment checklists tied to service catalog metadata.
Yes - minimal CSP and nosniff still help when responses are misinterpreted by browsers or proxies.
When browsers never send session cookies and clients use Bearer tokens not accessible to attacker-controlled sites.
XSS defense remains critical.
Every release build.
Attach the SBOM to the container image OCI artifact or release page.
Framework routers do not remove checklist items.
Verify their middleware ordering preserves auth, limits, and security headers as intended.
Stack versions: This page was written for Go 1.26.x (Green Tea GC default, go fix modernizers - verify patch at build), chi (latest - verify at build), gin (latest - verify at build), echo (latest - verify at build), google.golang.org/grpc (latest - verify at build), sigs.k8s.io/controller-runtime (latest - verify at build), kubebuilder (latest - verify at build), tinygo (latest - verify board targets at build), wazero (latest - verify at build), and golangci-lint (latest - verify at build).
Reviewed by Chris St. John·Last updated Jul 18, 2026