Skip to content

feat(server-core): revoke sessions by the application that used them - #3401

Closed
tada5hi wants to merge 1 commit into
feat/account-console-session-bindingfrom
feat/session-used-client-revocation
Closed

tada5hi wants to merge 1 commit into
feat/account-console-session-bindingfrom
feat/session-used-client-revocation

Conversation

@tada5hi

@tada5hi tada5hi commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #3400. Base is feat/account-console-session-binding, because this builds on the auth_session_tokens.client_id column added there. Review or merge #3400 first; GitHub will retarget this to master automatically once it lands.

Problem

Sessions can only be found by auth_sessions.client_id, and #3400 makes that column write-once, so it names the client that first authorized on the row. One browser session serves several applications, so an operator revoking application X after a compromise misses every session X served but did not create.

Concretely, with the admin console opened first and the account console second, DELETE /sessions?filter[clientId]=<account-console> matches nothing. Before #3400 the column was last-writer-wins, so it matched — differently partial, but partial either way. Neither answers "every session this application served".

Change

GET and DELETE /sessions accept ?usedClientId=<id>, a single id or a comma list. A session matches when either

  • its own client_id names one of them (the client that first authorized), or
  • an EXISTS over auth_session_tokens.client_id finds a token issued for one of them.

Both reaches are needed. The column alone misses every later application; the EXISTS alone misses a session whose token rows have since been swept by the cleanup component.

Why a request parameter and not a rapiq filter

Inferring this from a user-supplied condition tree means deciding what a negated or OR-nested clientId means. On a bulk delete a wrong answer is a mass deletion, so the safe move is a parameter with exactly one meaning. It composes as a mandatory AND-ed bracket next to the existing owner constraint, so no client-supplied filter can widen it.

Its presence selects the admin bulk-revoke path on its own. Without that it would fall through to self-service and silently revoke the caller's own devices instead of the named application's sessions. That means it carries the same SESSION_DELETE gate and per-session realm match as any target filter — filter breadth still cannot escalate, so a realm_admin reaches only its own realm's sessions.

filter[clientId] is untouched and still matches the session column.

Verification

  • server-core 180/180 files, full suite green. check:types clean, ESLint clean.
  • New test in session-token-attribution.spec.ts pins the actual capability gap: with two applications on one browser session, filter[clientId]=<second app> does not return the session, usedClientId=<second app> does, and the revoke removes it.

Follow-up left open

The account console's Applications page revokes consent, which is prompt-level: it stops the next silent issue and leaves live tokens working. It could now offer a real "sign out of this application everywhere" by calling this endpoint. Not done here, and note the page lists consent rows, which authorization/module.ts:57 skips for builtIn clients, so neither console appears there.

Copilot AI lite review requested due to automatic review settings August 5, 2026 06:59
@coderabbitai

coderabbitai Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 496b748a-f0f0-4692-a509-341b2abff20e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

authup

npm i https://pkg.pr.new/authup@3401

@authup/client-account-console

npm i https://pkg.pr.new/@authup/client-account-console@3401

@authup/client-admin-console

npm i https://pkg.pr.new/@authup/client-admin-console@3401

@authup/client-auth-console

npm i https://pkg.pr.new/@authup/client-auth-console@3401

@authup/server-core

npm i https://pkg.pr.new/@authup/server-core@3401

@authup/access

npm i https://pkg.pr.new/@authup/access@3401

@authup/client-web-kit

npm i https://pkg.pr.new/@authup/client-web-kit@3401

@authup/client-web-kit-theme

npm i https://pkg.pr.new/@authup/client-web-kit-theme@3401

@authup/client-web-nuxt

npm i https://pkg.pr.new/@authup/client-web-nuxt@3401

@authup/client-web-theme

npm i https://pkg.pr.new/@authup/client-web-theme@3401

@authup/core-http-kit

npm i https://pkg.pr.new/@authup/core-http-kit@3401

@authup/core-kit

npm i https://pkg.pr.new/@authup/core-kit@3401

@authup/core-realtime-kit

npm i https://pkg.pr.new/@authup/core-realtime-kit@3401

@authup/errors

npm i https://pkg.pr.new/@authup/errors@3401

@authup/i18n

npm i https://pkg.pr.new/@authup/i18n@3401

@authup/kit

npm i https://pkg.pr.new/@authup/kit@3401

@authup/server-adapter-kit

npm i https://pkg.pr.new/@authup/server-adapter-kit@3401

@authup/server-adapter-node

npm i https://pkg.pr.new/@authup/server-adapter-node@3401

@authup/server-adapter-socket-io

npm i https://pkg.pr.new/@authup/server-adapter-socket-io@3401

@authup/server-adapter-web

npm i https://pkg.pr.new/@authup/server-adapter-web@3401

@authup/server-kit

npm i https://pkg.pr.new/@authup/server-kit@3401

@authup/server-test-kit

npm i https://pkg.pr.new/@authup/server-test-kit@3401

@authup/specs

npm i https://pkg.pr.new/@authup/specs@3401

commit: 33e124e

@tada5hi
tada5hi force-pushed the feat/session-used-client-revocation branch from dc35461 to 0a42537 Compare August 5, 2026 07:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an explicit usedClientId query parameter to the sessions list and bulk-revoke endpoints so operators can target “every session that a given application served,” even when the session’s own clientId is write-once and only reflects the first authorizing client. This builds on the auth_session_tokens.client_id attribution introduced in the stacked base PR.

Changes:

  • Extend session listing (GET /sessions) to accept ?usedClientId=<id[,id...]> and apply it as a mandatory constraint.
  • Extend session bulk deletion (DELETE /sessions) so usedClientId alone selects the admin bulk-revoke path (permission-gated), applying the same constraint.
  • Add a unit test covering the gap where filter[clientId] cannot find sessions served (but not created) by a later application.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
apps/server-core/test/unit/http/controllers/workflows/token/session-token-attribution.spec.ts Adds coverage proving usedClientId finds and revokes sessions served by a second app on the same browser session.
apps/server-core/src/core/entities/session/types.ts Introduces SessionGetManyOptions.usedClientIds and threads usedClientIds through delete options.
apps/server-core/src/core/entities/session/service.ts Plumbs usedClientIds through getMany() and ensures usedClientId selects the admin bulk-delete path.
apps/server-core/src/core/authentication/session/types.ts Extends repository options to include usedClientIds and updates findAllByQuery signature accordingly.
apps/server-core/src/app/modules/authentication/repositories/session.ts Implements the (session.client_id IN ...) OR EXISTS(auth_session_tokens...) constraint via a bracketed AND clause.
apps/server-core/src/adapters/http/controllers/entities/session/module.ts Parses usedClientId (single / repeated / comma-list) and passes it to service methods for GET + DELETE.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tada5hi
tada5hi force-pushed the feat/account-console-session-binding branch from 29d7252 to 8363794 Compare August 5, 2026 07:35
Sessions could only be found by auth_sessions.client_id, which names the
client that first authorized on the row. One browser session serves several
applications, so an operator revoking application X after a compromise
missed every session X served but did not create.

GET and DELETE /sessions accept ?usedClientId=<id> (comma list supported),
matching the session's own client_id OR an EXISTS over
auth_session_tokens.client_id, which is where per-application attribution
lives. Both reaches are needed: the column alone misses later applications,
the EXISTS alone misses a session whose token rows have been swept.

It is a request parameter rather than a rapiq filter on purpose. Reading
intent out of a user-supplied condition tree would have to decide what a
negated or OR-nested clientId means, and on a bulk delete a wrong answer is
a mass deletion. Its presence selects the admin path on its own, so it
carries the same SESSION_DELETE gate and per-session realm match as any
target filter, and can never fall through to the self-service branch.
@tada5hi
tada5hi force-pushed the feat/session-used-client-revocation branch from 0a42537 to 33e124e Compare August 5, 2026 07:38
@tada5hi

tada5hi commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded by #3403, which carries this work in a single PR. The stack was split while the design was still moving; #3403 also drops the account console's SSO-realm reader, which could not work (nothing writes that cookie) and is tracked as an open decision there.

@tada5hi tada5hi closed this Aug 5, 2026
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.

2 participants