Skip to content

QuizNot attempted

localStorage

Why is localStorage a poor place for an auth token?
1–4 to choose, Enter to submit
Show answer & explanation

Correct answer:

  • Any script on the page (including an XSS payload) can read it; an httpOnly cookie cannot be read by JS
  • localStorage is fully readable by any script on the origin, so a single XSS payload can exfiltrate the token
  • an HttpOnly cookie can't be read by JS at all.
  • Not 'cleared on reload': it persists until removed (that is sessionStorage's tab scope, and even that survives reloads).
  • Not 1KB: about 5MB per origin.
  • Not 'sent with every request': that is cookies
  • localStorage is never sent automatically.