Page MenuHomePhabricator

Future version of Chrome might break Special:HideBanners cookies
Closed, DuplicatePublic

Description

Visit https://donate.wikimedia.org/wiki/Thank_You in the current version of Chrome and you'll get a host of console warnings like this:

A cookie associated with a cross-site resource at https://en.wikipedia.org/ was set without the SameSite attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set with SameSite=None and Secure. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and https://www.chromestatus.com/feature/5633521622188032.

This could break the cookies which hide banners for users after they donate. Looks like the change is planned for Chrome 80 which doesn't have a release date yet, but 79 will be stable December 10th.

Can someone from fr-tech look into this?

Event Timeline

Pcoombe triaged this task as High priority.

Thanks Peter. I've added my findings below.

The below is my interpretation of the changes and how things work today. It's possible I'm wrong. It would be great if others on the team could confirm any assumptions I've made and point out any corrections needed. Thanks in advance!
TLDR; There's a risk that our hide cookies will no longer work in a future version of Chrome due Feb 2020. To avoid this risk, we should consider explicitly setting the cookie attributes SameSite and Secure when creating hide cookies and test the behaviour in advance of Feb 2020 to confirm no unwanted side-effects.

Introduction:
Currently, we drop third-party cookies on a user's browser after they donate to prevent repeat fundraising banners being shown across all Wikimedia projects. Third-party cookies are any cookie where the domain attribute differs from the current domain you're visiting. A cookie set with the domain of 'en.wikipedia.org' while the user is on 'donate.wikimedia.org' is a third-party cookie.

What's Changing?
A future version of Chrome (Version 80) due Feb 2020 will include two updates that change the default behaviour of cookies.

  • Update One - Chrome will soon change the default value for the optional cookie attribute SameSite from 'None' to 'Lax' .
  • Update Two - Chrome will reject cookies where SameSite=None and Secure=false. This is to reduce the security risks associated with non-encrypted cross-site cookie traffic.
  • SameSite launch timeline

What is the SameSite cookie attribute?
It's a way to control when browsers send cookies to the server. There's a pretty good overview here.

What can we set it to?

  • not set The SameSite attribute can be left unset and chrome will default to the behaviour of SameSite=None. However from Feb 2020, chrome will default to SameSite=Lax when the SameSite attribute is not set.
  • SameSite=None Current Default Send cookies to the server regardless of how the server is accessed (e.g. via embedded link to image on the external domain or directly visiting).
  • SameSite=Lax Default Feb 2020 Send cookies to the server only when the browser URL is the same as the cookie domain. Also include the initial visit to the domain.
  • SameSite=Strict Send cookies to the server only when the browser URL is the same as the cookie domain. Do not send cookies on the initial visit to the domain, on-site requests only.

What is the Secure cookie attribute?
Is tells the browser to only send the cookies to the server when the request is over HTTPS (prevent snooping at the network level)

What can we set it to?
This is a boolean value, true/false.

Why does this affect our hide cookies?
So currently our hide cookies behave as if they have the cookie attributes SameSite=None and Secure=false. We don't explicitly set these values but the absence of values for these attributes results in those defaults. Update Two will cause these types of cookies to be rejected post the Feb 2020 release of Chrome 80. However, Update One should mean our hide cookies will default to SameSite=Lax preventing our cookies being rejected meaning banners should still be hidden when users visit wikimedia projects after donating. The risk here is that if these two updates don't coincide as planned, the hide cookies will be rejected and donors still seeing banners after donating.

What files do we need to change to avoid any problems?
The code that handles the creation of our hide cookies lives in the CentralNotice mediawiki extension here https://github.com/wikimedia/mediawiki-extensions-CentralNotice/blob/master/includes/specials/SpecialHideBanners.php. Cookies created by this file are then picked up and processed on the frontend here https://github.com/wikimedia/mediawiki-extensions-CentralNotice/blob/master/resources/ext.centralNotice.display/index.js#L385 which leads on to here https://github.com/wikimedia/mediawiki-extensions-CentralNotice/blob/master/resources/ext.centralNotice.display/hide.js#L34.

What would the fix look like?
To start explicitly setting the SameSite and Secure cookie attributes, we could update this function https://github.com/wikimedia/mediawiki-extensions-CentralNotice/blob/master/includes/specials/SpecialHideBanners.php#L66 but the approach will depend on which version of PHP we are using. To make this more complicated, versions of PHP before 7.3 (released Dec2018) do not natively support the SameSite attribute within the setcookie() method that we are using. According to https://en.wikipedia.org/wiki/Special:Version we are running 7.2.22 in production which requires a workaround (or hack) depending on how we implement. Both approaches are outlined here and here.

How can we test the proposed fixes before Feb 2020?
Current versions of Chrome allow you to simulate Chrome 80 default cookie attribute behaviour by enabling chrome flags within the browser. See screenshot below on how to find them:

Screenshot from 2019-10-25 14-26-46.png (961×658 px, 87 KB)
(Tested on Chrome 77)

Thanks for all the research and supporting links, @jgleeson!

So of all the workarounds mentioned in https://stackoverflow.com/questions/39750906/php-setcookie-samesite-strict/46971326#46971326 , it looks like we'd really only want to use the fall back to a bare header() command. Using version detection to exploit a bug in set-cookie feels gross, and I don't think we can achieve this with server config. Since WMF sites are https-only now, I guess we'd also set Secure=true?

One more thought - I see you've described the SameSite attribute as controlling when the browser sends stored cookies to the server. If it doesn't stop the browser from STORING cookies, we may not actually need to change anything, since we only need to access the value of the wikipedia.org cookie when the donor is targeted by a banner on wikipedia.org.

Just want to say thanks both for investigating! Seems even more complicated than I first thought :/

T244699 seems like a different task, but reminded me of this one. It appears we never did anything to mitigate after the investigation, since I'm still seeing the warnings on https://donate.wikimedia.org/wiki/Thank_You. As it could result in fundraising banners persisting after donating or clicking close, this looks like a high priority.

According to https://www.chromium.org/updates/same-site this change is now going to be gradually rolled out to Chrome 80 Stable starting on February 18