Home > Software design >  Subdomain preserves cookies from main domain
Subdomain preserves cookies from main domain

Time:08-09

I've set a cookie banner for a domain.com. It's a plugin for CMS. It works with user consent - blocking or giving permission to load a GTM script.

And I have an e-shop based on PrestaShop with a cookie banner plugin, which works with the same logic.

e-shop is placed on a subdomain.domain.com.

The problem: once a user grants consent on domain.com GTM cookies are loaded, the user clicks on a button leading to subdomain.domain.com (e-shop) and all previous cookies are loaded. What is not a good behaviour for a GDPR

So, is there an easy way to clear previous cookies?

Prestashop runs on Apache server

CodePudding user response:

From MDN:

Domain attribute

The Domain attribute specifies which hosts can receive a cookie. If unspecified, the attribute defaults to the same host that set the cookie, excluding subdomains. If Domain is specified, then subdomains are always included. Therefore, specifying Domain is less restrictive than omitting it. However, it can be helpful when subdomains need to share information about a user.

When setting your cookies, omit the Domain attribute.

This will prevent future cookies being applied to the subdomains (and will overwrite the old ones which were on the next visit which sets them).

  • Related