Repository navigation
fix(backchannel-logout): end every Nextcloud session of an IdP session - #1652
Draft
kevinveenbirkenbach wants to merge 1 commit into
Draft
kevinveenbirkenbach wants to merge 1 commit into
kevinveenbirkenbach wants to merge 1 commit into
Conversation
The sessions table kept one row per IdP sid (unique index) and every login overwrote it. When several Nextcloud sessions share one IdP session (the same browser on two Nextcloud hostnames, or a provider without sid where every login is stored as fallback-sid), a back-channel logout only ended the latest one and the others stayed valid. Store one row per Nextcloud session instead: drop the unique index on sid (keep a non-unique one), let createOrUpdateSession update only the row of the same Nextcloud session, and make the back-channel logout end every session matching sid (+sub+iss). Fixes nextcloud#1585 See nextcloud#1585 (comment) Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Kevin Veen-Birkenbach <kevin@veen.world>
kevinveenbirkenbach
added a commit
to kevinveenbirkenbach/infinito-nexus-core
that referenced
this pull request
Dec 1, 2026
…tream merges it user_oidc v8.13.0 (the latest release) keeps one session row per Keycloak sid and overwrites it on every login, so a Keycloak logout leaves the Nextcloud session of the first hostname valid when one browser signed in on the clearnet and the onion hostname. PR 2006 run 46505065135, job Nextcloud#13, failed this way in all six attempts. Tracked in infinito-nexus#3234, upstream nextcloud/user_oidc#1585, fix nextcloud/user_oidc#1652. Operator order: run the fix until the upstream PR is merged, then fail so the role returns to the plain app-store user_oidc. - NEXTCLOUD_USER_OIDC_PIN in vars/main.yml is the one place naming the PR, the commit 8aa43931 on the operator's fork kevinveenbirkenbach/user_oidc, the base release 8.13.0 and the three changed files with their sha256. - tasks/addons/user_oidc_pin.yml downloads each file at that commit with a sha256 check, overlays it on the installed app through files/shell/utils/overlay_pinned_app.sh, which refuses any installed release other than 8.13.0, and runs the new migration through Nextcloud's MigrationService (files/php/utils/migrate_app.php), because occ migrations:execute only exists in debug mode. - user_oidc is held back from app-store updates while it is the selected plugin. - The upstream directive above the pin makes tests/external/repository/test_upstream_references.py fail once the PR closes. - The Playwright spec proves the back-channel logout per network and, restored, across networks in one browser. Requirement 094 names the pin and keeps its box open until CI proves it. Tests: test_user_oidc_pin.py, test_overlay_pinned_app.py and test_user_oidc_provider.py green, the trip-wire passes today and fails against the merged PR 1184 (negative control), lint-javascript, lint-playwright, lint-markdown, lint-shellcheck and lint-ansible green, the fork files re-fetched and matched against the pinned sha256. 🎯 Fix: 85 % 💥 Break: 8 % 💸 Tokens: 100 % ⏱️ Velocity: 100 % 🛡️ Security: 100 % 🏆 Score: 85 🚦 Gate: ❌ quality-high on IAM pending Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
What
Back-channel logout now ends every Nextcloud session that belongs to the IdP session, not only the latest one.
user_oidc_sessionsstores one row per Nextcloud session. A new migration (Version081301Date20261201120000) drops the unique index onsidand adds a non-unique indexuser_oidc_sess_sid_idx. The unique index onnc_session_idstays.SessionMapper::createOrUpdateSession()updates the row of the same Nextcloud session (nc_session_id) if there is one and inserts a new row otherwise. Before, it overwrote the row of the samesid.SessionMapper::findSessionBySid()is nowfindSessionsBySid()and returns all matching sessions.LoginController::backChannelLogout()ends all of them, as thesub+issbranch already did.tests/unit/Db/SessionMapperTest.php: several sessions with the samesid, an update of the same Nextcloud session, andfallback-sidsessions of different users.Why
The unique
sidindex assumed that one IdP session maps to one Nextcloud session. That is not always true:sid. Keycloak's back-channel logout gets200 []from Nextcloud, but only the latest Nextcloud session is ended. The other one stays valid. Details: Back-channel logout withsubonly ends just the latest session: logins withoutsidoverwrite onefallback-sidrecord #1585 (comment)sid(Back-channel logout withsubonly ends just the latest session: logins withoutsidoverwrite onefallback-sidrecord #1585): every login is stored asfallback-sid, so logins overwrite each other, even across users. Asub-only logout token then ends only the latest login, andTokenInvalidatedListenercannot find the overwritten sessions.With one row per Nextcloud session, both lookup paths (
sid[+sub]+iss, andsub+iss) find every session.TokenInvalidatedListeneralready looks rows up by auth token, so it works again for every session without changes.How tested
php -l(PHP 8.3) on all changed files: no syntax errors.composer cs:check(php-cs-fixer, repo config) on the changed files: clean.psalm --no-cache: no new issues. The reported errors are already onmain(LoginControllerfallback-issRedundantCondition,Localefrom the missing intl extension in my local container).tests/bootstrap.phpsetup), so it runs in this PR's CI.Notes for review
sidno longer replace each other. Old rows are removed by back-channel logout, byTokenInvalidatedListener, by the single logout endpoint, or by the dailyCleanupSessionsjob (created_atolder than the session/remember-me lifetime). So the table holds at most one row per live Nextcloud login.user_oidc_sessions, a table that the daily job keeps short. It does not touch any data.appinfo/info.xml. Without the migration, the uniquesidindex is still there and a second login with the samesidfails on insert.Fixes #1585
🤖 Generated with Claude Code