Skip to content

Commit 41b935d

Browse files
committed
Fix incorrect setting of the SameSite cookie param
Add samesite cookie param support in form key provider and admin tools
1 parent bc5f97e commit 41b935d

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

app/code/Magento/PageCache/view/frontend/web/js/form-key-provider.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@ define(function () {
1717
function setFormKeyCookie(value) {
1818
var expires,
1919
secure,
20+
samesite,
2021
date = new Date(),
21-
isSecure = !!window.cookiesConfig && window.cookiesConfig.secure;
22+
cookiesConfig = window.cookiesConfig || {},
23+
isSecure = !!cookiesConfig.secure;
2224

2325
date.setTime(date.getTime() + 86400000);
2426
expires = '; expires=' + date.toUTCString();
2527
secure = isSecure ? '; secure' : '';
28+
samesite = '; samesite=' + (cookiesConfig.samesite ? cookiesConfig.samesite : 'lax');
2629

27-
document.cookie = 'form_key=' + (value || '') + expires + secure + '; path=/';
30+
document.cookie = 'form_key=' + (value || '') + expires + secure + '; path=/' + samesite;
2831
}
2932

3033
/**

lib/web/mage/adminhtml/tools.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ var Cookie = {
267267

268268
return null;
269269
},
270-
write: function (cookieName, cookieValue, cookieLifeTime) {
270+
write: function (cookieName, cookieValue, cookieLifeTime, samesite) {
271271
var expires = '';
272272

273273
if (cookieLifeTime) {
@@ -278,7 +278,9 @@ var Cookie = {
278278
}
279279
var urlPath = '/' + BASE_URL.split('/').slice(3).join('/'); // Get relative path
280280

281-
document.cookie = escape(cookieName) + '=' + escape(cookieValue) + expires + '; path=' + urlPath;
281+
samesite = '; samesite=' + (samesite ? samesite : 'lax');
282+
283+
document.cookie = escape(cookieName) + '=' + escape(cookieValue) + expires + '; path=' + urlPath + samesite;
282284
},
283285
clear: function (cookieName) {
284286
this.write(cookieName, '', -1);

0 commit comments

Comments
 (0)