Change all cookies to SameSite=None
A new KB article for SameSite with Federated Authentication is now available. In this article, one of the changes it suggests to make allows for ALL generated cookies to be set to SameSite=None
.
Configure the default values of cookies in the <system.web>
section of the web.config file as follows:
<httpCookies sameSite="None" requireSSL="true" />
Change SC_ANALYTICS_GLOBAL_COOKIE only
In order to change ONLY the analytics cookie you can make a pipeline change with a custom processor. Some notes:
- This will only work if your site runs on HTTPS because otherwise the cookie will be rejected.
- The visitor needs to visit the Sitecore site FIRST in order to get the new cookie. This is critical, so you want to make sure you are directing flow somehow through your Sitecore instance directly so that the cookie is created correctly, and then allowing visitors to go elsewhere to other 3rd party applications.
Here is a sample processor that the team here has been trying out:
namespace CustomProcessor
{
public class AdjustAnalyticsGlobalCookieSameSite
{
private const string AnalyticsGlobalCookieName = "SC_ANALYTICS_GLOBAL_COOKIE";
public void Process(PipelineArgs args)
{
var httpResponse = HttpContext.Current?.Response;
if (httpResponse != null && httpResponse.Cookies.AllKeys.Contains(AnalyticsGlobalCookieName))
{
var analyticsCookie = httpResponse.Cookies.Get(AnalyticsGlobalCookieName);
analyticsCookie.SameSite = SameSiteMode.None;
analyticsCookie.Secure = true;
}
}
}
}
To get this to run when content is delivered by Sitecore, you’ll need to patch your code into the analytics pipeline as the first processor so that it runs first and sets the cookie correctly:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"
xmlns:set="http://www.sitecore.net/xmlconfig/set/"
xmlns:role="http://www.sitecore.net/xmlconfig/role/">
<sitecore role:require="Standalone or ContentDelivery or ContentManagement">
<pipelines>
<endAnalytics>
<processor type="CustomProcessor.AdjustAnalyticsGlobalCookieSameSite, CustomProcessor" patch:before="processor[@type='Sitecore.Analytics.Pipelines.EndAnalytics.CheckPreconditions, Sitecore.Analytics']"/>
</endAnalytics>
</pipelines>
</sitecore>
</configuration>
References
- How do the SameSite cookie changes affect Sitecore installations? (Blog, Jason St-Cyr)
- Sitecore Knowledge Base article on SameSite support
- Reject insecure SameSite=None cookies (Feature article, Chrome Platform Status)
- SameSite Cookie Changes in February 2020: What You Need to Know (Chromium.org)
- SameSite Frequently Asked Questions (FAQ) (Chromium.org)
- SameSite cookies explained (Web.dev)
- Cross-site Request Forgery (Wikipedia.org)