First-party cookie demo
A Set-Cookie
header is included with the response to the request for both the image and the iframe on this page:
- Image: 1pc.glitch.me/images/kittens.jpg
Response header:Set-Cookie: session=123; Max-Age=86400; Secure; HTTPOnly
This header has noPath
attribute, so the cookie will only be included with requests to the/images
directory. - Iframe: 1pc.glitch.me/iframe/index.html
Response header:Set-Cookie: iframe-seen=true; Path=/; Secure; HTTPOnly
This header has aPath=/
attribute, so the cookie will be included with requests to this site. NoMax-Age
orExpires
attribute is set, so this cookie will be deleted at the end of the browser session.
See how it works
- Open the Chrome DevTools Network panel
- Click on
index.html
(from the iframe) orkittens.jpg
- In the Headers tab, view
Set-Cookie
in the Response Headers. - The first time you open the page, no cookies have been set yet, so there won't be a
Cookie
entry in the Request Headers. - Subsequent requests will include
Cookie
headers. A request for the image will include both thesession=123
andiframe-seen=true
cookies. Other requests will only includeiframe-seen=true
. - You can also view cookies from the Application panel. Try Ctrl-Alt-click to clear cookies, and then reopen the page.
You can view the backend Node code that sets the cookies in server.js.