# What Are HttpOnly Cookies? A Simple Guide to Secure Sessions

DevFeed: [What Are HttpOnly Cookies? A Simple Guide to Secure Sessions](<https://devfeed.tech/articles/what-are-httponly-cookies-a-simple-guide-to-secure-sessions-130198.md>)

Original publisher: [Read original article](<https://hackernoon.com/what-are-httponly-cookies-a-simple-guide-to-secure-sessions?source=rss>)

Author: Mohsen

Published: 2026-11-12T07:14:02Z

Content type: article

Language: en

Sources: [HackerNoon](<https://devfeed.tech/sources/hackernoon.md>)

Topics: [frontend security](<https://devfeed.tech/topics/frontend-security.md>), [Secure token management](<https://devfeed.tech/topics/secure-token-management.md>), [XSS](<https://devfeed.tech/topics/xss.md>), [LocalStorage](<https://devfeed.tech/topics/localstorage.md>)

Tags: [cookies](<https://devfeed.tech/tags/cookies.md>), [cross-site-scripting](<https://devfeed.tech/tags/cross-site-scripting.md>), [csrf](<https://devfeed.tech/tags/csrf.md>), [express](<https://devfeed.tech/tags/express.md>), [httponly-cookies](<https://devfeed.tech/tags/httponly-cookies.md>), [js](<https://devfeed.tech/tags/js.md>), [next-js](<https://devfeed.tech/tags/next-js.md>), [nextjs](<https://devfeed.tech/tags/nextjs.md>), [security](<https://devfeed.tech/tags/security.md>), [sessions](<https://devfeed.tech/tags/sessions.md>), [theft](<https://devfeed.tech/tags/theft.md>), [web](<https://devfeed.tech/tags/web.md>), [web-application-security](<https://devfeed.tech/tags/web-application-security.md>), [xss](<https://devfeed.tech/tags/xss.md>)

## AI overview

An `HttpOnly` session cookie keeps its value out of JavaScript while the browser still sends it to the server on matching requests. This blocks injected scripts from reading and exfiltrating the token, but does not stop XSS: malicious code running in the page can still make authenticated requests, and HttpOnly does not by itself prevent CSRF. Set the cookie server-side with `Set-Cookie`; client JavaScript cannot create an HttpOnly cookie. The excerpt recommends pairing it with `Secure` and `SameSite`, and notes that sensitive actions may also need a CSRF token. Its Express and Next.js examples differ in `maxAge` units: milliseconds in Express, seconds in Next.js. It also describes `SameSite=Lax` as a common session default and `Strict` as more restrictive, with usability tradeoffs.

## Source excerpt

What the HttpOnly flag does, what it stops (token theft via XSS), what it doesn't, and how to set it in Express and Next.js.