Skip to content

Cookies with duplicated name

Klaus Hartl edited this page May 29, 2023 · 2 revisions

Test http server:

// server.mjs
import http from 'http'

const host = 'localhost'
const port = 3000

http
  .createServer((req, res) => {
    if (req.url.endsWith('/test')) {
      res.setHeader('Set-Cookie', 'foo=nested; Path=/test')
    } else {
      res.setHeader('Set-Cookie', 'foo=top; Path=/')
    }
    res.writeHead(200)
    res.end('<p><a href="/test">Go to /test</a></p>')
  })
  .listen(port, host, () => {
    console.log(`Server is running on http://${host}:${port}`)
  })

In the browser visit /, and /test.

Cookie string:

Browser document.cookie
Firefox 109.0.1 foo=nested; foo=top
Chrome 113.0.5672.126 foo=nested; foo=top
Safari 16.4 foo=nested; foo=top