You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(web): JWT session versioning and credential revocation on org removal (#1168)
* feat(web): JWT session versioning and credential revocation on org removal
Adds a per-user `sessionVersion` integer to the `User` model. The version is
baked into every newly-minted JWT cookie via the `jwt` callback, copied onto
the session via the `session` callback, and verified on every read by a
wrapped `auth()` function that compares the cookie's claim against the
current DB value — mismatch returns null, treating the session as logged out
on the very next request.
Backwards compatible: pre-migration cookies have no claim and fall back to 0,
which matches the default User.sessionVersion of 0, so existing sessions
keep working until something explicitly bumps the user's version.
The `auth()` wrapper is memoized per-request via React `cache()` so the
extra DB read happens at most once per request even though `auth()` is
called from many places (layout, page, withAuth, getAuthenticatedUser).
`removeMemberFromOrg` and `leaveOrg` now run three credential-revocation
helpers inside the existing serializable transaction:
- `invalidateAllSessionsForUser` — bumps the version, killing every active
JWT cookie for the user on their next request.
- `revokeUserOAuthTokens` — deletes their `OAuthToken`,
`OAuthRefreshToken`, and `OAuthAuthorizationCode` rows. Not org-scoped
because OAuthClient has no `orgId`.
- `revokeUserApiKeysInOrg` — deletes their `ApiKey` rows scoped to the
current org (ApiKey.orgId).
Net effect: when an admin removes a member (or a member leaves), the user's
JWT cookie, personal API keys for that org, and OAuth tokens all stop
working atomically. A failed transaction rolls back all four changes.
* chore: add changelog entry for #1168
Copy file name to clipboardExpand all lines: CHANGELOG.md
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8
8
## [Unreleased]
9
9
10
10
### Added
11
-
-[EE] Added three new audit actions covering the full org membership lifecycle: `org.member_added`, `org.member_removed`, and `org.member_left`. [#1165](https://github.com/sourcebot-dev/sourcebot/pull/1165)
11
+
- Added three new audit actions covering the full org membership lifecycle: `org.member_added`, `org.member_removed`, and `org.member_left`. [#1165](https://github.com/sourcebot-dev/sourcebot/pull/1165)
12
+
- Added per-user JWT session versioning so admin-driven member removals (and voluntary leaves) invalidate the removed user's active JWT cookies, personal API keys, and OAuth tokens atomically on their next request. [#1168](https://github.com/sourcebot-dev/sourcebot/pull/1168)
0 commit comments