Skip to content

Commit ef67329

Browse files
Auth: Don't send HTTP cookies in non-HTTP processes
1 parent 5d879ce commit ef67329

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

Services/Authentication/classes/class.ilSession.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -287,16 +287,21 @@ public static function _destroy($a_session_id, ?int $a_closing_context = null, $
287287

288288
$ilDB->manipulate($q);
289289

290-
try {
291-
// only delete session cookie if it is set in the current request
292-
if ($DIC->http()->wrapper()->cookie()->has(session_name()) &&
293-
$DIC->http()->wrapper()->cookie()->retrieve(session_name(), $DIC->refinery()->kindlyTo()->string()) === $a_session_id) {
294-
$cookieJar = $DIC->http()->cookieJar()->without(session_name());
295-
$cookieJar->renderIntoResponseHeader($DIC->http()->response());
290+
if (ilContext::usesHTTP()) {
291+
try {
292+
// only delete session cookie if it is set in the current request
293+
if ($DIC->http()->wrapper()->cookie()->has(session_name()) &&
294+
$DIC->http()->wrapper()->cookie()->retrieve(
295+
session_name(),
296+
$DIC->refinery()->kindlyTo()->string()
297+
) === $a_session_id) {
298+
$cookieJar = $DIC->http()->cookieJar()->without(session_name());
299+
$cookieJar->renderIntoResponseHeader($DIC->http()->response());
300+
}
301+
} catch (\Throwable $e) {
302+
// ignore
303+
// this is needed for "header already" sent errors when the random cleanup of expired sessions is triggered
296304
}
297-
} catch (\Throwable $e) {
298-
// ignore
299-
// this is needed for "header already" sent errors when the random cleanup of expired sessions is triggered
300305
}
301306

302307
return true;

0 commit comments

Comments
 (0)