Use a secure-by-default approach for inputs, secrets, crypto, and supply chain.
-
Input & Output Hardening:
-
Validate all inputs (length, format, allow-lists).
-
Sanitize outputs for HTML/SQL; never build SQL with string concatenation—use placeholders or query builders.
-
-
AuthN/Z Patterns:
-
Prefer short-lived JWTs or opaque tokens with server-side introspection.
-
Use
context
to propagate identity/permissions; enforce role/attribute checks close to handlers.
-
-
Crypto & TLS:
-
Use standard libs for hashing/HMAC/signing; avoid rolling your own crypto.
-
Enforce TLS 1.2+; verify server certs; pin to root/intermediate as needed.
-
-
Secrets & Config:
-
Load secrets from environment/secret stores (Kubernetes Secrets, Vault).
-
Prevent secrets in logs; scrub known keys; restrict file permissions.
-
-
Web Security:
-
Set
Secure
,HttpOnly
,SameSite
cookies; add CSRF protection for state-changing requests. -
Apply safe defaults for CORS (restrict origins/methods/headers).
-
Implement rate limiting and request size limits to resist abuse.
-
-
Supply Chain & CI:
-
Pin dependencies with
go.mod
; rungovulncheck
and dependency audits in CI. -
Sign builds (SLSA/COSIGN) and produce SBOMs; verify images at deploy.
-
-
Practical Lab:
-
Threat model a small Go API, add middleware for auth, rate-limiters, CSRF, and input validation; integrate
govulncheck
and secret scanners; demonstrate blocked attacks and safe fallbacks.
-