Skip to content

Commit a0cd931

Browse files
Merge pull request #5325 from magento-qwerty/MC-29561
Deprecate SID query parameter-related methods
2 parents b899606 + ca68777 commit a0cd931

File tree

13 files changed

+57
-144
lines changed

13 files changed

+57
-144
lines changed

app/code/Magento/Catalog/Model/Template/Filter.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
/**
1616
* Work with catalog(store, website) urls
17-
*
18-
* @package Magento\Catalog\Model\Template
1917
*/
2018
class Filter extends \Magento\Framework\Filter\Template
2119
{
@@ -30,6 +28,7 @@ class Filter extends \Magento\Framework\Filter\Template
3028
* Whether to allow SID in store directive: NO
3129
*
3230
* @var bool
31+
* @deprecated SID query parameter is not used in URLs anymore.
3332
*/
3433
protected $_useSessionInUrl = false;
3534

@@ -81,10 +80,14 @@ public function setUseAbsoluteLinks($flag)
8180
*
8281
* @param bool $flag
8382
* @return $this
83+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
84+
* @deprecated SID query parameter is not used in URLs anymore.
8485
*/
8586
public function setUseSessionInUrl($flag)
8687
{
87-
$this->_useSessionInUrl = $flag;
88+
// phpcs:disable Magento2.Functions.DiscouragedFunction
89+
trigger_error('Session ID is not used as URL parameter anymore.', E_USER_DEPRECATED);
90+
8891
return $this;
8992
}
9093

@@ -126,6 +129,7 @@ public function viewDirective($construction)
126129
*/
127130
public function mediaDirective($construction)
128131
{
132+
// phpcs:disable Magento2.Functions.DiscouragedFunction
129133
$params = $this->getParameters(html_entity_decode($construction[2], ENT_QUOTES));
130134
return $this->_storeManager->getStore()
131135
->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . $params['url'];

app/code/Magento/Cms/Model/Template/Filter.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,6 @@
1212
*/
1313
class Filter extends \Magento\Email\Model\Template\Filter
1414
{
15-
/**
16-
* Whether to allow SID in store directive: AUTO
17-
*
18-
* @var bool
19-
*/
20-
protected $_useSessionInUrl;
21-
22-
/**
23-
* Setter whether SID is allowed in store directive
24-
*
25-
* @param bool $flag
26-
* @return $this
27-
*/
28-
public function setUseSessionInUrl($flag)
29-
{
30-
$this->_useSessionInUrl = (bool)$flag;
31-
return $this;
32-
}
33-
3415
/**
3516
* Retrieve media file URL directive
3617
*

app/code/Magento/Email/Model/Template/Filter.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class Filter extends \Magento\Framework\Filter\Template
4444
* Whether to allow SID in store directive: NO
4545
*
4646
* @var bool
47+
* @deprecated SID is not being used as query parameter anymore.
4748
*/
4849
protected $_useSessionInUrl = false;
4950

@@ -263,10 +264,14 @@ public function setUseAbsoluteLinks($flag)
263264
*
264265
* @param bool $flag
265266
* @return $this
267+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
268+
* @deprecated SID query parameter is not used in URLs anymore.
266269
*/
267270
public function setUseSessionInUrl($flag)
268271
{
269-
$this->_useSessionInUrl = $flag;
272+
// phpcs:disable Magento2.Functions.DiscouragedFunction
273+
trigger_error('Session ID is not used as URL parameter anymore.', E_USER_DEPRECATED);
274+
270275
return $this;
271276
}
272277

app/code/Magento/Store/Model/StoreSwitcher/CleanTargetUrl.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
/**
1616
* Remove SID, from_store, store from target url.
17+
*
18+
* Used in store-switching process in HTML frontend.
19+
*
20+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
1721
*/
1822
class CleanTargetUrl implements StoreSwitcherInterface
1923
{
@@ -22,42 +26,32 @@ class CleanTargetUrl implements StoreSwitcherInterface
2226
*/
2327
private $urlHelper;
2428

25-
/**
26-
* @var \Magento\Framework\Session\Generic
27-
*/
28-
private $session;
29-
30-
/**
31-
* @var \Magento\Framework\Session\SidResolverInterface
32-
*/
33-
private $sidResolver;
34-
3529
/**
3630
* @param UrlHelper $urlHelper
3731
* @param \Magento\Framework\Session\Generic $session
3832
* @param \Magento\Framework\Session\SidResolverInterface $sidResolver
33+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
3934
*/
4035
public function __construct(
4136
UrlHelper $urlHelper,
4237
\Magento\Framework\Session\Generic $session,
4338
\Magento\Framework\Session\SidResolverInterface $sidResolver
4439
) {
4540
$this->urlHelper = $urlHelper;
46-
$this->session = $session;
47-
$this->sidResolver = $sidResolver;
4841
}
4942

5043
/**
44+
* Generate target URL to switch stores through other mechanism then via URL params.
45+
*
5146
* @param StoreInterface $fromStore store where we came from
5247
* @param StoreInterface $targetStore store where to go to
5348
* @param string $redirectUrl original url requested for redirect after switching
5449
* @return string redirect url
50+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
5551
*/
5652
public function switch(StoreInterface $fromStore, StoreInterface $targetStore, string $redirectUrl): string
5753
{
5854
$targetUrl = $redirectUrl;
59-
$sidName = $this->sidResolver->getSessionIdQueryParam($this->session);
60-
$targetUrl = $this->urlHelper->removeRequestParam($targetUrl, $sidName);
6155
$targetUrl = $this->urlHelper->removeRequestParam($targetUrl, '___from_store');
6256
$targetUrl = $this->urlHelper->removeRequestParam($targetUrl, StoreResolverInterface::PARAM_NAME);
6357

dev/tests/integration/testsuite/Magento/Framework/Session/SessionManagerTest.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -225,22 +225,6 @@ public function testSetSessionId()
225225
$this->assertEquals('test', $this->model->getSessionId());
226226
}
227227

228-
/**
229-
* @magentoConfigFixture current_store web/session/use_frontend_sid 1
230-
*/
231-
public function testSetSessionIdFromParam()
232-
{
233-
$this->initializeModel();
234-
$this->appState->expects($this->any())
235-
->method('getAreaCode')
236-
->willReturn(\Magento\Framework\App\Area::AREA_FRONTEND);
237-
$currentId = $this->model->getSessionId();
238-
$this->assertNotEquals('test_id', $this->model->getSessionId());
239-
$this->request->getQuery()->set(SidResolverInterface::SESSION_ID_QUERY_PARAM, 'test-id');
240-
$this->model->setSessionId($this->sidResolver->getSid($this->model));
241-
$this->assertEquals($currentId, $this->model->getSessionId());
242-
}
243-
244228
public function testGetSessionIdForHost()
245229
{
246230
$this->initializeModel();

dev/tests/integration/testsuite/Magento/Framework/UrlTest.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@ protected function setUp()
2323
$this->model = Bootstrap::getObjectManager()->create(\Magento\Framework\Url::class);
2424
}
2525

26-
public function testSetGetUseSession()
27-
{
28-
$this->assertFalse((bool)$this->model->getUseSession());
29-
$this->model->setUseSession(false);
30-
$this->assertFalse($this->model->getUseSession());
31-
}
32-
3326
public function testSetRouteFrontName()
3427
{
3528
$value = 'route';

dev/tests/integration/testsuite/Magento/Store/Model/StoreSwitcherTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected function setUp()
4242
*/
4343
public function testSwitch(): void
4444
{
45-
$redirectUrl = "http://domain.com/?SID=e5h3e086dce3ckkqt9ia7avl27&___store=fixture_second_store";
45+
$redirectUrl = "http://domain.com/?___store=fixture_second_store";
4646
$expectedUrl = "http://domain.com/";
4747
$fromStoreCode = 'test';
4848
/** @var \Magento\Store\Api\StoreRepositoryInterface $storeRepository */

lib/internal/Magento/Framework/Session/SessionManager.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
use Magento\Framework\Session\Config\ConfigInterface;
1111

1212
/**
13-
* Session Manager
13+
* Standard session management.
14+
*
1415
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1516
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
1617
*/
@@ -200,9 +201,6 @@ public function start()
200201
session_commit();
201202
session_id($_SESSION['new_session_id']);
202203
}
203-
$sid = $this->sidResolver->getSid($this);
204-
// potential custom logic for session id (ex. switching between hosts)
205-
$this->setSessionId($sid);
206204
session_start();
207205
if (isset($_SESSION['destroyed'])
208206
&& $_SESSION['destroyed'] < time() - $this->sessionConfig->getCookieLifetime()
@@ -211,7 +209,7 @@ public function start()
211209
}
212210

213211
$this->validator->validate($this);
214-
$this->renewCookie($sid);
212+
$this->renewCookie(null);
215213

216214
register_shutdown_function([$this, 'writeClose']);
217215

lib/internal/Magento/Framework/Session/SidResolver.php

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class SidResolver implements SidResolverInterface
5656
* @var bool|null
5757
* @see \Magento\Framework\UrlInterface
5858
*/
59-
protected $_useSessionInUrl;
59+
protected $_useSessionInUrl = false;
6060

6161
/**
6262
* @var string
@@ -88,26 +88,21 @@ public function __construct(
8888
}
8989

9090
/**
91-
* Get Sid
92-
*
93-
* @param SessionManagerInterface $session
94-
* @return string|null
95-
* @throws \Magento\Framework\Exception\LocalizedException
96-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
91+
* @inheritDoc
9792
*/
9893
public function getSid(SessionManagerInterface $session)
9994
{
95+
trigger_error('Session ID is not used as URL parameter anymore.', E_USER_DEPRECATED);
96+
10097
return null;
10198
}
10299

103100
/**
104-
* Get session id query param
105-
*
106-
* @param SessionManagerInterface $session
107-
* @return string
101+
* @inheritDoc
108102
*/
109103
public function getSessionIdQueryParam(SessionManagerInterface $session)
110104
{
105+
trigger_error('Session ID is not used as URL parameter anymore.', E_USER_DEPRECATED);
111106
$sessionName = $session->getName();
112107
if ($sessionName && isset($this->sidNameMap[$sessionName])) {
113108
return $this->sidNameMap[$sessionName];
@@ -116,57 +111,42 @@ public function getSessionIdQueryParam(SessionManagerInterface $session)
116111
}
117112

118113
/**
119-
* Set use session var instead of SID for URL
120-
*
121-
* @param bool $var
122-
* @return $this
114+
* @inheritDoc
123115
*/
124116
public function setUseSessionVar($var)
125117
{
126-
$this->_useSessionVar = (bool)$var;
118+
trigger_error('Session ID is not used as URL parameter anymore.', E_USER_DEPRECATED);
119+
127120
return $this;
128121
}
129122

130123
/**
131-
* Retrieve use flag session var instead of SID for URL
132-
*
133-
* @return bool
134-
* @SuppressWarnings(PHPMD.BooleanGetMethodName)
124+
* @inheritDoc
135125
*/
136126
public function getUseSessionVar()
137127
{
138-
return $this->_useSessionVar;
128+
trigger_error('Session ID is not used as URL parameter anymore.', E_USER_DEPRECATED);
129+
130+
return false;
139131
}
140132

141133
/**
142-
* Set Use session in URL flag
143-
*
144-
* @param bool $flag
145-
* @return $this
134+
* @inheritDoc
146135
*/
147136
public function setUseSessionInUrl($flag = true)
148137
{
149-
$this->_useSessionInUrl = (bool)$flag;
138+
trigger_error('Session ID is not used as URL parameter anymore.', E_USER_DEPRECATED);
139+
150140
return $this;
151141
}
152142

153143
/**
154-
* Retrieve use session in URL flag.
155-
*
156-
* @return bool
157-
* @SuppressWarnings(PHPMD.BooleanGetMethodName)
144+
* @inheritDoc
158145
*/
159146
public function getUseSessionInUrl()
160147
{
161-
if ($this->_useSessionInUrl === null) {
162-
//Using config value by default, can be overridden by using the
163-
//setter.
164-
$this->_useSessionInUrl = $this->scopeConfig->isSetFlag(
165-
self::XML_PATH_USE_FRONTEND_SID,
166-
$this->_scopeType
167-
);
168-
}
148+
trigger_error('Session ID is not used as URL parameter anymore.', E_USER_DEPRECATED);
169149

170-
return $this->_useSessionInUrl;
150+
return false;
171151
}
172152
}

lib/internal/Magento/Framework/Session/SidResolverInterface.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
/**
1111
* Interface \Magento\Framework\Session\SidResolverInterface
1212
*
13+
* @deprecated 2.3.3 SIDs in URLs are no longer used
1314
*/
1415
interface SidResolverInterface
1516
{
@@ -23,6 +24,7 @@ interface SidResolverInterface
2324
*
2425
* @param \Magento\Framework\Session\SessionManagerInterface $session
2526
* @return string|null
27+
* @deprecated SID query parameter is not used in URLs anymore.
2628
*/
2729
public function getSid(\Magento\Framework\Session\SessionManagerInterface $session);
2830

@@ -31,6 +33,7 @@ public function getSid(\Magento\Framework\Session\SessionManagerInterface $sessi
3133
*
3234
* @param \Magento\Framework\Session\SessionManagerInterface $session
3335
* @return string
36+
* @deprecated SID query parameter is not used in URLs anymore.
3437
*/
3538
public function getSessionIdQueryParam(\Magento\Framework\Session\SessionManagerInterface $session);
3639

@@ -39,6 +42,7 @@ public function getSessionIdQueryParam(\Magento\Framework\Session\SessionManager
3942
*
4043
* @param bool $var
4144
* @return $this
45+
* @deprecated SID query parameter is not used in URLs anymore.
4246
*/
4347
public function setUseSessionVar($var);
4448

@@ -55,13 +59,15 @@ public function getUseSessionVar();
5559
*
5660
* @param bool $flag
5761
* @return $this
62+
* @deprecated SID query parameter is not used in URLs anymore.
5863
*/
5964
public function setUseSessionInUrl($flag = true);
6065

6166
/**
6267
* Retrieve use session in URL flag
6368
*
6469
* @return bool
70+
* @deprecated SID query parameter is not used in URLs anymore.
6571
* @SuppressWarnings(PHPMD.BooleanGetMethodName)
6672
*/
6773
public function getUseSessionInUrl();

0 commit comments

Comments
 (0)