Skip to content

Commit f8726e8

Browse files
ENGCOM-8927: Fix incorrect setting of the SameSite cookie param #32462
- Merge Pull Request #32462 from ihor-sviziev/magento2:fix-incorrect-settinf-of-the-samesite-cookie-param - Merged commits: 1. bc5f97e 2. 41b935d 3. 35570b3 4. 753be2a
2 parents 7d5967f + 753be2a commit f8726e8

File tree

5 files changed

+15
-8
lines changed

5 files changed

+15
-8
lines changed

app/code/Magento/Cookie/view/base/web/js/jquery.storageapi.extended.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ define([
1616
* @private
1717
*/
1818
function _extend(storage) {
19+
var cookiesConfig = window.cookiesConfig || {};
20+
1921
$.extend(storage, {
20-
_secure: window.cookiesConfig ? window.cookiesConfig.secure : false,
21-
_samesite: window.cookiesConfig ? window.cookiesConfig.samesite : 'lax',
22+
_secure: !!cookiesConfig.secure,
23+
_samesite: cookiesConfig.samesite ? cookiesConfig.samesite : 'lax',
2224

2325
/**
2426
* Set value under name

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
@@ -18,13 +18,16 @@ define(function () {
1818
var expires,
1919
secure,
2020
date = new Date(),
21-
isSecure = !!window.cookiesConfig && window.cookiesConfig.secure;
21+
cookiesConfig = window.cookiesConfig || {},
22+
isSecure = !!cookiesConfig.secure,
23+
samesite = cookiesConfig.samesite || 'lax';
2224

2325
date.setTime(date.getTime() + 86400000);
2426
expires = '; expires=' + date.toUTCString();
2527
secure = isSecure ? '; secure' : '';
28+
samesite = '; samesite=' + samesite;
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/jquery/jquery.cookie.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
options.path ? '; path=' + options.path : '',
4848
options.domain ? '; domain=' + options.domain : '',
4949
options.secure ? '; secure' : '',
50-
options.samesite ? '; samesite=' + options.samesite : 'lax',
50+
'; samesite=' + (options.samesite ? options.samesite : 'lax'),
5151
].join(''));
5252
}
5353

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);

lib/web/mage/cookies.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ define([
7676
(path ? '; path=' + path : '') +
7777
(domain ? '; domain=' + domain : '') +
7878
(secure ? '; secure' : '') +
79-
(samesite ? '; samesite=' + samesite : 'lax');
79+
'; samesite=' + (samesite ? samesite : 'lax');
8080
};
8181

8282
/**

0 commit comments

Comments
 (0)