Skip to main content
PProfileMatch
← Path

JWT Authentication · Where to Store a JWT: HttpOnly Cookies vs localStorage Compared

0 XP
  1. 1 current stop: learning
  2. 2 upcoming
  3. 3 upcoming
  4. 4 upcoming
  5. 5 upcoming

Finish after stop 5

Stop 1 of 5 · Browser tab: the loading dock

Trick to keep in mind+3 XP

Cookies ride along by themselves; web storage only moves when your own code carries it.

The browser attaches matching cookies to every request to that site, even ones triggered by a different page, with no JavaScript involved. A token in localStorage, sessionStorage or a variable is sent only when your code adds it to a request. Automatic sending is convenient, and it is also exactly why cookie designs must think about CSRF.

Read it once, then a question tests whether the trick stuck.