Skip to content

Commit cd0ac3a

Browse files
Mention how to immediately remove cookies (#41354)
* Mention how to immediately remove cookies * Update files/en-us/web/http/guides/cookies/index.md Co-authored-by: Hamish Willee <[email protected]> * Update files/en-us/web/http/guides/cookies/index.md --------- Co-authored-by: Hamish Willee <[email protected]>
1 parent 8a258b0 commit cd0ac3a

File tree

1 file changed

+13
-0
lines changed
  • files/en-us/web/http/guides/cookies

1 file changed

+13
-0
lines changed

files/en-us/web/http/guides/cookies/index.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,19 @@ You can specify an expiration date or time period after which the cookie should
9292
> [!NOTE]
9393
> If your site authenticates users, it should regenerate and resend session cookies, even ones that already exist, whenever a user authenticates. This approach helps prevent [session fixation](https://owasp.org/www-community/attacks/Session_fixation) attacks, where a third-party can reuse a user's session.
9494
95+
To immediately remove a cookie, set the cookie again with the same name, path, and domain (if specified), and set its `Expires` attribute to a date in the past or its `Max-Age` attribute to `0` or negative. This instructs the browser to delete the cookie right away. For example:
96+
97+
```http
98+
Set-Cookie: id=a3fWa; Max-Age=0
99+
```
100+
101+
You can also clear all cookies associated with a registrable domain using the {{httpheader("Clear-Site-Data")}} response header.
102+
For example, the following header sent from `https://foo.example.com/` would clear all cookies sent by `example.com` and all of its subdomains, such as `all.bar.example.com`.
103+
104+
```http
105+
Clear-Site-Data: "cookies"
106+
```
107+
95108
There are some techniques designed to recreate cookies after they're deleted. These are known as "zombie" cookies. These techniques violate the principles of user [privacy](#privacy_and_tracking) and control, may violate [data privacy regulations](#cookie-related_regulations), and could expose a website using them to legal liability.
96109

97110
### Updating cookie values

0 commit comments

Comments
 (0)