Skip to content

Commit a15f335

Browse files
committed
Fix for the issue #24547
1 parent 5ee35e5 commit a15f335

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

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

100644100755
Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Customer\Model\Url as CustomerUrl;
1010
use Magento\Framework\App\RequestInterface;
1111
use Magento\Framework\Controller\ResultFactory;
12+
use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory;
1213
use Magento\Framework\Url\HostChecker;
1314
use Magento\Framework\UrlInterface;
1415
use Magento\Store\Model\ScopeInterface;
@@ -69,6 +70,11 @@ class Redirect
6970
*/
7071
protected $cookieManager;
7172

73+
/**
74+
* @var CookieMetadataFactory
75+
*/
76+
protected $cookieMetadataFactory;
77+
7278
/**
7379
* @var HostChecker
7480
*/
@@ -88,6 +94,7 @@ class Redirect
8894
* @param DecoderInterface $urlDecoder
8995
* @param CustomerUrl $customerUrl
9096
* @param ResultFactory $resultFactory
97+
* @param CookieMetadataFactory $cookieMetadataFactory
9198
* @param HostChecker|null $hostChecker
9299
*/
93100
public function __construct(
@@ -99,6 +106,7 @@ public function __construct(
99106
DecoderInterface $urlDecoder,
100107
CustomerUrl $customerUrl,
101108
ResultFactory $resultFactory,
109+
CookieMetadataFactory $cookieMetadataFactory,
102110
HostChecker $hostChecker = null
103111
) {
104112
$this->request = $request;
@@ -109,6 +117,7 @@ public function __construct(
109117
$this->urlDecoder = $urlDecoder;
110118
$this->customerUrl = $customerUrl;
111119
$this->resultFactory = $resultFactory;
120+
$this->cookieMetadataFactory = $cookieMetadataFactory;
112121
$this->hostChecker = $hostChecker ?: ObjectManager::getInstance()->get(HostChecker::class);
113122
}
114123

@@ -279,7 +288,11 @@ public function getRedirectCookie()
279288
*/
280289
public function setRedirectCookie($route)
281290
{
282-
$this->getCookieManager()->setPublicCookie(self::LOGIN_REDIRECT_URL, $route);
291+
$cookieMetadata = $this->cookieMetadataFactory->createPublicCookieMetadata()
292+
->setHttpOnly(true)
293+
->setDuration(3600)
294+
->setPath($this->storeManager->getStore()->getStorePath());
295+
$this->getCookieManager()->setPublicCookie(self::LOGIN_REDIRECT_URL, $route, $cookieMetadata);
283296
}
284297

285298
/**
@@ -289,6 +302,8 @@ public function setRedirectCookie($route)
289302
*/
290303
public function clearRedirectCookie()
291304
{
292-
$this->getCookieManager()->deleteCookie(self::LOGIN_REDIRECT_URL);
305+
$cookieMetadata = $this->cookieMetadataFactory->createPublicCookieMetadata()
306+
->setPath($this->storeManager->getStore()->getStorePath());
307+
$this->getCookieManager()->deleteCookie(self::LOGIN_REDIRECT_URL, $cookieMetadata);
293308
}
294309
}

0 commit comments

Comments
 (0)