Skip to content

Commit f75d5a3

Browse files
authored
[5.4] Fix deprecated cookie set method calls (joomla#45728)
Fix deprecated parameters in cookie set method calls
1 parent e1543c9 commit f75d5a3

File tree

4 files changed

+81
-25
lines changed

4 files changed

+81
-25
lines changed

libraries/src/Session/Storage/JoomlaStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ public function start(): void
306306

307307
if ($session_clean) {
308308
$this->setId($session_clean);
309-
$cookie->set($session_name, '', time() - 3600);
309+
$cookie->set($session_name, '', ['expires' => time() - 3600 ]);
310310
}
311311
}
312312

plugins/authentication/cookie/src/Extension/Cookie.php

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,15 @@ public function onUserAuthenticate(AuthenticationEvent $event): void
112112
// Check for valid cookie value
113113
if (\count($cookieArray) !== 2) {
114114
// Destroy the cookie in the browser.
115-
$app->getInput()->cookie->set($cookieName, '', 1, $app->get('cookie_path', '/'), $app->get('cookie_domain', ''));
115+
$app->getInput()->cookie->set(
116+
$cookieName,
117+
'',
118+
[
119+
'expires' => 1,
120+
'path' => $app->get('cookie_path', '/'),
121+
'domain' => $app->get('cookie_domain', ''),
122+
]
123+
);
116124
Log::add('Invalid cookie detected.', Log::WARNING, 'error');
117125

118126
return;
@@ -159,7 +167,15 @@ public function onUserAuthenticate(AuthenticationEvent $event): void
159167

160168
if (\count($results) !== 1) {
161169
// Destroy the cookie in the browser.
162-
$app->getInput()->cookie->set($cookieName, '', 1, $app->get('cookie_path', '/'), $app->get('cookie_domain', ''));
170+
$app->getInput()->cookie->set(
171+
$cookieName,
172+
'',
173+
[
174+
'expires' => 1,
175+
'path' => $app->get('cookie_path', '/'),
176+
'domain' => $app->get('cookie_domain', ''),
177+
]
178+
);
163179
$response->status = Authentication::STATUS_FAILURE;
164180

165181
return;
@@ -189,7 +205,15 @@ public function onUserAuthenticate(AuthenticationEvent $event): void
189205
}
190206

191207
// Destroy the cookie in the browser.
192-
$app->getInput()->cookie->set($cookieName, '', 1, $app->get('cookie_path', '/'), $app->get('cookie_domain', ''));
208+
$app->getInput()->cookie->set(
209+
$cookieName,
210+
'',
211+
[
212+
'expires' => 1,
213+
'path' => $app->get('cookie_path', '/'),
214+
'domain' => $app->get('cookie_domain', ''),
215+
]
216+
);
193217

194218
// Issue warning by email to user and/or admin?
195219
Log::add(Text::sprintf('PLG_AUTHENTICATION_COOKIE_ERROR_LOG_LOGIN_FAILED', $results[0]->user_id), Log::WARNING, 'security');
@@ -273,7 +297,15 @@ public function onUserAfterLogin(AfterLoginEvent $event): void
273297
$cookieValue = $app->getInput()->cookie->get($oldCookieName);
274298

275299
// Destroy the old cookie in the browser
276-
$app->getInput()->cookie->set($oldCookieName, '', 1, $app->get('cookie_path', '/'), $app->get('cookie_domain', ''));
300+
$app->getInput()->cookie->set(
301+
$oldCookieName,
302+
'',
303+
[
304+
'expires' => 1,
305+
'path' => $app->get('cookie_path', '/'),
306+
'domain' => $app->get('cookie_domain', ''),
307+
]
308+
);
277309
}
278310

279311
$cookieArray = explode('.', $cookieValue);
@@ -328,11 +360,13 @@ public function onUserAfterLogin(AfterLoginEvent $event): void
328360
$app->getInput()->cookie->set(
329361
$cookieName,
330362
$cookieValue,
331-
time() + $lifetime,
332-
$app->get('cookie_path', '/'),
333-
$app->get('cookie_domain', ''),
334-
$app->isHttpsForced(),
335-
true
363+
[
364+
'expires' => time() + $lifetime,
365+
'path' => $app->get('cookie_path', '/'),
366+
'domain' => $app->get('cookie_domain', ''),
367+
'secure' => $app->isHttpsForced(),
368+
'httponly' => true,
369+
]
336370
);
337371

338372
$query = $db->getQuery(true);
@@ -421,6 +455,14 @@ public function onUserAfterLogout(AfterLogoutEvent $event): void
421455
}
422456

423457
// Destroy the cookie
424-
$app->getInput()->cookie->set($cookieName, '', 1, $app->get('cookie_path', '/'), $app->get('cookie_domain', ''));
458+
$app->getInput()->cookie->set(
459+
$cookieName,
460+
'',
461+
[
462+
'expires' => 1,
463+
'path' => $app->get('cookie_path', '/'),
464+
'domain' => $app->get('cookie_domain', ''),
465+
]
466+
);
425467
}
426468
}

plugins/system/logout/src/Extension/Logout.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ public function __construct(DispatcherInterface $dispatcher, array $config, CMSA
5353
$this->getApplication()->getInput()->cookie->set(
5454
$hash,
5555
'',
56-
1,
57-
$this->getApplication()->get('cookie_path', '/'),
58-
$this->getApplication()->get('cookie_domain', '')
56+
[
57+
'expires' => 1,
58+
'path' => $this->getApplication()->get('cookie_path', '/'),
59+
'domain' => $this->getApplication()->get('cookie_domain', ''),
60+
]
5961
);
6062
}
6163
}
@@ -90,11 +92,13 @@ public function onUserLogout(LogoutEvent $event): void
9092
$this->getApplication()->getInput()->cookie->set(
9193
ApplicationHelper::getHash('PlgSystemLogout'),
9294
true,
93-
time() + 86400,
94-
$this->getApplication()->get('cookie_path', '/'),
95-
$this->getApplication()->get('cookie_domain', ''),
96-
$this->getApplication()->isHttpsForced(),
97-
true
95+
[
96+
'expires' => time() + 86400,
97+
'path' => $this->getApplication()->get('cookie_path', '/'),
98+
'domain' => $this->getApplication()->get('cookie_domain', ''),
99+
'secure' => $this->getApplication()->isHttpsForced(),
100+
'httponly' => true,
101+
]
98102
);
99103
}
100104
}

plugins/user/joomla/src/Extension/Joomla.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,13 @@ public function onUserLogin(LoginEvent $event)
361361
$this->getApplication()->getInput()->cookie->set(
362362
'joomla_user_state',
363363
'logged_in',
364-
0,
365-
$this->getApplication()->get('cookie_path', '/'),
366-
$this->getApplication()->get('cookie_domain', ''),
367-
$this->getApplication()->isHttpsForced(),
368-
true
364+
[
365+
'expires' => 0,
366+
'path' => $this->getApplication()->get('cookie_path', '/'),
367+
'domain' => $this->getApplication()->get('cookie_domain', ''),
368+
'secure' => $this->getApplication()->isHttpsForced(),
369+
'httponly' => true,
370+
]
369371
);
370372
}
371373
}
@@ -415,7 +417,15 @@ public function onUserLogout(LogoutEvent $event)
415417

416418
// Delete "user state" cookie used for reverse caching proxies like Varnish, Nginx etc.
417419
if ($this->getApplication()->isClient('site')) {
418-
$this->getApplication()->getInput()->cookie->set('joomla_user_state', '', 1, $this->getApplication()->get('cookie_path', '/'), $this->getApplication()->get('cookie_domain', ''));
420+
$this->getApplication()->getInput()->cookie->set(
421+
'joomla_user_state',
422+
'',
423+
[
424+
'expires' => 1,
425+
'path' => $this->getApplication()->get('cookie_path', '/'),
426+
'domain' => $this->getApplication()->get('cookie_domain', ''),
427+
]
428+
);
419429
}
420430
}
421431

0 commit comments

Comments
 (0)