Skip to content

Commit 83202ee

Browse files
Merge pull request #6408 from magento-borg/MC-35390
[CIA] Bugfixes
2 parents 1717956 + 36657b6 commit 83202ee

File tree

25 files changed

+147
-23
lines changed

25 files changed

+147
-23
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ define([
1818
function _extend(storage) {
1919
$.extend(storage, {
2020
_secure: window.cookiesConfig ? window.cookiesConfig.secure : false,
21+
_samesite: window.cookiesConfig ? window.cookiesConfig.samesite : 'lax',
2122

2223
/**
2324
* Set value under name
@@ -30,7 +31,8 @@ define([
3031
expires: this._expires,
3132
path: this._path,
3233
domain: this._domain,
33-
secure: this._secure
34+
secure: this._secure,
35+
samesite: this._samesite
3436
};
3537

3638
$.cookie(this._prefix + name, value, $.extend(_default, options || {}));
@@ -58,6 +60,10 @@ define([
5860
this._secure = c.secure;
5961
}
6062

63+
if (typeof c.samesite !== 'undefined') {
64+
this._samesite = c.samesite;
65+
}
66+
6167
return this;
6268
}
6369
});

app/code/Magento/Customer/Model/Account/Redirect.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ public function setRedirectCookie($route)
322322
->setHttpOnly(true)
323323
->setDuration(3600)
324324
->setPath($this->storeManager->getStore()->getStorePath())
325+
->setSameSite('Lax')
325326
);
326327
}
327328

app/code/Magento/Customer/Test/Unit/Model/Account/RedirectTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,10 @@ public function testSetRedirectCookie(): void
398398
->method('setPath')
399399
->with('storePath')
400400
->willReturnSelf();
401+
$publicMetadataMock->expects($this->once())
402+
->method('setSameSite')
403+
->with('Lax')
404+
->willReturnSelf();
401405
$coockieManagerMock->expects($this->once())
402406
->method('setPublicCookie')
403407
->with(

app/code/Magento/Customer/view/frontend/web/js/customer-data.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ define([
219219
initStorage: function () {
220220
$.cookieStorage.setConf({
221221
path: '/',
222-
expires: new Date(Date.now() + parseInt(options.cookieLifeTime, 10) * 1000)
222+
expires: new Date(Date.now() + parseInt(options.cookieLifeTime, 10) * 1000),
223+
samesite: 'lax'
223224
});
224225
storage = $.initNamespaceStorage('mage-cache-storage').localStorage;
225226
storageInvalidation = $.initNamespaceStorage('mage-cache-storage-section-invalidation').localStorage;

app/code/Magento/PageCache/Plugin/RegisterFormKeyFromCookie.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ private function updateCookieFormKey(string $formKey): void
9696
$cookieMetadata->setDomain($this->sessionConfig->getCookieDomain());
9797
$cookieMetadata->setPath($this->sessionConfig->getCookiePath());
9898
$cookieMetadata->setSecure($this->sessionConfig->getCookieSecure());
99+
$cookieMetadata->setSameSite('Lax');
99100
$lifetime = $this->sessionConfig->getCookieLifetime();
100101
if ($lifetime !== 0) {
101102
$cookieMetadata->setDuration($lifetime);

app/code/Magento/Persistent/Model/Session.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* @method int getCustomerId()
1313
* @method Session setCustomerId()
1414
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
15+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
1516
* @since 100.0.2
1617
*/
1718
class Session extends \Magento\Framework\Model\AbstractModel
@@ -391,7 +392,8 @@ private function setCookie($value, $duration, $path)
391392
->setDuration($duration)
392393
->setPath($path)
393394
->setSecure($this->getRequest()->isSecure())
394-
->setHttpOnly(true);
395+
->setHttpOnly(true)
396+
->setSameSite('Lax');
395397
$this->_cookieManager->setPublicCookie(
396398
self::COOKIE_NAME,
397399
$value,

app/code/Magento/Persistent/Test/Unit/Model/SessionTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ public function testSetPersistentCookie()
143143
$cookieMetadataMock->expects($this->once())
144144
->method('setHttpOnly')
145145
->with(true)->willReturnSelf();
146+
$cookieMetadataMock->expects($this->once())
147+
->method('setSameSite')
148+
->with('Lax')->willReturnSelf();
146149
$this->cookieMetadataFactoryMock->expects($this->once())
147150
->method('createPublicCookieMetadata')
148151
->willReturn($cookieMetadataMock);
@@ -186,6 +189,9 @@ public function testRenewPersistentCookie(
186189
$cookieMetadataMock->expects($this->exactly($numCalls))
187190
->method('setHttpOnly')
188191
->with(true)->willReturnSelf();
192+
$cookieMetadataMock->expects($this->exactly($numCalls))
193+
->method('setSameSite')
194+
->with('Lax')->willReturnSelf();
189195
$this->cookieMetadataFactoryMock->expects($this->exactly($numCalls))
190196
->method('createPublicCookieMetadata')
191197
->willReturn($cookieMetadataMock);

app/code/Magento/Sales/Helper/Guest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ private function setGuestViewCookie($cookieValue)
211211
{
212212
$metadata = $this->cookieMetadataFactory->createPublicCookieMetadata()
213213
->setPath(self::COOKIE_PATH)
214-
->setHttpOnly(true);
214+
->setHttpOnly(true)
215+
->setSameSite('Lax');
215216
$this->cookieManager->setPublicCookie(self::COOKIE_NAME, $cookieValue, $metadata);
216217
}
217218

app/code/Magento/Sales/Test/Unit/Helper/GuestTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ public function testLoadValidOrderNotEmptyPost($post)
196196
->method('setHttpOnly')
197197
->with(true)
198198
->willReturnSelf();
199+
$metaDataMock->expects($this->once())
200+
->method('setSameSite')
201+
->with('Lax')
202+
->willReturnSelf();
199203
$this->cookieMetadataFactoryMock->expects($this->once())
200204
->method('createPublicCookieMetadata')
201205
->willReturn($metaDataMock);
@@ -279,6 +283,10 @@ public function testLoadValidOrderStoredCookie()
279283
->method('setHttpOnly')
280284
->with(true)
281285
->willReturnSelf();
286+
$metaDataMock->expects($this->once())
287+
->method('setSameSite')
288+
->with('Lax')
289+
->willReturnSelf();
282290
$this->cookieMetadataFactoryMock->expects($this->once())
283291
->method('createPublicCookieMetadata')
284292
->willReturn($metaDataMock);

app/code/Magento/Security/Model/SecurityCookie.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
/**
1111
* Manager for a cookie with logout reason
1212
*
13+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
1314
* @api
1415
* @since 100.1.0
1516
*/
@@ -80,6 +81,7 @@ public function setLogoutReasonCookie($status)
8081
{
8182
$metaData = $this->createCookieMetaData();
8283
$metaData->setPath('/' . $this->backendData->getAreaFrontName());
84+
$metaData->setSameSite('Strict');
8385

8486
$this->phpCookieManager->setPublicCookie(
8587
self::LOGOUT_REASON_CODE_COOKIE_NAME,

0 commit comments

Comments
 (0)