Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement #16161: SameSite cookie attribute can be configured for JS tracker #16504

Closed
wants to merge 1 commit into from

Conversation

beger
Copy link

@beger beger commented Oct 1, 2020

With this change you can now set up your JS tracking code like this:

_paq.push(['setCookieSameSite', 'None']);

This will set the SameSite attribute for all cookies set by Matomo to the value used above. The default is still SameSite='Lax' if setCookieSameSite is not used.

Implements the enhancement discussed in #16161.

@tsteur
Copy link
Member

tsteur commented Oct 1, 2020

@beger thanks for creating this PR! I was wondering if we could simplify it and set automatically SameSite=None when isSecure is set? I'm suggesting this because None only works when also Secure is set see eg https://web.dev/samesite-cookies-explained/#changes-to-the-default-behavior-without-samesite AFAIK

@beger
Copy link
Author

beger commented Oct 1, 2020

@tsteur I think this may not be the right solution for every use case: you still may want to enforce a different SameSite policy even if your connection is secure. But I think it probably would make sense to do it the other way around and set isSecure to true automatically if SameSite is set to None. What do you think?

@tsteur
Copy link
Member

tsteur commented Oct 1, 2020

@beger that could work. And ideally it was to throw an error and/or log a message if this is called on HTTP ?

@tsteur tsteur added the Needs Review PRs that need a code review label Oct 26, 2020
@tsteur
Copy link
Member

tsteur commented Oct 26, 2020

@beger be great if you could look at my last comment and let us know if you're still planning to work on this PR?

@beger
Copy link
Author

beger commented Oct 27, 2020

Hello @tsteur,
yes I'm still planning to implement this and also include your suggestion. Due to high workload on my side I'll probably get to it sometime during November.

@fealXX
Copy link

fealXX commented Oct 28, 2020

Hi @beger, we're currently trying to use the code of your PR as a fix until a release happens and found a Problem:
If you're in a scenario where your tracking-domain is my.matomo.org, you're working on othersite.org and set your Cookiedomain to .matomo.org isPossibleToSetCookieOnDomain will fail. We need to set configCookieIsSecure and configCookieSameSite in line 4349 too.
function isPossibleToSetCookieOnDomain(domainToTest) { var valueToSet = 'testvalue'; setCookie('test', valueToSet, 10000, null, domainToTest, configCookieIsSecure, configCookieSameSite); [...]

Which leads me to another issue: This check depends on the order of operations of setCookieDomain, setSecureCookie and setCookieSameSite. If you first set the CookieDomain, then the SameSite/Secure attributes, the check fails. If you first set Secure and Samesite, the Check works fine. Maybe the cookie configuration should be moved into a single paq-Setting, along the lines of this, while keeping the old syntax for backwards compatibility:
_paq.push(['setCookieConfig', 'my.matomo.org', 'None', true]);

I'd be happy to help implementing this, if possible.

@tsteur
Copy link
Member

tsteur commented Nov 4, 2020

fyi if you are using one tracker using and init this trackker using _paq.push() then Matomo should make sure to call the methods in the right order as the order is defined in var applyFirst = .

To make it fully independent would probably require quite a few more changes as it is already a general problem in Matomo which could therefore also be fixed in a separate PR later. We should document it though at least that eg setCookiePath should be called before setCookieDomain if the tracker is being initialised manually.

Adding it to isPossibleToSetCookieOnDomain be indeed good and respect settings there too.

@beger
Copy link
Author

beger commented Nov 17, 2020

Thank you @fealXX and @tsteur for implementing and reviewing this in #16724. I think this PR can now be closed.

@beger beger closed this Nov 17, 2020
@tsteur
Copy link
Member

tsteur commented Nov 17, 2020

Thanks for getting this work started @beger and contributing to this feature, very appreciated 👍

@tsteur tsteur added the not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. label Nov 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review PRs that need a code review not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants