Skip to content

Commit e2558cb

Browse files
authored
domain cookie option
1 parent 7b76185 commit e2558cb

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

6-data-storage/01-cookie/article.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,13 @@ Usually, we should set `path` to the root: `path=/` to make the cookie accessibl
9696

9797
A domain defines where the cookie is accessible. In practice though, there are limitations. We can't set any domain.
9898

99-
By default, a cookie is accessible only at the domain that set it. So, if the cookie was set by `site.com`, we won't get it at `other.com`.
99+
**There's no way to let a cookie be accessible from another domain, so `other.com` will never receive a cookie set at `site.com`.**
100100

101-
...But what's more tricky, we also won't get the cookie at a subdomain `forum.site.com`!
101+
It's a safety restriction, to allow us to store sensitive data in cookies, that should be available only on one site.
102+
103+
By default, a cookie is accessible only at the domain level that set it.
104+
105+
...What's tricky, we won't get the cookie at a subdomain `forum.site.com`!
102106

103107
```js
104108
// at site.com
@@ -108,10 +112,6 @@ document.cookie = "user=John"
108112
alert(document.cookie); // no user
109113
```
110114

111-
**There's no way to let a cookie be accessible from another 2nd-level domain, so `other.com` will never receive a cookie set at `site.com`.**
112-
113-
It's a safety restriction, to allow us to store sensitive data in cookies, that should be available only on one site.
114-
115115
...But if we'd like to allow subdomains like `forum.site.com` to get a cookie, that's possible. When setting a cookie at `site.com`, we should explicitly set the `domain` option to the root domain: `domain=site.com`:
116116

117117
```js

0 commit comments

Comments
 (0)