Repository navigation
fix: verify an auth module session with the module that established it - #41967
Open
oc-tmueller wants to merge 3 commits into
Open
oc-tmueller wants to merge 3 commits into
oc-tmueller wants to merge 3 commits into
Conversation
verifyAuthHeaders() handed the request's credential to every auth module on each request of an existing session. A module that does not know the credential may check it remotely: openidconnect introspects every opaque bearer token at the identity provider, so each OCS and web request of a client using a local oauth2 token cost two failing IdP round trips. tryAuthModuleLogin() now records the module that established the session, and verifyAuthHeaders() asks that module first. If it confirms the session user the request is verified, which is what the DAV auth backends already do; in every other case all modules are asked exactly as before. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Thomas Müller <[email protected]>
Address review of the session auth module shortcut: - the built-in TokenAuthModule and BasicAuthModule are still asked after the session module confirmed the user, so a conflicting app password or basic auth credential still ends the session; only the other app modules, which are the remote and expensive ones, are skipped - the session module is asked first in the regular loop instead of in a separate pass, so it is not called twice when it does not confirm - every login forgets the recorded module, so a session re-established by another path is not vouched for by the module of an earlier login Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Thomas Müller <[email protected]>
Address the second review round: - record the user together with the module, and only trust the module while that user is still the session user; some paths switch the session user with setUser() alone and never reach loginInOwnCloud() - put the session module behind the built-in TokenAuthModule, so a conflicting app password still ends the session before any app module is asked, as before - let the test double honour $includeBuiltIn, so the tests fail when the built-in modules drop out of the check - describe in the changelog that the built-in checks still apply Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Thomas Müller <[email protected]>
Closed
5 of 12 tasks
jvillafanez
reviewed
Nov 5, 2026
| * @return IAuthModule[] | ||
| * @throws Exception | ||
| */ | ||
| private function getAuthModulesForSession($sessionModuleClass) { |
Member
There was a problem hiding this comment.
How about
private function getAuthModulesForSession($sessionModuleClass) {
$modules = [null];
foreach ($this->getAuthModules(true) as $mod) {
if (get_class($mod) === $sessionModuleClass) {
$r[0] = $mod;
} else {
$r[] = $mod;
}
}
if ($modules[0] === null) {
array_shift($modules);
}
return $modules;
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Session::verifyAuthHeaders()hands the credential of an established session to every auth module on each request. A module that doesn't know the credential may check it remotely. openidconnect introspects every opaque bearer token at the identity provider. So a client that keeps its session cookie and authenticates with a local OAuth2 token (the desktop and mobile clients) cost two failing IdP round trips per OCS and web request: an introspection that answersactive: falseand a discovery fetch. The OAuth2 module authenticated the request anyway.The DAV auth backends already avoid this. Once a session is DAV-authenticated, each backend re-checks the token only with its own module. This PR does the same in core for all requests:
tryAuthModuleLogin()records the module that established the session, together with the user.verifyAuthHeaders()asks that module right after the built-inTokenAuthModule. Once it confirms the session user, the other app modules are skipped. The built-inTokenAuthModuleandBasicAuthModuleare local and still have to agree.null, or an exception. The recorded module is also ignored once the session user has changed, and every login clears it.No app has to know about another app, and openidconnect/oauth2 need no change.
Motivation and Context
A customer reported a large rise in requests to their SSO after enabling openidconnect next to oauth2 on 11.0.1. See also owncloud/openidconnect#338 and the analysis in owncloud/openidconnect#377.
How Has This Been Tested?
tests/lib/User284/284 on PHP 8.3. New tests for each guard: built-in modules still asked, token auth still first, module asked only once on fallback, uid binding, the key cleared on login and recorded on module login. Each was mutation-checked: removing the guard fails exactly its test.Types of changes
Checklist:
🤖 Generated with Claude Code