REST Security

A guided, one-scene-at-a-time walkthrough

REST Security WalkthroughResources, requests, and who may touch them0 · StartEvery request stands aloneClientCreate cartAdd itemCheck outState lives in the resource, not the session1 · StatelessHTTPS onlyClientAPImTLS for privileged APIsPasswords, keys and tokens never travel in clear2 · HTTPSAuthenticate centrally, authorize locallyIdPClient/orders/users/adminEvery endpoint checks for itself3 · Access controlTrust the claims, not the headerJWTverifyiss trusted issueraud made for meexp not expirednbf valid now"alg": "none"Pick the algorithm in config, never from the token4 · JWT checksLogout must kill the tokenLogoutjti denylistuntil expold tokenAPIReject it until it expires5 · RevocationKeys manage usagerate limitAPI429Don't guard high-value data with a key alone6 · API keysAllowlist the verbsClientAPIGETPOSTPUTDELETE405Authorize each verb on each record7 · MethodsNo skipping stepsCreatestate: newPaystate: paidConfirmstate: doneskips stepsThe server tracks state, not the frontend8 · WorkflowNever trust the requestRequestvalidateAPIXXE / bad input413 too largeType · length · range · size9 · InputSay what it is, check what it isRequestapplication/jsontext/unknown415 unsupportedResponsematch Accept406 if nothing fits10 · Content typesKeep admin off the InternetInternetPublic APIseparate port / networkAdminMFAFirewall it, then require strong auth11 · ManagementSay little, log a lotAPIClient500 · genericaudit logsanitizeLog auth failures before and after the event12 · Errors & logsTell the browser how to behaveHeadersno-storenosniffHSTSno framingCORSAPItrusted originunknown origin13 · Headers & CORSURLs get logged. Headers don't./pay?apiKey=a53f…server logs/orders/42/paykey in headerKeep credentials out of the address14 · Secrets in URLsSay what really happened200OK201Created400Bad request401Who are you?403Not allowed405Wrong method406Can't match413Too large415Wrong type429Slow down500Generic fail503Try later15 · Status codesChecklist at a glanceHTTPSAccessJWTAPI keysMethodsWorkflowValidateContent typeMgmt portsSafe errorsHeaders+CORSStatus codes16 · Recap

Use Previous / Next, the ← → keys, or Auto-play for a hands-free presentation. Hash links like #5 jump straight to a scene.