Cookie meaning, in plain words

A cookie is a small record, such as a login state, kept in the browser. What RFC 6265 and OWASP say about Secure, HttpOnly and SameSite, and their limits.

Written by: Mio Kanzaki(Security Analyst (AI))Reviewed by: 千葉圭介Updated

A cookie is a small record, such as a login state, saved in the browser. The IETF's RFC 6265 defines two headers, Set-Cookie and Cookie, as the mechanism by which a server entrusts a record to the browser and gets it returned on the next communication.

How does a cookie work?

Think of a cloakroom tag. The shop keeps your belongings, and you hold only a numbered tag. When you come back and show the tag, the shop knows whose belongings they are. A cookie is that tag.

Web communication, as it is, does not remember the previous exchange. The overview of RFC 6265 says that with cookies a server can keep a continuing state even on top of stateless communication. A screen that stays logged in, and the contents of a cart, continue by this mechanism.

The server entrusts a pair of a name and a value, with attached information such as the expiry and the range to send to. Attributes include Secure and HttpOnly. Cases where management of the logged-in state goes wrong are gathered in session management flaws. To have the cookies on your site reviewed, contact us.

Why does a cookie matter?

If a cookie that holds the logged-in state is stolen, someone may impersonate the owner. What protects it is the setting of the attributes. Their functions, in the explanations of the RFC and OWASP, can be set out like this.

  • Secure: the browser sends the cookie only over an encrypted channel. OWASP says it is required for cookies that show a logged-in state.
  • HttpOnly: makes the cookie unreadable by scripts on the screen. RFC 6265 explains it as a setting so that it is not handed to mechanisms such as scripts.
  • SameSite: makes it harder to attach the cookie to requests sent from other sites. OWASP says to prefer Strict and use Lax next.
  • Expiry: decides how long the entrusted cookie stays.

Even with Secure, what is protected is the side of snooping. RFC 6265 cautions that Secure protects only the confidentiality of the cookie and does not prevent an attacker in the middle of the communication from overwriting it. For HttpOnly too, OWASP says it only prevents reading and does not prevent operations that abuse the screen.

Do not put personal information in the value that shows the logged-in state. OWASP asks that a session ID contain no sensitive information.

Related terms

  • Session: the series of usage from login to the end
  • Session timeout: a mechanism that logs out automatically after a period without activity
  • CSRF: an attack that makes a logged-in user perform an unintended operation
  • HSTS: a mechanism that tells the browser to use only encrypted communication

Frequently asked questions

Is a cookie dangerous?

The mechanism itself is not dangerous. RFC 6265 describes cookies as a means of keeping a continuing state on top of stateless communication. What is tested is how they are handled. Settings such as Secure, HttpOnly, and SameSite make them harder to steal.

Is it enough to add the Secure attribute?

No. RFC 6265 says Secure protects only the confidentiality of the cookie, and an attacker in the middle of the communication may still overwrite it. Use it together with other settings such as HttpOnly and SameSite.

Next step

A way in to reviewing the management of logged-in state is session management flaws. The free URL check shows only what is visible from outside, such as how cookies are set, and for a review of your settings, contact us.

Frequently asked questions

Is a cookie dangerous?

The mechanism itself is not dangerous. RFC 6265 describes cookies as a means of keeping a continuing state on top of stateless communication. What is tested is how they are handled. Settings such as Secure, HttpOnly, and SameSite make them harder to steal.

Is it enough to add the Secure attribute?

No. RFC 6265 says Secure protects only the confidentiality of the cookie, and an attacker in the middle of the communication may still overwrite it. Use it together with other settings such as HttpOnly and SameSite.

See what an attacker can see, today

The free URL check returns a grade in under a minute. For costs and next steps, book a free consultation.