Skip to main content
green gradient background, "The Future of Application Security Is Already Here." and a read the report button.
Category: Tracking Technologies

Secure Cookies

Also known as: Secure Cookie Flag, Secure Cookie Attribute, Secure Attribute
Simply put

A secure cookie is a browser cookie that carries a special setting, called the Secure attribute, telling the browser to send it only over encrypted HTTPS connections. This helps prevent the cookie from being read by unauthorized parties if it were sent as plain, unencrypted text. It is a technical safeguard for how a cookie travels between the browser and the server, and is separate from questions of whether the cookie itself is permitted or requires consent.

Formal definition

A secure cookie is an HTTP cookie that has the Secure attribute set, which limits the scope of the cookie to encrypted channels. When the attribute is present, a compliant browser transmits the cookie to the server only over HTTPS and does not include it in requests sent over unencrypted (HTTP) connections, reducing the risk of interception in transit. The Secure attribute is a transport-layer confidentiality control and is typically applied alongside related attributes such as HttpOnly and SameSite, which address different threats. It governs only how a cookie is transmitted and does not, on its own, address whether placing or reading the cookie is lawful or requires user consent under applicable frameworks such as the ePrivacy rules or the GDPR; those obligations must be assessed separately and are out of scope for this definition.

Why it matters

Cookies frequently carry session identifiers, authentication tokens, and other values that, if intercepted, could allow an unauthorized party to impersonate a user or gain access to an account. When a cookie is transmitted over an unencrypted HTTP connection, its contents travel as plain text and can, in principle, be observed by parties positioned on the network path. The Secure attribute mitigates this specific risk by instructing compliant browsers to send the cookie only over encrypted HTTPS connections, so it is not exposed on unsecured channels. For teams responsible for the confidentiality and integrity of user sessions, applying this attribute is a foundational technical control.

Who it's relevant to

Web Developers and Engineers
Developers are generally responsible for setting cookie attributes when their applications issue cookies. Applying the Secure attribute, typically alongside related attributes such as HttpOnly and SameSite that address different threats, is a practical part of hardening session and authentication cookies against interception.
Security and Application Security Teams
Security teams assessing an application's handling of cookies may treat the presence of the Secure attribute as a baseline transport-layer confidentiality control. It reduces the risk of cookies being observed in clear text, though it addresses only how a cookie is transmitted and does not, on its own, resolve other cookie-related risks.
Privacy and Compliance Professionals
The Secure attribute is a technical safeguard for how a cookie travels between browser and server. It does not, by itself, determine whether placing or reading a cookie is lawful or requires consent under frameworks such as the ePrivacy rules or the GDPR; those obligations must be assessed separately and are out of scope for this attribute. Compliance professionals should be careful not to treat a technical control such as this as a substitute for that separate legal analysis.

Inside Secure Cookies

Secure attribute
A flag set on an HTTP cookie that instructs the browser to transmit the cookie only over encrypted HTTPS connections, preventing it from being sent in cleartext over ordinary HTTP where it could be intercepted.
Transport-layer protection
Secure cookies rely on TLS/HTTPS for confidentiality in transit; the attribute governs when a cookie is sent, not how its contents are stored or encrypted at rest.
Relationship to other cookie attributes
The Secure attribute is commonly combined with HttpOnly (which restricts access from client-side scripts) and SameSite (which limits cross-site sending) to reduce different classes of risk. These attributes address distinct threats and are not interchangeable.
Applicability across cookie categories
The Secure attribute is a technical control that can be applied to any cookie regardless of purpose, including strictly necessary, functional, analytics, or advertising cookies. Setting it does not change a cookie's consent classification under applicable law.
Security measure, not consent mechanism
Secure cookies relate to safeguarding data, which may support security and data-protection obligations, but they do not obtain, record, or represent user consent for placing or accessing information on a device.

Common questions

Answers to the questions practitioners most commonly ask about Secure Cookies.

Does setting the Secure attribute on a cookie make it compliant with cookie consent laws?
No. The Secure attribute is a technical safeguard that instructs the browser to transmit a cookie only over encrypted HTTPS connections; it addresses the confidentiality of the cookie in transit, not the lawfulness of placing or reading it. Consent obligations arise separately. In most EU and UK contexts, the ePrivacy rules govern whether you may store or access information on a user's device, and the GDPR governs any subsequent processing of personal data. A cookie can carry the Secure attribute and still require prior consent if it is not strictly necessary. Conversely, a strictly necessary cookie may be exempt from consent regardless of whether it is marked Secure. The two questions, technical protection and legal basis, should be assessed independently.
Does the Secure attribute mean the cookie's contents are encrypted or protected from all tampering?
Not on its own. The Secure attribute controls the transport channel, causing the cookie to be sent only over HTTPS rather than in cleartext over HTTP. It does not encrypt the cookie value itself, nor does it prevent client-side access or modification. Protecting cookie contents from script access typically involves the separate HttpOnly attribute, and mitigating cross-site request risks often involves the SameSite attribute; encrypting or signing the value is a further application-level measure. Treating Secure as a comprehensive protection is a misreading of its narrow purpose.
How is the Secure attribute typically applied to a cookie?
The Secure attribute is generally added to the Set-Cookie response header (for example, appending Secure alongside the cookie name, value, and any Path, Domain, HttpOnly, or SameSite attributes). Many web frameworks and server configurations expose a setting to mark cookies as secure, and consent management platforms and tag managers may set it on the cookies they control. The exact mechanism depends on your server stack, so consult your framework's documentation. This entry describes the general concept rather than any specific implementation.
Should the Secure attribute be used together with HttpOnly and SameSite?
These attributes address distinct concerns and are commonly used in combination as part of a layered approach to cookie handling. Secure restricts transmission to HTTPS, HttpOnly generally limits access from client-side scripts, and SameSite influences whether a cookie is sent with cross-site requests. Which combination is appropriate depends on the cookie's function, for example, a cookie used across contexts may need different SameSite handling than a session cookie. The suitable configuration is a technical and risk decision specific to your application, and these attributes support security objectives but do not by themselves resolve consent or lawfulness requirements.
Can the Secure attribute be used on cookies served over localhost or non-HTTPS development environments?
Behavior varies by browser and configuration. Because the Secure attribute restricts a cookie to secure connections, cookies marked Secure are generally not sent or accepted over plain HTTP, which can affect local or non-HTTPS development environments. Some browsers apply special handling for localhost. Because these behaviors differ between browsers and change over time, verify against current browser documentation for your target environments rather than assuming uniform behavior.
Does marking consent-related cookies as Secure help with record-keeping or demonstrating compliance?
Applying appropriate technical attributes such as Secure can form part of demonstrating that you have implemented suitable technical measures for cookie handling, which may be relevant to accountability expectations under the GDPR in EU and UK contexts. However, the Secure attribute does not constitute a consent record, and it does not replace separate consent logging or record-keeping practices. Whether your overall approach meets applicable obligations depends on facts beyond this attribute and should be assessed with reference to current guidance and, where appropriate, legal advice.

Common misconceptions

Marking a cookie as Secure makes it compliant with cookie consent law.
The Secure attribute is purely a technical safeguard governing transmission over HTTPS. Consent obligations for placing or accessing cookies arise separately under the ePrivacy rules and national implementations in the EU and UK, and processing of any resulting personal data is governed by the GDPR. A Secure attribute neither triggers nor satisfies these consent requirements.
The Secure attribute encrypts the contents of the cookie.
The attribute does not encrypt the cookie value itself. It only ensures the browser sends the cookie over an encrypted HTTPS connection. Protecting the stored value, or the data it references, generally requires additional measures.
Secure and HttpOnly do the same thing, so setting one is enough.
They address different risks. Secure controls whether a cookie is sent over encrypted connections, while HttpOnly restricts access to the cookie from client-side scripts. SameSite addresses cross-site sending. These are complementary and typically used together rather than as substitutes.

Best practices

Serve your site over HTTPS and apply the Secure attribute to cookies so they are not transmitted over unencrypted HTTP, reducing the risk of interception in transit.
Combine Secure with HttpOnly and an appropriate SameSite setting where suitable, since each attribute mitigates a distinct type of risk rather than replacing the others.
Treat the Secure attribute as a security and data-protection safeguard that is separate from consent; continue to obtain and record consent for non-exempt cookies as required in the relevant jurisdiction, such as the EU and UK.
Do not rely on cookie attributes to determine consent classification; assess each cookie's purpose (for example strictly necessary, functional, analytics, or advertising) separately when deciding whether prior consent is generally required.
Consider additional protections for sensitive cookie contents, as the Secure attribute governs transmission but does not itself encrypt the stored value.
Document your cookie security configuration alongside your consent records, and seek legal review where obligations vary by jurisdiction or where enforcement guidance is unsettled, recognizing that technical controls support but do not guarantee compliance.
Promotional banner highlighting failures found in PCI audits and how to spot the gaps