The real document.cookie: write HttpOnly from a script, SameSite=None without Secure, a 5000-byte note, or a delete without the Path, then see what the…
Why it matters
A token in localStorage can be stolen by XSS. Forgetting SameSite opens CSRF. Forgetting Secure leaks the cookie over HTTP. A big cookie weighs down every request. Cookie attribute mistakes are real security and performance holes.
The key idea
A cookie’s attributes, not its value, decide whether it is safe or leaks
Common mistakes
Keeping a session token in localStorage Any script on the page, one injected by XSS included, can read it. Let the server set an HttpOnly; Secure; SameSite=Lax cookie, which JavaScript cannot read.
SameSite=None without Secure The browser refuses the cookie. None always goes with Secure.
Putting big data in a cookie The limit is 4096 bytes per cookie, and every matching cookie rides along on every request. Big client data belongs in localStorage or IndexedDB.
Try it in this playground
Write an HttpOnly cookie from a script The browser ignores it entirely: only the server may.
Write SameSite=None without Secure See whether this browser keeps it.
Write a 5000-byte note Over the 4096-byte limit per cookie.
Keep two cookies, then read document.cookie gives every pair, without attributes.