Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The proper way to use JWTs for API Authorization on the web

The proper way to use JWTs for API Authorization on the web

Using JSON Web Tokens (JWTs) for API Authorization can have awesome benefits over the more traditional session-ids approach: stateless verification/authorization, cross-domain and being client-side readable, but using JWTs on the web can be contentious. There is a lot of concern (and a lot of FUD spread) about using JWTs in web apps, specifically about storing the JWT in localstorage, but luckily there is a better way...

Adam L Barrett

March 15, 2019
Tweet

More Decks by Adam L Barrett

Other Decks in Programming

Transcript

  1. VS

  2. “THE IDEA IS TO REDUCE THE ATTACK SURFACE. A CODE-SPECIFIC

    ATTACK IS GOING TO DO MORE DAMAGE, EXPLOIT MORE HOLES, ETC. BUT A BLANKET ATTACK CAN LOOP OVER 1000 GENERIC SITES LOCALSTORAGE AND EXTRACT EVERYTHING WITHOUT NEEDING TO WRITE ANY CODE” Luke Oliff from Auth0
  3. JSON WEB TOKENS THE REAL BENEFITS OF JWTs ▸ Stateless

    verification/authorization ▸ Client-side readable
  4. JSON WEB TOKENS THE REAL BENEFITS OF NOT USING COOKIES

    ▸ Cross Domain ▸ No Cross-Site Request Forgery (CSRF)
  5. JSON WEB TOKENS THE REAL CONS ▸ inability to revoke

    a users access without revoking everyones access ▸ Easy to misuse (like localstorage)
  6. JSON WEB TOKENS THE REAL BENEFITS OF SESSION COOKIES ▸

    Better defended from blanket XSS ▸ Ability to revoke access ▸ Battle Hardend Assuming `httpOnly`, `secure`, and `sameSite`
  7. JSON WEB TOKENS THE REAL CONS OF SESSION COOKIES ▸

    vulnerable to CSRF
 (sameSite flag mitigates this) ▸ not cross-domain ▸ Not client-side readable ▸ stateful verification
  8. Steps to making your SPA or JAMstack app use JWTs

    for authentication the right way ADAM L BARRETT’S
  9. JSON WEB TOKENS QUICK RECAP ▸ Storing JWTs in localstorage

    is bad ▸ Don’t handle auth yourself, leave it to experts ▸ Only use JWTs if you benefit from ▸ Stateless verification ▸ Client side readability ▸ Recognize and avoid both FUD and Hype