Skip to content

QuizNot attempted

Where to keep tokens

Which setup is the recommended one for a single-page app?
1–4 to choose, Enter to submit
Show answer & explanation

Correct answer:

  • Short-lived access token in memory, refresh token in an HttpOnly; Secure; SameSite cookie
  • A short-lived access token in memory is gone on reload and useless within minutes, and an `HttpOnly
  • Secure
  • SameSite` refresh cookie can't be read by JavaScript at all, so an XSS payload can't exfiltrate either long-term.
  • Not both in localStorage: any script, including XSS, can read localStorage.
  • Not access in localStorage, refresh in memory: exposes one token and loses the other on reload, the worst of both.
  • Not a long-lived JS-readable cookie: readable by XSS and valid for a long time.