HttpOnly
A cookie attribute that stops scripts running in the page from reading the cookie, while the browser still sends it on requests.
Without it, any script injected into the page can steal the session.
In more detail
It limits the damage of cross-site scripting: injected code cannot simply copy the session cookie and send it elsewhere. Set it on every session cookie.
Example
In the browser: Session cookies should be HttpOnly so an XSS attack cannot steal them with document.cookie. The browser still sends them with requests.Related terms
- cookie — A small named value a server asks a browser to store and send back automatically on later matching requests.
- cross-site scripting — An attack where hostile script is injected into a trusted web page and runs with that page’s access, for example to read data or cookies.
- session — A record the server keeps about a logged-in caller, found on each request through a handle the client presents, usually in a cookie.
- Secure attribute — A cookie attribute that tells the browser to send the cookie only over encrypted HTTPS connections.
- cross-site scripting — An attack in which someone gets their own script to run inside your page, where it can read data, act as the user or steal tokens.
- localStorage — A browser feature that saves small text values for a website so they are still there after the page is closed and reopened.
- session cookie — The cookie that proves a user is signed in, carrying a session ID or a signed or encrypted token.
Taught in
- Cookies And CORS — Modern API Architecture: REST, GraphQL & gRPC
- Basic Auth, Tokens And Sessions — Modern API Architecture: REST, GraphQL & gRPC
- Client Storage Paradigms: Cookies, Storage Tradeoffs — Frontend Architecture & Web Platform
- Session Architecture: HTTP-Only Cookies vs Tokens — Production Full-Stack Engineering
- Session Management: Secure Cookies & Token Validation — Next.js 15 & Modern App Router Architecture
- Secure Defaults — Application Security & Threat Modeling for Engineers