Authentication · interview question
How would you explain a significant risk of storing a JWT in localStorage in a browser context in an interview?
Multiple choiceHardchapter-17-curatedpremiumauthenticationjwt-signatures
Answer and explanation
Correct answer
D. It is prone to XSS attacks.
Why
Storing JWTs in localStorage exposes them to XSS attacks, where a malicious script could access and misuse the token. Secure storage options like HttpOnly cookies can mitigate this risk.
Test yourself on Authentication
A free test with instant, explained results. No account needed.
More Authentication questions
- In the context of JWT, what is the primary purpose of the signature?
- How can a Java developer verify the signature of a JWT using HMAC SHA-256?
- How would you explain a significant consequence of using stateless JWT tokens for authentication in an interview?
- Which statement about JWT payloads is correct?
- Which statement best describes the use of CSRF tokens in web applications?
- Why is using BCrypt preferable over a fast hashing algorithm like SHA-256 for password hashing?