Level 1: Bronze
A memorized definition. Not wrong, but it stops there.
Cookies are stored in the browser and sessions are stored on the server.
2 stars Asked often.
In one or two sentences
A cookie is a small value the browser stores and sends with requests. A session keeps login state on the server. A token proves identity with a signed value, so the server keeps no state.
Say it out loud, or type it below. What you type never leaves this device.
A memorized definition. Not wrong, but it stops there.
Cookies are stored in the browser and sessions are stored on the server.
Correct, but too broad or missing context.
With sessions the server stores the login state and the cookie holds only a session ID. With tokens the client holds a signed value and sends it on each request.
Reaches principle, use and trade-off, with words that invite the next question.
Sessions keep state on the server, so invalidating one is easy, but several servers must share the store. A signed token is verified without server state, which scales easily, but it is hard to revoke once issued, so you keep expiry short and add a refresh token. When it travels in a cookie, HttpOnly blocks script access and reduces theft through XSS, and SameSite reduces CSRF. Putting it in local storage lets scripts read it, which is risky. The trade is instant revocation against scalability.
These are likely next questions from an interviewer. Think of your answer first, then press the button.
1 / 3
How do XSS and CSRF differ?
XSS runs an attacker's script inside the victim's page. CSRF makes a logged in victim's browser send a request the attacker built.
2 / 3
How do you revoke a token?
Keep expiry short and keep a deny list or store refresh tokens on the server. The server then holds some state again.
3 / 3
What does the SameSite attribute do?
It decides whether the cookie is attached to requests that start on another site, which reduces CSRF.