Метод invalidateCurrentGuestSession
Расположение
Исходный файл метода в Bitrix Framework
~/bitrix/modulesim/lib/V2/Guest/Auth/AuthorizationService.php
Исходный код
Сигнатура метода
public function invalidateCurrentGuestSession(): void
Возвращает:
void
Описание
Ends a guest session for good: drop server-side auth and clear the guest cookies WITHOUT calling Logout(). Cookies must go with the auth slot: a leftover BITRIX_IM_GUEST_HASH would re-authenticate the guest. To end it while the guest stays themselves, use {@see self::suspendCurrentGuestSession}. Logout() is off limits for the whole guest contour, for two independent reasons: 1. The messenger fires a burst of concurrent requests, so the hot per-request guard ({@see \Bitrix\Im\V2\Controller\Filter\AuthorizationPrefilter}) must not call Logout(): Logout()→regenerateId() rotates the file-backed session, and concurrent rotations of the same session race and make session_start() throw ("Could not start session by PHP"). 2. Every guest path that ends a session runs inside the guest's own request, which owes a machine-readable response. Logout() raises main:OnAfterUserLogout, and on the cloud its bitrix24 subscriber answers with LocalRedirect to OAuth — the response body never ships. Server-side auth is still dropped: leaving SESS_AUTH in place keeps the guest authorized for auth-only endpoints outside the im guard (e.g. ui.entityselector), so a revoked guest could keep querying them until the session expires. Clearing SESS_AUTH is idempotent under the burst, unlike regenerateId() — so we deauthorize but skip the rotation. Consequence to keep in mind: the CUser object of the CURRENT request stays authorized, because only the session slot is cleared and CUser::$context survives. The next request (a fresh CUser) is unauthorized.