Skip to content

Try “polymorphism”, “TCP handshake” or “git rebase”.

    Computer Basics / Security Fundamentals

    Secrets, Dependencies and Brute Force

    Known vulnerabilities: scan with pip-audit (Python), npm audit (JavaScript), GitHub Dependabot. Keep dependencies updated.

    Chapter 11 of 134 min read

    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.

    WhereOK?
    in source code or Gitnever (Git Ch 10)
    in a .env file on a developer laptopacceptable for local development only — Part 0's problem 6
    in environment variables on a servercommon; 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 (reqeusts for requests). 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 questions
    1

    Rank 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 answer

    Git (worst) → env variable → secret manager → cloud identity with short-lived credentials (best).

    2

    What do lock files protect against?

    Show answer

    Unexpected or tampered dependency versions being installed; they pin exact, known versions.

    3

    What is credential stuffing, and name two defences.

    Show answer

    Trying username/password pairs leaked from other sites. Defences: rate limiting, MFA, breached-password checks, anomaly alerts.

    4

    Why should a login error not say "no user with that email"?

    Show answer

    It reveals which emails have accounts (user enumeration), helping attackers target them.