The Plain Picture#
Most burglaries aren't lock-picking. They're a key under the doormat, a window left open, or a lock bought from a shady seller.
The Real Names#
Secrets management#
A secret is any credential: database passwords, API keys, signing keys, private keys.
| Where | OK? |
|---|---|
| in source code or Git | never (Git Ch 10) |
in a .env file on a developer laptop | acceptable for local development only — Part 0's problem 6 |
| in environment variables on a server | common; watch for leaks through logs and error pages |
| in a secret manager (AWS Secrets Manager, GCP Secret Manager, HashiCorp Vault) | best — access-controlled, audited, rotatable |
| no secret at all: the cloud gives the server an identity with short-lived credentials (IAM roles, workload identity) | even better where possible (AWS Foundations and IAM (coming soon)) |
Rotate secrets regularly and immediately after any possible exposure.
Supply chain — the code you didn't write#
A typical app has hundreds of dependencies (libraries it uses), plus their dependencies. Each is code you run with full permissions.
Known vulnerabilities: scan with
pip-audit(Python),npm audit(JavaScript), GitHub Dependabot. Keep dependencies updated.Lock files (
package-lock.json,poetry.lock,uv.lock) pin exact versions, so a tampered new release doesn't slip in unnoticed (Python Packaging and Tools (coming soon)).Typosquatting: malicious packages with names one letter off popular ones (
reqeustsforrequests). Check what you install.
Brute force and rate limiting#
Brute force / credential stuffing: trying many passwords, or trying email/password pairs leaked from other sites (because people reuse passwords).
Rate limiting: capping requests per user / IP / account per time window — e.g. 5 failed logins per account per 15 minutes — answering 429 (Networking 3: DNS, HTTP and HTTPS Ch 5). The algorithms (token bucket, sliding window) are a classic system design topic (Rate Limiting and API Gateways (coming soon)).
Plus: MFA (Ch 5), breached-password checks (Ch 3), and alerts on unusual login patterns.
Logging for security#
Log security events: logins, failures, permission denials, admin actions — with who, when, from where.
Never log passwords, tokens, full card numbers or secrets.
Error messages to users should be generic ("Invalid email or password" — not "no such user", which lets attackers discover valid emails). Details go to the logs.
Check yourself
4 questionsRank these from worst to best for storing a production database password: in Git, in a secret manager, in an env variable, no
password at all (cloud identity).
Show answerHide answer
Git (worst) → env variable → secret manager → cloud identity with short-lived credentials (best).
What do lock files protect against?
Show answerHide answer
Unexpected or tampered dependency versions being installed; they pin exact, known versions.
What is credential stuffing, and name two defences.
Show answerHide answer
Trying username/password pairs leaked from other sites. Defences: rate limiting, MFA, breached-password checks, anomaly alerts.
Why should a login error not say "no user with that email"?
Show answerHide answer
It reveals which emails have accounts (user enumeration), helping attackers target them.