Skip to main content

01 - Introduction to Authentication & Authorization

Identity management is the fundamental pillar of modern application security. In any computing ecosystem, securing system boundaries begins by separating two distinct operations: Authentication (AuthN) and Authorization (AuthZ).

[!IMPORTANT] Authentication precedes Authorization: Authentication establishes who an entity is. Authorization determines what actions that authenticated entity is permitted to execute. Conflating these two concepts leads to critical security design flaws, such as using identity tokens for access control or trusting unverified user assertions.


1. AuthN vs AuthZ: Comprehensive Comparison

Understanding the exact boundary between AuthN and AuthZ is necessary for building resilient access control systems.

AttributeAuthentication (AuthN)Authorization (AuthZ)
Core Question"Who are you?""What are you allowed to do?"
Primary ObjectiveEstablish and verify entity identityEnforce access rules and policy constraints
Data HandledCredentials, Passwords, Biometrics, Keys, Id TokensRoles, Permissions, Attributes, Relationships, Scope
Protocol StandardsOpenID Connect (OIDC), SAML 2.0, FIDO2/WebAuthnOAuth 2.0 (Scopes), XACML, Rego/OPA, Cedar
TimingPerformed upon initial login or session establishmentEvaluated continuously on every API/resource request
Failure Mode401 Unauthorized (Unauthenticated)403 Forbidden (Authenticated but unprivileged)
Common VulnerabilitiesCredential Stuffing, Brute Force, Session HijackingBOLA/IDOR, BFLA, Privilege Escalation

2. Authentication (AuthN) Mechanics & Factors

Authentication relies on presenting proof of identity across one or more Authentication Factors:

┌───────────────────────────────────────────┐
│ AUTHENTICATION FACTORS │
└─────────────────────┬─────────────────────┘

┌──────────────────────────────┼──────────────────────────────┐
▼ ▼ ▼
┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐
│ KNOWLEDGE │ │ POSSESSION │ │ INHERENCE │
│ "Something You │ │ "Something You │ │ "Something You │
│ Know" │ │ Have" │ │ Are" │
├──────────────────┤ ├──────────────────┤ ├──────────────────┤
│ • Password / PIN │ │ • Hardware Key │ │ • Fingerprint │
│ • Security Qs │ │ (YubiKey/FIDO2)│ │ • Facial Recog │
│ • Passphrase │ │ • Authenticator │ │ • Retina Scan │
│ │ │ App (TOTP) │ │ • Voice Pattern │
│ │ │ • SMS / Push │ │ │
└──────────────────┘ └──────────────────┘ └──────────────────┘

NIST SP 800-63B Authenticator Assurance Levels (AAL)

The National Institute of Standards and Technology (NIST) classifies identity verification into three assurance levels:

  • AAL1 (Single-Factor): Requires single-factor authentication (e.g., password only). High vulnerability to credential theft.
  • AAL2 (Multi-Factor): Requires two distinct authentication factors (e.g., password + TOTP authenticator app). Protects against automated mass attacks.
  • AAL3 (Hardware MFA): Requires key-based hardware authenticators (e.g., FIDO2 YubiKey) with cryptographic proof of possession. Fully phishing-resistant.

3. Session-based vs Token-based Architecture

Web and API applications generally implement one of two paradigm models for maintaining authentication state across requests: Stateful Session-based or Stateless Token-based.

A. Session-based Authentication (Stateful)

In traditional stateful architecture, the server maintains identity state in server memory or a centralized session store (e.g., Redis).

B. Token-based Authentication (Stateless)

In stateless token architecture, identity state is cryptographically signed and encapsulated inside a self-contained token (e.g., JSON Web Token) held by the client.


4. Deep Technical Tradeoff Matrix

Choosing between Stateful Sessions and Stateless Tokens involves critical security and architectural tradeoffs:

DimensionStateful Sessions (Cookies + Server Store)Stateless Tokens (Bearer JWTs)
State LocationCentralized server side (Redis / Database)Distributed client side (LocalStorage / Cookies)
Server OverheadRAM/Storage lookup per requestCryptographic verification (CPU) per request
Revocation CapabilityInstantaneous: Delete key from Redis storeDifficult: Token valid until exp unless revoking via CRL/Redis blacklists
Cross-Site Attack VectorSusceptible to CSRF if missing SameSite flagsSusceptible to XSS token theft if stored in LocalStorage
ScalabilityRequires session replication or centralized fast key-value storeInfinite Horizontal Scale: Microservices verify signatures independently
Payload OverheadTiny cookie footprint (~32 bytes Session ID)Large payload (500+ bytes carrying claims & signatures)
Microservice FitHigh database coupling across servicesDecoupled; microservices consume identity claims natively

[!WARNING] The Stateless Revocation Myth: Purely stateless JWTs cannot be revoked instantly without maintaining state on the backend (such as a Token Revocation List or Redis cache). If immediate session termination is a strict business requirement, pure statelessness must be compromised.


5. Threat Landscape & OWASP Mapping

Flaws in authentication and authorization represent the most critical vulnerabilities in application security today.

┌─────────────────────────────────────────────────────────────────────────────┐
│ IDENTITY THREAT LANDSCAPE MATRIX │
├────────────────────────────────┬────────────────────────────────────────────┤
│ OWASP Category │ Failure Mode & Attack Vector │
├────────────────────────────────┼────────────────────────────────────────────┤
│ A01:2021 - Broken Access │ • BOLA / IDOR (User access to /user/102) │
│ Control │ • BFLA (Regular user hits POST /admin/delete)│
│ │ • Missing CORS / Improper Scope Checking │
├────────────────────────────────┼────────────────────────────────────────────┤
│ A07:2021 - Identification & │ • Credential Stuffing / Password Spraying │
│ Authentication Failures │ • Session Fixation (Reusing pre-login ID) │
│ │ • Weak Password Policy / Lack of MFA │
│ │ • Permissive JWT verification (alg: none) │
└────────────────────────────────┴────────────────────────────────────────────┘

6. Identity Defense-in-Depth Architecture

To build a resilient identity architecture, enforce defense-in-depth across every boundary:

  1. Edge Enforcer (API Gateway): Terminate SSL/TLS, enforce rate limits against brute force, reject malformed HTTP requests, validate TLS client certificates.
  2. Authentication Layer (IdP): Enforce phishing-resistant MFA (WebAuthn/FIDO2), risk-based step-up auth, session timeout policies, and secure cookie attributes.
  3. Authorization Layer (Policy Decision Engine): Decouple authorization logic using Policy-as-Code (OPA), validating context, resource ownership, and tenant isolation on every API request.
  4. Data Layer (Storage & Audit): Store password hashes using memory-hard algorithms (Argon2id), salt every password, and maintain tamper-evident audit logs.
Share this guide