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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set SameSite in cookie test #2596

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

Markel
Copy link
Contributor

@Markel Markel commented Sep 3, 2020

Resolves #2589

The PR basically does what the title says, it really shouldn't affect as the cookie it's deleted once the test is performed, but hey the Chromium team recommends it

However we strongly recommend you apply an appropriate SameSite value (Lax or Strict) and not rely on default browser behavior since not all browsers protect same-site cookies by default.

Moreover, the caniuse page shows us that this feature is backwards compatible so it shouldn't result on any errors in old browsers

This feature is backwards compatible. Browsers not supporting this feature will simply use the cookie as a regular cookie. There is no need to deliver different cookies to clients.

And if you are asking why I used Lax instead of Strict is because I prefer to be safe than sorry even if it shouldn't make any difference 馃槄

@codecov
Copy link

codecov bot commented Sep 3, 2020

Codecov Report

Merging #2596 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2596   +/-   ##
=======================================
  Coverage   95.15%   95.15%           
=======================================
  Files           5        5           
  Lines         165      165           
=======================================
  Hits          157      157           
  Misses          8        8           

Continue to review full report at Codecov.

Legend - Click here to learn more
螖 = absolute <relative> (impact), 酶 = not affected, ? = missing data
Powered by Codecov. Last update ef28146...6adcf3c. Read the comment docs.

@dev-rke
Copy link

dev-rke commented Nov 6, 2020

Hi,

i stumbled over your pull request as i have the same issue.
In my case i use a cross domain parent page for an iframe, where your implementation might break as well.
It's an assumption, i did not run your code, just set a cookie using chrome web developer tools within the iframe context.

To fix my case, i have to use SameSite=None and set the Secure flag:

document.cookie = 'cookietest=1; SameSite=None; Secure';

I assume your pull request will only fix cases where the iframe parent has the same origin.

@Markel
Copy link
Contributor Author

Markel commented Nov 10, 2020

Hi @dev-rke may you elaborate on that? Because the cookie we set it should only be used for Modernizr purposes (actually it gets deleted after the test), moreover, setting the Secure flag would break compatibility with non-HTTPS websites.

EDIT: Sorry for the late response

@dev-rke
Copy link

dev-rke commented Nov 10, 2020

Hi @Markel ,

i did not use the whole pull request itself, but i used the main parts of the code (excluding Modernizr plugin setup code).
So i cannot assure if your implementation will work, as i did not test it.
My setup uses a cross domain iframe, so top domain and iframe domain are different. Both domains use HTTPS.
The cookie is set within the iframe. Using Chromium 86 on Ubuntu.

Setting document.cookie manually by using your code snippet with SameSite=Lax won't work within my setup, i had to use SameSite=None and the Secure flag to get it working.

@dev-rke
Copy link

dev-rke commented Nov 11, 2020

Just as update: i disabled the modernizr cookie test in my specific cross domain case, as it turns out that it seem not to work reliable, it might have other causes (maybe caching).
I'd recommend not to worry too much about SameSite=Lax vs None at the moment, both approaches will be an improvement. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cookie test doesn't currently set the cookie with required attributes for Chrome
2 participants