Cookie “PHPSESSID” will be soon treated as cross-site cookie against <file> because the scheme does not match
Asked Answered
B

5

52

I've just noticed my console is littered with this warning, appearing for every single linked resource. This includes all referenced CSS files, javascript files, SVG images, and even URLs from ajax calls (which respond in JSON). But not images.

The warning, for example in case of a style.css file, will say:

Cookie “PHPSESSID” will be soon treated as cross-site cookie against “http://localhost/style.css” because the scheme does not match.

But, the scheme doesn't match what? The document? Because that it does.

  • The URL of my site is http://localhost/.
  • The site and its resources are all on http (no https on localhost)
  • The domain name is definitely not different because everything is referenced relative to the domain name (meaning the filepaths start with a slash href="/style.css")

The Network inspector just reports a green 200 OK response, showing everything as normal.

It's only Mozilla Firefox that is complaining about this. Chromium seems to not be concerned by anything. I don't have any browser add-ons. The warnings seem to originate from the browser, and each warning links to view the corresponding file source in Debugger.

Why is this appearing?

Budding answered 7/8, 2020 at 8:19 Comment(2)
tl;dr In Firefox, go to settings, search for cookies, click Manage Data, search for localhost, select localhost, click Remove Selected... Worked for me...Bibby
in addidtion you can follow these easy steps in Firefox: support.mozilla.org/en-US/kb/…Audra
P
29

that was exactly same happening with me. the issue was that, firefox keeps me showing even Cookies of different websites hosted on same URL : "localhost:Port number" stored inside browser memory.

In my case, i have two projects configured to run at http://localhost:62601, when i run first project, it saves that cookie in browser memory. when i run second project having same URL, Cookie is available inside that projects console also.

what you can do, is delete the all of the cookies from browser.

Peddling answered 17/8, 2020 at 13:48 Comment(2)
I run several development projects from VirtualBox, accessed on the same IP address but via domains defined in my hosts file. Deleting cookies seems to have made the message go away.Southpaw
You can also go to Development Tools -> Storage and select line for the "localhost" domain and "/" path and then right click it and delete the selected cookie.Chon
I
27

@Paramjot Singh's answer is correct and got me most of the way to where I needed to be. I also wasted a lot of time staring at those warnings.

But to clarify a little, you don't have to delete ALL of your cookies to resolve this. In Firefox, you can delete individual site cookies, which will keep your settings on other sites.

To do so, click the hamburger menu in the top right, then, Options->Privacy & Security or Settings->Privacy & Security

From here, scroll down about half-way and find Cookies and Site Data. Don't click Clear Data. Instead, click Manage Data. Then, search for the site you are having the notices on, highlight it, and Remove Selected

Simple, I know, but I made the mistake of clearing everything the first time - maybe this will prevent someone from doing same.

Ieshaieso answered 10/9, 2020 at 0:12 Comment(0)
L
20

The warning is given because, according to MDN web docs:

Standards related to the Cookie SameSite attribute recently changed such that:

The cookie-sending behaviour if SameSite is not specified is SameSite=Lax. Previously the default was that cookies were sent for all requests. Cookies with SameSite=None must now also specify the Secure attribute (they require a secure context/HTTPS).

Which indicates that a secure context/HTTPS is required in order to allow cross site cookies by setting SameSite=None Secure for the cookie.

According to Mozilla, you should explicitly communicate the intended SameSite policy for your cookie (rather than relying on browsers to apply SameSite=Lax automatically), otherwise you might get a warning like this:

Cookie “myCookie” has “SameSite” policy set to “Lax” because it is missing a “SameSite” attribute, and “SameSite=Lax” is the default value for this attribute.

The suggestion to simply delete localhost cookies is not actually solving the problem. The solution is to properly set the SameSite attribute of cookies being set by the server and use HTTPS if needed.

Firefox is not the only browser making these changes. Apparently the version of Chrome I am using (84.0.4147.125) has already implemented the changes as I got this message in the console: enter image description here

The previously mentioned MDN article and this article by Mike Conca have great information about changes to SameSite cookie behavior.

Leflore answered 4/12, 2020 at 20:18 Comment(0)
R
3

Guess you are using WAMP or LAMP etc. The first thing you need to do is enable ssl on WAMP as you will find many references saying you need to adjust the cookie settings to SameSite=None; Secure That entails your local connection being secure. There are instructions on this link https://articlebin.michaelmilette.com/how-to-add-ssl-https-to-wampserver/ as well as some YouTube vids. The important thing to note is that when creating the SSL certificate you should use sha256 encoding as sha1 is now deprecated and will throw another warning. There is a good explanation of SameSite cookies on https://web.dev/samesite-cookies-explained/ I was struggling with the same issue and solved it by making sure the Apache 2.4 headers module was enabled and than added one line of code

Header always edit Set-Cookie ^(.")$ $1;HttpOnly;Secure

I wasted lots of time staring at the same sets of warnings in the Inspector until it dawned on me that the cookies were persisting and needed purging.

Apparently Chrome was going to introduce the new rules by now but Covid-19 meant a lot of websites might have been broken while people worked from home. The major browsers are working together on the SameSite attribute this so it will be in force soon.

Reest answered 7/8, 2020 at 10:43 Comment(0)
G
0

Use something like this inside some php code:

session_start([
'cookie_samesite' => 'Lax',]);
Gerlac answered 12/11, 2023 at 1:19 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Retool

© 2022 - 2024 — McMap. All rights reserved.