tadata
Back to home

API Security: Patterns for Authentication, Authorization, and Defense in Depth

#security#api#architecture#authentication

APIs are the attack surface of the modern organization. Every exposed endpoint is a potential entry point for unauthorized access, data exfiltration, or service disruption. Yet API security is often an afterthought -- bolted on after the fact rather than designed in from the start. This post maps the essential security layers, compares authentication methods, catalogs the OWASP API Top 10, and provides a tool landscape for implementation.

Security Layer Architecture

┌─────────────────────────────────────────────────────────┐
│                    CLIENT REQUEST                        │
└────────────────────────┬────────────────────────────────┘
                         ▼
┌─────────────────────────────────────────────────────────┐
│  LAYER 1: NETWORK / EDGE                                │
│  ┌─────────┐ ┌──────────┐ ┌───────────┐ ┌───────────┐  │
│  │ WAF     │ │ DDoS     │ │ TLS       │ │ IP Allow  │  │
│  │         │ │ Protect  │ │ Termination│ │ List      │  │
│  └─────────┘ └──────────┘ └───────────┘ └───────────┘  │
└────────────────────────┬────────────────────────────────┘
                         ▼
┌─────────────────────────────────────────────────────────┐
│  LAYER 2: API GATEWAY                                   │
│  ┌─────────┐ ┌──────────┐ ┌───────────┐ ┌───────────┐  │
│  │ Rate    │ │ Auth     │ │ Request   │ │ API Key   │  │
│  │ Limiting│ │ (JWT/    │ │ Validation│ │ Mgmt      │  │
│  │         │ │  OAuth)  │ │           │ │           │  │
│  └─────────┘ └──────────┘ └───────────┘ └───────────┘  │
└────────────────────────┬────────────────────────────────┘
                         ▼
┌─────────────────────────────────────────────────────────┐
│  LAYER 3: APPLICATION                                   │
│  ┌─────────┐ ┌──────────┐ ┌───────────┐ ┌───────────┐  │
│  │ Input   │ │ AuthZ    │ │ Business  │ │ Output    │  │
│  │ Valid.  │ │ (RBAC/   │ │ Logic     │ │ Filtering │  │
│  │         │ │  ABAC)   │ │ Checks    │ │           │  │
│  └─────────┘ └──────────┘ └───────────┘ └───────────┘  │
└────────────────────────┬────────────────────────────────┘
                         ▼
┌─────────────────────────────────────────────────────────┐
│  LAYER 4: DATA                                          │
│  ┌─────────┐ ┌──────────┐ ┌───────────┐ ┌───────────┐  │
│  │ Encrypt │ │ Column   │ │ Audit     │ │ Data      │  │
│  │ at Rest │ │ Masking  │ │ Logging   │ │ Classif.  │  │
│  └─────────┘ └──────────┘ └───────────┘ └───────────┘  │
└─────────────────────────────────────────────────────────┘

Authentication Method Comparison

MethodSecurity LevelComplexityUse CaseRevocabilityScalability
API KeyLowLowServer-to-server, internalPer-key revocationHigh
OAuth 2.0 + OIDCHighHighUser-facing apps, delegated accessToken expiry + revocationHigh
JWT (self-contained)Medium-HighMediumMicroservices, stateless authHard (until expiry)Very high
mTLSVery HighVery HighService mesh, zero-trustCertificate revocation (CRL/OCSP)Medium
HMAC SignaturesHighMediumWebhooks, request integrityPer-key revocationHigh
Session CookiesMediumLowTraditional web appsServer-side invalidationMedium

When to Use What

Decision Tree: Authentication Method
│
├── Machine-to-machine, internal?
│   ├── Zero-trust environment? → mTLS
│   ├── Need request integrity? → HMAC Signatures
│   └── Simple internal call? → API Key + network restriction
│
├── User-facing application?
│   ├── Third-party access delegation? → OAuth 2.0
│   ├── Single-page app / mobile? → OAuth 2.0 + PKCE
│   └── Traditional server-rendered? → Session Cookies
│
└── Microservice-to-microservice?
    ├── Service mesh in place? → mTLS (Istio/Linkerd)
    └── No mesh? → JWT with short expiry + rotation

OWASP API Security Top 10 (2023)

RankRiskDescriptionMitigation
API1Broken Object Level AuthorizationAccessing other users' data via ID manipulationEnforce authorization checks per object, not just endpoint
API2Broken AuthenticationWeak auth mechanisms or implementation flawsUse proven auth libraries, enforce MFA, rate-limit login
API3Broken Object Property Level AuthorizationMass assignment, exposing internal fieldsExplicit allowlists for input/output fields
API4Unrestricted Resource ConsumptionNo limits on request size, rate, or paginationRate limiting, pagination caps, request size limits
API5Broken Function Level AuthorizationAccessing admin endpoints without admin roleRBAC enforcement at function/endpoint level
API6Unrestricted Access to Sensitive Business FlowsAutomated abuse of business logic (scalping, spam)Bot detection, CAPTCHA, business-logic rate limits
API7Server Side Request Forgery (SSRF)API fetches attacker-controlled URLsURL allowlisting, disable redirects, network segmentation
API8Security MisconfigurationDefault configs, verbose errors, missing headersSecurity hardening checklists, automated scanning
API9Improper Inventory ManagementShadow APIs, undocumented endpointsAPI discovery scanning, OpenAPI spec enforcement
API10Unsafe Consumption of APIsTrusting third-party API responses without validationValidate all external inputs, use timeouts and circuit breakers

Rate Limiting Strategy Matrix

StrategyHow It WorksProsConsBest For
Fixed WindowN requests per time windowSimple to implementBurst at window edgesLow-traffic APIs
Sliding WindowRolling count over time periodSmoother distributionMore memory/computeGeneral purpose
Token BucketTokens replenish at fixed rateAllows controlled burstsSlightly complexAPIs with bursty traffic
Leaky BucketRequests processed at fixed ratePerfectly smooth outputNo burst toleranceStrict throughput control
AdaptiveLimits adjust based on loadResilient to traffic spikesComplex to tuneHigh-scale production

Tool Comparison

CategoryToolTypeStrengthsBest For
API GatewayKongOSS + EnterprisePlugin ecosystem, Lua extensibilityMulti-protocol APIs
API GatewayAWS API GatewayManagedNative AWS integrationAWS-native architectures
API GatewayEnvoy / IstioOSSService mesh, mTLS nativeKubernetes environments
Auth ProviderAuth0 / OktaSaaSFast integration, social loginUser-facing applications
Auth ProviderKeycloakOSSFull OIDC/SAML, self-hostedOn-prem or privacy-sensitive
WAFAWS WAFManagedCloudFront integrationAWS workloads
WAFCloudflare WAFSaaSGlobal edge, easy setupWeb-facing APIs
ScanningOWASP ZAPOSSFree, CI/CD integrationDevelopment/testing
ScanningBurp SuiteCommercialDeep manual testingSecurity teams
API DiscoveryApiiro / TraceableSaaSRuntime API discoveryShadow API detection

Resources