|
MediaWiki master
|
This serves as the entry point to the MediaWiki session handling system. More...
Inherits MediaWiki\Session\SessionManagerInterface.

Public Member Functions | ||||||||||
| __construct (Config $config, LoggerInterface $logger, CentralIdLookup $centralIdLookup, HookContainer $hookContainer, ObjectFactory $objectFactory, ProxyLookup $proxyLookup, UrlUtils $urlUtils, UserNameUtils $userNameUtils, SessionStore $sessionStore) | ||||||||||
| getAllOpenApiSecuritySchemes () | ||||||||||
| Gathers the OpenAPI security schemes from all registered SessionProviders. | ||||||||||
| getEmptySession (?WebRequest $request=null) | ||||||||||
Create a new, empty session.The first provider configured that is able to provide an empty session will be used.
| ||||||||||
| getJwtData (UserIdentity $user) | ||||||||||
| Return a set of key-value pairs applicable for use as claims in a JSON Web Token. | ||||||||||
| getSessionById ( $id, $create=false, ?WebRequest $request=null) | ||||||||||
Fetch a session by ID.
| ||||||||||
| getSessionForRequest (WebRequest $request) | ||||||||||
Fetch the session for a request (or a new empty session if none is attached to it)
\OverflowException if there are multiple sessions tied for top priority in the request. Exception has a property "sessionInfos" holding the SessionInfo objects for the sessions involved. | ||||||||||
| getVaryCookies () | ||||||||||
Return the list of cookies that need varying on.
| ||||||||||
| getVaryHeaders () | ||||||||||
| invalidateSessionsForUser (User $user) | ||||||||||
| Invalidate sessions for a user. | ||||||||||
| setHookContainer (HookContainer $hookContainer) | ||||||||||
| setLogger (LoggerInterface $logger) | ||||||||||
| validateJwtSubject (array $jwtData, UserIdentity $user) | ||||||||||
| Partially validate JWT data that's presumed to be generated by getJwtData(). | ||||||||||
Static Public Member Functions | |
| static | getGlobalSession () |
| static | validateSessionId ( $id) |
| Validate a session ID. | |
Internal methods | |
| preventSessionsForUser ( $username) | |
| Prevent future sessions for the user. | |
| isUserSessionPrevented ( $username) | |
| Test if a user is prevented. | |
| getProvider ( $name) | |
| Get a session provider by name. | |
| shutdown () | |
| Save all active sessions on shutdown. | |
| getSessionFromInfo (SessionInfo $info, WebRequest $request) | |
| Create a Session corresponding to the passed SessionInfo. | |
| changeBackendId (SessionBackend $backend) | |
| Change a SessionBackend's ID. | |
| generateSessionId () | |
| Generate a new random session ID. | |
| logPotentialSessionLeakage (?Session $session=null) | |
| Write debug logs if the current request may have experienced session leak bug. | |
| getProviders () | |
| Get the available SessionProviders. | |
This serves as the entry point to the MediaWiki session handling system.
Most methods here are for internal use by session handling code. Other callers should only use the methods of SessionManagerInterface; the rest of the functionality is exposed via MediaWiki\Session\Session methods, which can be accessed from WebRequest::getSession().
To provide custom session handling, implement a MediaWiki\Session\SessionProvider.
See SessionStore Storage expectations.
Definition at line 54 of file SessionManager.php.
| MediaWiki\Session\SessionManager::__construct | ( | Config | $config, |
| LoggerInterface | $logger, | ||
| CentralIdLookup | $centralIdLookup, | ||
| HookContainer | $hookContainer, | ||
| ObjectFactory | $objectFactory, | ||
| ProxyLookup | $proxyLookup, | ||
| UrlUtils | $urlUtils, | ||
| UserNameUtils | $userNameUtils, | ||
| SessionStore | $sessionStore ) |
Definition at line 104 of file SessionManager.php.
| MediaWiki\Session\SessionManager::changeBackendId | ( | SessionBackend | $backend | ) |
Change a SessionBackend's ID.
| SessionBackend | $backend |
Definition at line 1025 of file SessionManager.php.
References MediaWiki\Session\SessionBackend\getSessionId().
| MediaWiki\Session\SessionManager::generateSessionId | ( | ) |
| MediaWiki\Session\SessionManager::getAllOpenApiSecuritySchemes | ( | ) |
Gathers the OpenAPI security schemes from all registered SessionProviders.
Iterates through all active session providers (from both Core and Extensions) and collects their OpenAPI security scheme definitions. Each scheme key is auto-generated from the provider's name (its string representation, which defaults to the fully qualified PHP class name, with backslashes replaced by hyphens), followed by a hyphen and the scheme-specific suffix returned by the provider. Using the provider's name keeps keys unique even if two providers share the same class, matching the uniqueness guarantee SessionManager enforces on provider names.
Example: CookieSessionProvider returning [ 'Session' => [...] ] produces the key "MediaWiki-Session-CookieSessionProvider-Session" in the returned array.
Implements MediaWiki\Session\SessionManagerInterface.
Definition at line 352 of file SessionManager.php.
| MediaWiki\Session\SessionManager::getEmptySession | ( | ?WebRequest | $request = null | ) |
Create a new, empty session.The first provider configured that is able to provide an empty session will be used.
| WebRequest | null | $request | Corresponding request. Any existing session associated with this WebRequest object will be overwritten. |
Implements MediaWiki\Session\SessionManagerInterface.
Definition at line 194 of file SessionManager.php.
References $request.
|
static |
Definition at line 100 of file SessionManager.php.
| MediaWiki\Session\SessionManager::getJwtData | ( | UserIdentity | $user | ) |
Return a set of key-value pairs applicable for use as claims in a JSON Web Token.
This can be used to standardize some session credentials as JWTs. It is up to individual session providers whether and how to use JWTs, but if they use them, they should make use of this mechanism so that infrastructure outside MediaWiki that makes use of such JWTs can be standardized.
Providers which call this method are free to extend or replace the values whenever that makes sense, but are encouraged to add at least the following fields:
| UserIdentity | $user | The user who is the subject of the claim. |
Implements MediaWiki\Session\SessionManagerInterface.
Definition at line 393 of file SessionManager.php.
| MediaWiki\Session\SessionManager::getProvider | ( | $name | ) |
Get a session provider by name.
Generally, this will only be used by internal implementation of some special session-providing mechanism. General purpose code, if it needs to access a SessionProvider at all, will use Session::getProvider().
| string | $name |
Definition at line 573 of file SessionManager.php.
|
protected |
Get the available SessionProviders.
Definition at line 538 of file SessionManager.php.
| MediaWiki\Session\SessionManager::getSessionById | ( | $id, | |
| $create = false, | |||
| ?WebRequest | $request = null ) |
Fetch a session by ID.
| string | $id | |
| bool | $create | If no session exists for $id, try to create a new one. May still return null if a session for $id exists but cannot be loaded. |
| WebRequest | null | $request | Corresponding request. Any existing session associated with this WebRequest object will be overwritten. |
Implements MediaWiki\Session\SessionManagerInterface.
Definition at line 153 of file SessionManager.php.
References $request.
| MediaWiki\Session\SessionManager::getSessionForRequest | ( | WebRequest | $request | ) |
Fetch the session for a request (or a new empty session if none is attached to it)
| WebRequest | $request | Any existing associated session will be reset to the session corresponding to the data in the request itself. |
\OverflowException if there are multiple sessions tied for top priority in the request. Exception has a property "sessionInfos" holding the SessionInfo objects for the sessions involved.
Implements MediaWiki\Session\SessionManagerInterface.
Definition at line 140 of file SessionManager.php.
References $request.
| MediaWiki\Session\SessionManager::getSessionFromInfo | ( | SessionInfo | $info, |
| WebRequest | $request ) |
Create a Session corresponding to the passed SessionInfo.
| SessionInfo | $info | |
| WebRequest | $request |
Definition at line 964 of file SessionManager.php.
References $request, MediaWiki\Session\SessionInfo\getId(), MediaWiki\Session\SessionInfo\isIdSafe(), MW_ENTRY_POINT, MW_NO_SESSION, MediaWiki\Session\SessionInfo\needsRefresh(), MediaWiki\Session\SessionInfo\wasPersisted(), and MediaWiki\Session\SessionInfo\wasRemembered().
| MediaWiki\Session\SessionManager::getVaryCookies | ( | ) |
Return the list of cookies that need varying on.
Implements MediaWiki\Session\SessionManagerInterface.
Definition at line 318 of file SessionManager.php.
References MW_NO_SESSION.
| MediaWiki\Session\SessionManager::getVaryHeaders | ( | ) |
Implements MediaWiki\Session\SessionManagerInterface.
Definition at line 299 of file SessionManager.php.
References MW_NO_SESSION.
| MediaWiki\Session\SessionManager::invalidateSessionsForUser | ( | User | $user | ) |
Invalidate sessions for a user.
After calling this, existing sessions should be invalid. For mutable session providers, this generally means the user has to log in again; for immutable providers, it generally means the loss of session data.
Implements MediaWiki\Session\SessionManagerInterface.
Definition at line 282 of file SessionManager.php.
References $request, MediaWiki\User\User\getName(), MediaWiki\User\User\saveSettings(), and MediaWiki\User\User\setToken().
| MediaWiki\Session\SessionManager::isUserSessionPrevented | ( | $username | ) |
Test if a user is prevented.
| string | $username |
Definition at line 530 of file SessionManager.php.
| MediaWiki\Session\SessionManager::logPotentialSessionLeakage | ( | ?Session | $session = null | ) |
Write debug logs if the current request may have experienced session leak bug.
If the same session is suddenly used from a different IP, that's potentially due to a session leak bug, so log it for investigation. In most cases, these are false positives simply due to a user switching connections. Noisy logs are fine, because we only use this audit trail by looking up a specific username.
This also logs for unexpected changes to the "mwuser" cookie, an analytics cookie set from mediawiki.user.js, which should be a little less noisy.
| Session | null | $session | For testing only |
Definition at line 1086 of file SessionManager.php.
| MediaWiki\Session\SessionManager::preventSessionsForUser | ( | $username | ) |
Prevent future sessions for the user.
The intention is that the named account will never again be usable for normal login (i.e. there is no way to undo the prevention of access).
| string | $username |
Definition at line 515 of file SessionManager.php.
| MediaWiki\Session\SessionManager::setHookContainer | ( | HookContainer | $hookContainer | ) |
| HookContainer | $hookContainer |
Definition at line 134 of file SessionManager.php.
| MediaWiki\Session\SessionManager::setLogger | ( | LoggerInterface | $logger | ) |
Definition at line 126 of file SessionManager.php.
| MediaWiki\Session\SessionManager::shutdown | ( | ) |
Save all active sessions on shutdown.
Definition at line 583 of file SessionManager.php.
| MediaWiki\Session\SessionManager::validateJwtSubject | ( | array | $jwtData, |
| UserIdentity | $user ) |
Partially validate JWT data that's presumed to be generated by getJwtData().
| array | $jwtData | Claim data in the JWT (the full set, not just the subject). Callers should obtain it via JwtCodec, this method doesn't duplicate the checks there. |
| UserIdentity | $user | Validation will only succeed if this user is the subject. Can be anonymous. |
| JwtException | on invalid data |
Definition at line 439 of file SessionManager.php.
|
static |
Validate a session ID.
| string | $id |
Definition at line 498 of file SessionManager.php.
Referenced by MediaWiki\Session\SessionInfo\__construct(), MediaWiki\Session\ImmutableSessionProviderWithCookie\getSessionIdFromCookie(), and MediaWiki\Session\CookieSessionProvider\provideSessionInfo().