Security & Operations

Auth, Abuse & Security Basics

Authenticate callers, authorize actions, protect secrets, and blunt common abuse.

Intermediate, about 60 minutes to read, 4 open questions to practise.

1Understand

The idea

Security in system design is not a bolt-on box labeled WAF. It is how every hop answers who is this caller and are they allowed to do this on this resource. Authentication establishes identity; authorization enforces policy on each sensitive operation. Secrets live outside git; clients are untrusted for prices, roles, and ownership.

Interviews test whether you place validation at the trust boundary (API gateway, first middleware), whether tokens have sane lifetimes and revocation, and whether service-to-service calls use mTLS or scoped service credentials instead of forwarding a user cookie into the payment tier.

Abuse controls, rate limits on login, CAPTCHA, WAF rules, reduce brute force but do not replace authz. A valid JWT for Alice must not let her GET /orders/{bob_order_id} unless policy says so. Name the failure mode: credential stuffing, IDOR, secret leak in image layer, insider over-broad IAM.

Intuition

Authn mechanisms (pick one story). Sessions: server stores session id in Redis/DB; cookie is opaque; easy revoke on logout; sticky or shared session store required. JWT access tokens: signed claims (sub, exp, scope); verify signature and expiry on every request; refresh token rotation for long-lived mobile; revocation via short access TTL (5-15m) plus refresh denylist or session version claim.

OAuth/OIDC for “Login with Google”, your app gets tokens from IdP; still need your session or JWT for API calls; do not confuse IdP identity with your internal user_id mapping table.

Authz patterns. Ownership: resource.owner_id === caller.sub. RBAC: role from DB, never from client JSON. ABAC / scopes: orders:read on token; check on each route. Enforce at API layer closest to user; downstream services re-validate service identity, not re-trust user headers without cryptographic proof.

Service-to-service. User cookie forwarded service-to-service is an anti-pattern. Prefer mTLS between meshes, or signed service JWT with audience payment-service. Least-privilege IAM roles for workers (S3 prefix, specific queue).

Secrets. KMS/Vault/Secrets Manager; inject at runtime; rotate; separate dev/staging/prod; scan CI for leaked keys. Never embed in Docker layers that ship to registry.

Public surface. Rate limit /login and /signup by IP + account; lockout/backoff; WAF for OWASP top ten; validate and canonicalize input server-side; audit admin mutations.

Defense in depth sketch: TLS edge, authn, authz, rate limits, network policies, encryption at rest for PII columns. Say what you skip in MVP and what you never skip (authz on id-based reads).

What you will be able to do

  • Separate authentication from authorization
  • Keep secrets out of config repos and images
  • Combine rate limits with auth for abuse control

When this comes up

  • OAuth / JWT
  • Least privilege
  • Secrets
  • WAF / bot

2See it

Architecture sketch

Authn then authz

Identity at the edge; permission check on every sensitive resource access.

100%
ClientGatewayServiceOtherStore

Walkthrough

Stop IDOR

Valid token ≠ access to Bob’s order

1 / 4

100%

Alice presents a valid JWT. Authentication passed. That is not authorization.

Read the walkthrough as text

Worked example, B2C marketplace API + partner webhooks.

Actors: mobile app users, admin panel, partner shipping webhooks, internal order→payment call.

  1. Users: email/password or OIDC → issue access JWT 15m + refresh 7d httpOnly cookie or secure storage; store user_id server-side mapping; rotate refresh on use.
  2. Every API route: gateway terminates TLS; middleware validates JWT signature, exp, audience; attach caller to context.
  3. Authz IDOR trap: GET /orders/{id} loads order from DB, checks order.user_id === caller.sub before return; admin uses separate role from DB, not role field in mobile JSON.
  4. Checkout pricing: server recomputes line totals from catalog table; ignore client totalCents.
  5. Partners: webhook POST /hooks/shipment requires HMAC-SHA256 of body with shared secret + timestamp skew < 5m; reject replays via nonce store.
  6. Order → payment: mTLS or service account JWT with audience payment; payment service does not accept arbitrary X-User-Id without signed user context.
  7. Secrets: RDS creds from secrets manager at boot; Stripe keys never in repo; CI blocks commits matching secret patterns.
  8. Abuse: 20 login attempts / 10m / IP; alert on 5xx spike on auth; CAPTCHA after failures.

What interviewers listen for: authn vs authz named explicitly; IDOR prevention example; partner signature; no trust client; service identity distinct from user session.

Napkin math

Auth napkin

authn at gateway: validate JWT / session

access token TTL = 15 min, refresh longer

authz on every sensitive resource (not once)

least privilege: role / policy per action

secrets in vault, never in images

Know who, then ask may they. Every time.

3Answer it

How to answer in an interview

When the prompt is public API, login, payments, or multi-service:

  1. Caller types, human, partner, internal job, admin, different credentials each.
  2. Authn, session vs JWT vs mTLS; token lifetimes; refresh/revoke story.
  3. Authz, one concrete resource check (order ownership).
  4. Secrets, where stored, rotation, blast radius if leaked.
  5. Abuse, rate limits on auth endpoints; WAF if internet-facing.
  6. Transport, TLS 1.2+; mTLS inside mesh if microservices.
  7. What you will not do, trust client price/role; forward cookies blindly.

Phrases: “authenticate at the edge,” “authorize on every id-based read,” “short-lived access, rotating refresh,” “least-privilege service account.”

Answer checklist

1. Who is the caller (user, service, anonymous)? 2. Authn mechanism and token lifetime. 3. Authz checks at the right boundary. 4. Secrets storage and rotation. 5. Abuse: rate limit, bot, injection assumptions.

Tradeoffs & numbers

  • JWT stateless: horizontal scale easy; revocation needs short TTL + refresh infrastructure.
  • Server sessions: instant logout; Redis SPOF unless clustered, acceptable for web-heavy products.
  • mTLS everywhere: strong service identity; cert renewal and mesh ops cost, worth at >5 services handling money.
  • Strict WAF: blocks scanners; can break mobile clients with odd headers, tune and monitor false positives.
  • OAuth: delegates password risk; adds IdP dependency and account-linking edge cases.
  • When NOT to over-build: internal admin tool behind VPN, SSO + RBAC may suffice; skip bot detection until public signup exists.

Kinds of questions (4)

Same pattern, different interview surfaces. Recognise which variant you are in before you answer.

  • User login / session or JWT

    Example. Banking-lite app: stolen device must not keep API access for days without re-auth. Place authn/authz at the trust boundary, never trust client prices/roles, and name one abuse scenario (IDOR, stuffing, leaked secret).

    How. Short access JWT (10m), refresh rotation, biometric step-up for wire transfers; server-side session version bump on password change.

  • Service-to-service auth

    Example. Order service calls payment and inventory; attacker must not invoke payment directly. Place authn/authz at the trust boundary, never trust client prices/roles, and name one abuse scenario (IDOR, stuffing, leaked secret).

    How. mTLS between mesh identities; payment accepts only `order-service` SPIFFE ID; user id passed as signed internal claim, not spoofable header.

  • Secrets and KMS

    Example. Contractor laptop had clone of repo; old API key still worked in production. Place authn/authz at the trust boundary, never trust client prices/roles, and name one abuse scenario (IDOR, stuffing, leaked secret).

    How. Keys only in KMS references; inject at deploy; quarterly rotation; audit `GetSecretValue`; block git hooks on pattern match.

  • Public endpoint abuse

    Example. Credential stuffing against `/login` from 50k IPs; legitimate users locked out. Place authn/authz at the trust boundary, never trust client prices/roles, and name one abuse scenario (IDOR, stuffing, leaked secret).

    How. Per-IP and per-username rate limits, progressive CAPTCHA, WAF reputation lists, anomaly dashboard on failed auth ratio. JWT validation + policy check per resource; secrets in KMS; rate limit login; audit sensitive reads.

Common mistakes

Failure modes the AI coach watches for when you practise open questions.

Trust the client

Avoid. Client sends role=admin or price=1. Server trusts it.

Prefer. Server loads price/role from trusted stores after authz.

Weak sketch

Bad

100%

Stronger sketch

Good

100%
  • Authn as authz

    Why it happens. Valid identity does not imply permission on arbitrary object ids, classic IDOR data breach pattern.

    How it fails. Middleware verifies JWT signature then returns any `GET /invoices/{id}` if token not expired.

    Fix. After authn, load resource and enforce ownership/role/scopes server-side on every sensitive read and write.

  • Secrets in code

    Why it happens. Git history, forks, and CI logs are permanent; rotation requires redeploy of every copy; scanners exfiltrate within minutes.

    How it fails. Production Stripe secret and DB URL committed in `config/default.json` on a public template repo.

    Fix. Secret manager + IAM-scoped access; inject at runtime; rotate and revoke leaked keys; scan PRs.

  • Trusts the client

    Why it happens. Mobile and browser payloads are fully attacker-controlled; trusting them bypasses business rules.

    How it fails. Checkout persists `discountPercent: 100` from JSON without server-side promotion engine validation.

    Fix. Recompute price from authoritative catalog and entitlements; strip privilege fields from client input.

4Practise

Concept check

A short quiz on this lesson before open questions. Optional, and it does not gate practice.

Open questions

Ready to practise?

Write an answer, get AI coaching, then revise. You are not building a real system.

Practise with an open question

All systems lessons