Lably
Skip to content

Secure cookie

Type of HTTP cookie

  • 3 min read
  • 2 chapters

Related on Lably

Through Web browser, JavaScript and Web server

Although seemingly useful for protecting cookies from active network attackers, the Secure attribute protects only the cookie's confidentiality. An active network attacker can overwrite Secure cookies from an insecure channel, disrupting their integrity. This issue is officially referred to as Weak Integrity. However, some browsers, including Chrome 52 and higher and Firefox 52 and higher, forgo this specification in favor of better security and forbid insecure sites (HTTP) from setting cookies with the Secure directive.

Even with Secure, some sources recommend that sensitive information never be stored in cookies, on the premise that they are inherently insecure and this flag can't offer real protection. Secure attribute is not the only protection mechanism for cookies, there are also HttpOnly and SameSite attributes. The HttpOnly attribute restricts the cookie from being accessed by, for instance, JavaScript, while the SameSite attribute only allows the cookie to be sent to the application if the request originated from the same domain.

Background

An HTTP cookie is a small packet of data that is sent from a web server to a user's web browser. There are two types of cookie:

  • Persistent cookies - Cookies that store information in the user's browser for a long time.
  • Non-persistent cookies - Cookies that generally expire when the browser closes.

Cookies could contain sensitive information, such as passwords and credit card numbers, which are sent over an HTTP connection and might be stored in web browsers as plain text. To prevent attackers from stealing this information, cookies can be secured with attributes.

Sign in to keep reading

One more chapter is free with a Lably account.

More in Computing and communication