Where the Credential Lives — XSS and CSRF — Concept Check
Questions on Where the Credential Lives — XSS and CSRF. localStorage is exposed to any script on the page; a cookie is sent automatically by any site. Each storage choice picks which attack you have to defend against.
Questions in this quiz
8 questions on Where the Credential Lives — XSS and CSRF — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A developer stores a JWT in localStorage for an application. What is the primary security risk?
- ACSRF can exploit the token in localStorage.
- BXSS can steal the token from localStorage.
- CThe token expires too quickly.
- DThe token is not sent with requests automatically.
2.Which storage method is immune to CSRF but vulnerable to XSS?
- AsessionStorage
- BlocalStorage
- CIn-memory storage
- DhttpOnly cookies
3.A site uses httpOnly cookies for session management. Which attack does this primarily defend against?
- ACSRF attacks on state-changing requests
- BXSS exfiltrating the token
- CSession fixation attacks
- DToken replay attacks
4.What is a potential issue when using SameSite=Lax cookies for authentication?
- AThey are vulnerable to XSS.
- BThey require HTTPS to function.
- CThey are not sent on cross-site POST requests.
- DThey cannot be read by JavaScript.
5.A team uses in-memory storage for tokens. What is the main drawback of this approach?
- ATokens persist across tabs.
- BTokens are lost on page refresh.
- CTokens can be read by other sites.
- DTokens are vulnerable to CSRF.
6.Why might a developer choose sessionStorage over localStorage for storing tokens?
- AsessionStorage is immune to XSS.
- BsessionStorage automatically sends tokens with requests.
- CsessionStorage supports httpOnly attributes.
- DsessionStorage clears tokens on tab close.
7.A developer sets a cookie with 'SameSite=None' and 'Secure'. What should they be cautious about?
- ACSRF attacks due to cross-site requests.
- BThe cookie not being sent over HTTP.
- CThe cookie expiring too quickly.
- DXSS attacks reading the cookie.
8.What is the primary defense against XSS regardless of storage choice?
- ASetting SameSite=Lax on cookies
- BUsing httpOnly cookies
- CImplementing a strict Content-Security-Policy
- DStoring tokens in sessionStorage