Skip to content

fix(backchannel-logout): end every Nextcloud session of an IdP session - #1652

Draft
kevinveenbirkenbach wants to merge 1 commit into
nextcloud:mainfrom
kevinveenbirkenbach:fix/backchannel-logout-every-session
Draft

kevinveenbirkenbach wants to merge 1 commit into
nextcloud:mainfrom
kevinveenbirkenbach:fix/backchannel-logout-every-session

Conversation

@kevinveenbirkenbach

Copy link
Copy Markdown

What

Back-channel logout now ends every Nextcloud session that belongs to the IdP session, not only the latest one.

  • user_oidc_sessions stores one row per Nextcloud session. A new migration (Version081301Date20261201120000) drops the unique index on sid and adds a non-unique index user_oidc_sess_sid_idx. The unique index on nc_session_id stays.
  • 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 same sid.
  • SessionMapper::findSessionBySid() is now findSessionsBySid() and returns all matching sessions. LoginController::backChannelLogout() ends all of them, as the sub+iss branch already did.
  • New tests/unit/Db/SessionMapperTest.php: several sessions with the same sid, an update of the same Nextcloud session, and fallback-sid sessions of different users.

Why

The unique sid index assumed that one IdP session maps to one Nextcloud session. That is not always true:

  1. One browser logs in to Nextcloud on two hostnames (here a clearnet and an onion name) through one Keycloak session, so both logins share one sid. Keycloak's back-channel logout gets 200 [] from Nextcloud, but only the latest Nextcloud session is ended. The other one stays valid. Details: Back-channel logout with sub only ends just the latest session: logins without sid overwrite one fallback-sid record #1585 (comment)
  2. Providers that do not send a sid (Back-channel logout with sub only ends just the latest session: logins without sid overwrite one fallback-sid record #1585): every login is stored as fallback-sid, so logins overwrite each other, even across users. A sub-only logout token then ends only the latest login, and TokenInvalidatedListener cannot find the overwritten sessions.

With one row per Nextcloud session, both lookup paths (sid[+sub]+iss, and sub+iss) find every session. TokenInvalidatedListener already 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 on main (LoginController fallback-iss RedundantCondition, Locale from the missing intl extension in my local container).
  • The new PHPUnit test needs a Nextcloud server with a database (the tests/bootstrap.php setup), so it runs in this PR's CI.

Notes for review

  • Behaviour change: logins that share a sid no longer replace each other. Old rows are removed by back-channel logout, by TokenInvalidatedListener, by the single logout endpoint, or by the daily CleanupSessions job (created_at older than the session/remember-me lifetime). So the table holds at most one row per live Nextcloud login.
  • The migration only swaps an index on user_oidc_sessions, a table that the daily job keeps short. It does not touch any data.
  • I named the migration after a 8.13.1 release. Please rename it if the fix goes into a different version. The code and the migration have to ship together with a version bump in appinfo/info.xml. Without the migration, the unique sid index is still there and a second login with the same sid fails on insert.

Fixes #1585

🤖 Generated with Claude Code

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Back-channel logout with sub only ends just the latest session: logins without sid overwrite one fallback-sid record

1 participant