cookie
A small named value a server asks a browser to store and send back automatically on later matching requests.
In more detail
The server creates one with Set-Cookie and the browser returns it in the Cookie header. A session cookie normally holds only a handle; the server looks it up to find the session. Attributes such as HttpOnly, Secure and SameSite limit where and when the browser sends it.
Example
In the browser: Cookies are how most sites remember that you are logged in. Because they travel with every request they cost bandwidth, and because they are sent automatically they enable cross-site request forgery unless protected with SameSite. Attributes such as HttpOnly and Secure limit who can read them.Related terms
- Set-Cookie — The response header a server uses to ask the browser to store a cookie, together with attributes that limit where it is sent.
- 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.
- HttpOnly — A cookie attribute that stops scripts running in the page from reading the cookie, while the browser still sends it on requests.
- Secure attribute — A cookie attribute that tells the browser to send the cookie only over encrypted HTTPS connections.
- SameSite — A cookie attribute that limits whether the browser sends the cookie on requests started by other websites.
- cross-site request forgery — An attack where another website makes the victim's browser send a request to your site, and the browser's cookie makes it look genuine.
- __Host- prefix — A cookie name prefix that the browser only accepts if the cookie is Secure, has Path=/ and names no domain, so subdomains cannot overwrite it.
- cookies() — The async function from next/headers that reads the request's cookies, and in Server Actions or Route Handlers can also set or delete them.
Taught in
- Cookies And CORS — Modern API Architecture: REST, GraphQL & gRPC
- The REST Constraints — Modern API Architecture: REST, GraphQL & gRPC
- Basic Auth, Tokens And Sessions — Modern API Architecture: REST, GraphQL & gRPC
- Software Composition Analysis with Trivy — Cloud Security & DevSecOps Engineering
- Client Storage Paradigms: Cookies, Storage Tradeoffs — Frontend Architecture & Web Platform
- Same-Origin Policy, CORS Preflight, Credentials And Headers — Frontend Architecture & Web Platform
- CSRF Mitigations, SameSite Cookies And Subresource Integrity — Frontend Architecture & Web Platform
- Type-Safe RPC Architectures: tRPC & Procedures — Production Full-Stack Engineering
- Session Architecture: HTTP-Only Cookies vs Tokens — Production Full-Stack Engineering
- OAuth2 & OpenID Connect: Social Auth & PKCE Flows — Production Full-Stack Engineering
- Full Route Cache: Static Rendering & Segment Config — Next.js 15 & Modern App Router Architecture
- Route Handlers: RESTful Endpoints with NextRequest — Next.js 15 & Modern App Router Architecture
- Edge Middleware: Auth Verification & Route Matchers — Next.js 15 & Modern App Router Architecture
- Session Management: Secure Cookies & Token Validation — Next.js 15 & Modern App Router Architecture
- Authentication Versus Authorisation — Application Security & Threat Modeling for Engineers
- Secure Defaults — Application Security & Threat Modeling for Engineers
- Cross-Site Request Forgery — Application Security & Threat Modeling for Engineers