dobarkod / cookie-banner

JavaScript based cookie-info banner for complying with EU cookie law
MIT License
425 stars 85 forks source link

`expires` option doesn't work with Firefox. #89

Closed fabiocaccamo closed 1 year ago

fabiocaccamo commented 1 year ago

Hi, I'm not setting the expires option because the default value Infinity is ok in my case.

I noticed that the cookie-banner shows from time to time after having agreed once, so I decided to set the expires option.

Setting the option I noticed that the expiration date is always one week (I tried to set it using seconds and also explicit Date object).

Initially I though it was a problem of the option, but I tested the same code with Chrome and it works well, so it's a Firefox (v.106) issue.

zytzagoo commented 1 year ago

Hi, sorry for the delay, and sorry to have to say that it's kind of hard to give more concrete info without having/seeing/testing a minimal reproducible example somewhere.

I tried running the tests manually in latest Firefox on osx, nothing breaks there. But this doesn't really prove much (in and of itself).

Maybe we could come up with a test for this exact scenario and add it to the test suite, but first we'd probably want to figure out what exactly is failing in the first place? Is it Cookies.set(), or Cookies.get()? Or neither and it's just a "duration" issue? Why only 7 days? Very strange.

Could you provide a minimal reproducible example somewhere online (or just code/options for it) that demonstrates the exact issue you're having?

fabiocaccamo commented 1 year ago

Hi, thank you for the feedback. This is the code I run:

let options = {
    "message": "Our website uses cookies ...",
    "linkmsg": "Cookie Policy",
    "moreinfo": "/cookie-policy/",
    "cookie": "cookie-consent",
    "cookie-secure": (window.location.protocol === 'https:' ? true : false),
    "close-text": "✕"
};
this._cookieBanner = new Cookiebanner(options);
this._cookieBanner.run();

As you can see I don't set the expiration date.

I now deleted the cookie from both Firefox and Chrome, then:

I open the website with Firefox, I accept the cookie-policy and this is the cookie expiration date:

Screenshot 2022-11-15 at 15 25 43

I open the website with Chrome, I accept the cookie-policy and this is the cookie expiration date:

Screenshot 2022-11-15 at 15 27 21

This can't be an implementation problem.

zytzagoo commented 1 year ago

I cannot replicate :/

For me, in Firefox (107, osx), running either the test suite (via file:///) or serving up a blank demo page via http, I get the "expected" expiry dates:

Screenshot 2022-11-15 at 17 15 14 Screenshot 2022-11-15 at 17 35 15

Not sure what to do in order to prove the default/Infinity expiry in the tests suite though (since there is no way to get that data directly out of document.cookie)

fabiocaccamo commented 1 year ago

Incredibile, I try to replicate it in smaller scale.

zytzagoo commented 1 year ago

Any luck finding out what's going on exactly?

fabiocaccamo commented 1 year ago

Sorry for the silence, I will isolate a test this week.

fabiocaccamo commented 1 year ago

@zytzagoo here the minimal test:

HTML

cookiebanner.html file with the following content:

<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>cookiebanner</title>
    </head>
    <body>
        <script type="text/javascript" src="cookiebanner.js"></script>
        <script type="text/javascript">
            let cookieBanner = new Cookiebanner({
                "message": "Our website uses cookies ...,",
                "linkmsg": "Cookie Policy",
                "moreinfo": "/cookie-policy.html",
                "cookie": "test-cookiebanner",
                "cookie-secure": (window.location.protocol === 'https:' ? true : false),
                "close-text": "&#10005;"
            });
            cookieBanner.run();
        </script>
    </body>
</html>

JS

cookiebanner.js file taken from master

COOKIE

This is the result cookie set on macOS Monterey 12.2.1 / Firefox 107.0.1:

Screenshot 2022-12-14 at 14 20 51

As you can see the default "infinite" expiration date doesn't work, it is set to one week.

zytzagoo commented 1 year ago

For me it behaves as expected, Firefox 107.0.0, macOS High Sierra (10.13.6), here are the screenshots:

Screen Shot 2022-12-15 at 12 34 20

Screen Shot 2022-12-15 at 12 34 38

Screen Shot 2022-12-15 at 12 34 53

fabiocaccamo commented 1 year ago

Thank you for your feedback. I isolated the problem, it's caused by a browser extension. I try now to isolate also the extension that causes that.

fabiocaccamo commented 1 year ago

These the extensions I'm using, not too many and pretty popular:

Screenshot 2022-12-15 at 13 05 30
zytzagoo commented 1 year ago

Perhaps something in your firefox profile (or install) is wonky -- did you maybe try a new/fresh profile (and/or [re]install) and see if the issue persists there?

I have uBlock Origin as well, so can't be that. The only other suspect could be DuckDuckGo Privacy Essentials maybe? (if it's really caused by an extension at all)

fabiocaccamo commented 1 year ago

I confirm it, I don't know why, but it's caused by the "DuckDuckGo Privacy Essentials" extension.

zytzagoo commented 1 year ago

It's a feature, described here: https://help.duckduckgo.com/duckduckgo-help-pages/privacy/web-tracking-protections/ -- search for '7-day' (1st party cookie protection)

fabiocaccamo commented 1 year ago

ohhh didn't know that, thank you very much!