← Secure Go services

SECURITY · GO SERVICES · 7 LESSONS

Secrets, cryptography and supply chain

Redaction, constant-time checks, AEAD encryption, password storage, token design, fuzzing and dependency hygiene.

  1. Keep secrets out of logs and errors with a type that refuses to print itself

    Wrap credentials in a Secret type that redacts itself in fmt, slog and JSON, redact credentials in URLs, and load secrets with errors that name the source but never the value.

    6 min · Worked lesson

  2. Compare secrets in constant time: an early return reveals how much of a guess was right

    Recognize timing-dependent comparisons and replace them with crypto/subtle or hmac.Equal over fixed-size digests, including the lookup and error paths around them.

    5 min · Worked lesson

  3. Encrypt records with AES-GCM: random nonces, a key ID, and the record ID as additional data

    Seal application records with AES-GCM so that tampering, row swapping and key rotation are handled explicitly, and explain why a repeated nonce breaks GCM.

    5 min · Worked lesson

  4. Store passwords with argon2id: encoded parameters, rehash on login, one answer for every failure

    Hash passwords with argon2id in a self-describing PHC-style string, upgrade parameters at login, handle bcrypt's 72-byte limit and keep login failures indistinguishable.

    5 min · Worked lesson

  5. Design tokens deliberately: hashed opaque tokens, strictly verified signed tokens, expiry and rotation

    Choose between opaque and signed tokens, store opaque tokens as hashes with rotation and reuse detection, and verify HMAC-signed JWTs with a pinned algorithm and checked claims.

    5 min · Worked lesson

  6. Fuzz the parsers that read untrusted bytes, and bound what they may allocate or inflate

    Write a native Go fuzz test with seed inputs and real invariants for a binary parser, harden the parser against what it finds, and cap decompressed size with io.LimitReader.

    5 min · Worked lesson

  7. Secure the Go supply chain: reachable vulnerabilities, verified modules, pinned tools, auditable binaries

    Run govulncheck in CI, rely on go.sum and the checksum database correctly, pin tools with tool directives, build with -trimpath, and audit a binary's embedded build information.

    6 min · Worked lesson