Skip to content

Security — Core Concepts

Interview Relevance: High — Security is a cross-cutting concern in every system. Know the full request lifecycle: from HTTPS at the wire to JWT validation at the service.


The Security Layers


HTTPS & TLS

Why HTTPS?

TLS Handshake (Simplified)

Key certificate concepts for interviews:

ConceptMeaning
CA (Certificate Authority)Trusted third party that signs certificates (Let's Encrypt, DigiCert)
CertificateBinds a domain name to a public key, signed by CA
TLS 1.3Latest version — 1 round-trip handshake (vs 2 in TLS 1.2)
mTLS (Mutual TLS)Both client AND server present certificates — used for service-to-service auth
Certificate pinningMobile apps reject certs not matching an expected fingerprint
HSTSHTTP header forcing HTTPS-only for all future visits

Authentication vs. Authorization


JWT (JSON Web Token)

JWT is a self-contained token that carries identity claims. The server doesn't need to look up a session store.

JWT Structure

JWT Auth Flow

JWT Security Properties

✅ Stateless — no session store lookup needed (scales easily)
✅ Self-contained — payload carries all needed claims
✅ Tamper-proof — signature verifiable with public key only
✅ Works across services — any service can verify with public key

❌ Cannot be revoked before expiry (use short TTL + refresh tokens)
❌ Payload is Base64 encoded — NOT encrypted (don't put secrets in it)
❌ If private key is compromised — all tokens are compromised

JWT best practices:

• Access token TTL: 15 minutes (short — limits damage if stolen)
• Refresh token TTL: 7–30 days (long-lived, stored in HttpOnly cookie)
• Use RS256 (asymmetric) not HS256 (shared secret) for microservices
• Store in memory or HttpOnly cookie — never localStorage (XSS risk)
• Revocation: maintain a token blocklist in Redis (for logout/compromise)

OAuth 2.0

OAuth is an authorization framework that lets users grant third-party apps access to their data without sharing their password.

The Authorization Code Flow (Most Secure)

OAuth Roles

RoleDescriptionExample
Resource OwnerThe user who owns the dataAlice
ClientThe app requesting accessyour-app.com
Authorization ServerIssues tokens after user consentGoogle, Auth0, Okta
Resource ServerThe API that has the user's dataGoogle APIs

OAuth Scopes

scope=email           → Read user's email address
scope=profile         → Read name, picture
scope=repo            → GitHub: read/write repos
scope=read:orders     → Your app: read orders only
scope=write:orders    → Your app: create/update orders

Principle of Least Privilege: Request only the scopes you need.

Authorization Models

RBAC — Role-Based Access Control

✅ Simple to understand and manage
✅ Good for well-defined roles (admin, editor, viewer)
❌ Role explosion: 100 roles for complex permission sets
❌ Not fine-grained enough for resource-level permissions

ABAC — Attribute-Based Access Control

✅ Very fine-grained — any attribute combination
✅ Dynamic — adapts to context (time, location, device)
✅ Used by AWS IAM policies, Google Cloud IAM
❌ Complex to write and debug policies
❌ Performance overhead (policy evaluation per request)

WAF — Web Application Firewall

A WAF sits in front of your application and filters HTTP traffic based on rules targeting known attack patterns.

OWASP Top 10 (What WAF Protects Against)

RankVulnerabilityExample AttackWAF Defense
A01Broken Access ControlAccessing /admin without authAuth enforcement rules
A02Cryptographic FailuresStoring passwords in plaintextPolicy enforcement
A03SQL Injection' OR '1'='1 in query paramsSQLi pattern matching
A07XSS (Cross-Site Scripting)<script> in form inputXSS signature rules
A10Server-Side Request Forgeryurl=http://169.254.169.254/ (AWS metadata)SSRF blocklist rules

Encryption at Rest

Encryption levels:

LevelWhatTool
Disk encryptionFull disk encrypted (OS level)AWS EBS encryption, Linux LUKS
DB-levelDB files on disk encryptedMySQL TDE, PostgreSQL pgcrypto
Column-levelOnly sensitive columns encryptedApplication-level AES-256
Field-levelIndividual values encrypted in appAWS KMS + envelope encryption

Worked Example: Secure URL Shortener

Security decisions table:

ConcernSolutionReason
TransportTLS 1.3 + HSTSEncrypt in transit, prevent downgrade
DDoSCloudflare WAF + rate limitingBlock before reaching origin
AuthNJWT RS256 (15min TTL) + refresh tokensStateless, short-lived
AuthZRBAC (free/paid tiers) + scope checkPrinciple of least privilege
SecretsHashiCorp Vault (dynamic DB creds)No hardcoded secrets, auto-rotated
Data at restAES-256 TDE + column encryption for PIIDefense in depth
AuditStructured logs (who shortened what, when)Compliance + breach investigation

Interview Cheat Sheet

One-Line Summaries

HTTPS/TLS:     Encrypts data in transit — prevents eavesdropping and MITM
mTLS:          Both sides present certs — used for service-to-service auth
JWT:           Self-contained signed token — stateless, tamper-proof, short-lived
OAuth 2.0:     Authorization framework — delegate access without sharing passwords
RBAC:          Role-based permissions — simple, good for well-defined roles
ABAC:          Attribute-based — fine-grained, dynamic (AWS IAM style)
WAF:           Filters malicious HTTP — blocks SQLi, XSS, OWASP Top 10
Encryption at rest: AES-256 on disk/DB — protects from physical/storage compromise
Secret Manager: Vault/KMS — no hardcoded credentials, auto-rotation

The Interview Phrase

"For security, I'd apply defense in depth across every layer:
 TLS 1.3 encrypts all traffic in transit. Cloudflare WAF sits at
 the edge blocking OWASP Top 10 attacks and DDoS. The API Gateway
 terminates TLS, enforces rate limits, and validates RS256-signed
 JWTs with a 15-minute TTL. Internal service-to-service calls use
 mTLS for mutual authentication. All secrets — DB credentials, API
 keys — are stored in HashiCorp Vault with daily rotation. PII data
 in the database is AES-256 encrypted at the column level, and all
 access is audit-logged for compliance."

Red Flags vs. Green Flags

🔴 Red Flag🟢 Green Flag
Store JWT in localStorageHttpOnly cookie — prevents XSS token theft
Long-lived access tokens (days)15-min access token + 7-day refresh token
Hardcode DB passwords in codeHashiCorp Vault or AWS Secrets Manager
No WAF mentionedWAF at edge (Cloudflare) for OWASP protection
Use HS256 in microservicesRS256 — only auth service has private key
Skip mTLS for internal servicesmTLS for zero-trust service-to-service auth
Confuse AuthN and AuthZState explicitly: JWT = AuthN; RBAC/scope = AuthZ

IMPORTANT

Always mention defense in depth. A single security control is never enough. Say: "Security is applied at every layer — WAF at the edge, TLS in transit, JWT at the gateway, RBAC at the service, and AES-256 encryption at rest."

TIP

Mentioning mTLS for service-to-service communication and secret rotation via Vault/KMS signals senior-level security awareness that most candidates skip.

Released under the ISC License.