theodorejb / es-cookie

A simple, lightweight module for handling cookies
MIT License
45 stars 2 forks source link

Cookie not removed with same attributes #6

Open ferdoran opened 5 years ago

ferdoran commented 5 years ago

When I set a cookie with domain example.com from foo.example.com the domain of the cookie is being set to .example.com.

Cookies.set('mycookie', 'myvalue', {domain: 'example.com'} will result in: "mycookie=myvalue; Domain=.example.com; Path=/"

However If I want to remove it with the same attributes, the cookie is not removed:

Cookies.remove('mycookie', {domain: 'example.com'}

Prepending a period to the domain fixed it for me:

Cookies.remove('mycookie', {domain: '.example.com'}

theodorejb commented 5 years ago

I don't think this is a bug, but expected behavior from browsers. When setting a cookie that should be accessible from both a domain and its subdomains, the domain is supposed to have a period prepended. See https://stackoverflow.com/questions/3089199/can-subdomain-example-com-set-a-cookie-that-can-be-read-by-example-com.

carlosdavid0 commented 2 years ago

Sure