Skip to content

fix(#455): revoke the relayed fork session on account disable (fork half) - #49

Merged
PMQ9 merged 3 commits into
wiki-v2from
fix/455-fork-session-revoke-on-disable
Sep 22, 2026
Merged

PMQ9 merged 3 commits into
wiki-v2from
fix/455-fork-session-revoke-on-disable

Conversation

@PMQ9

@PMQ9 PMQ9 commented Sep 22, 2026

Copy link
Copy Markdown

TL;DR

The fork half of wiki-v2 docmost#455 (ADR 0023): the service-bridge surface + collab seam the platform calls to revoke a disabled identity's already-issued fork credential, plus the notifications-socket liveness gate. Pairs with the super-repo PR (which wires disable()/enable() and re-pins this gitlink); merge this first.

What this does

  • service-bridge — new session:revoke / session:restore scopes + POST /api/service/session/{revoke,restore}.
    • deactivateShadowUser(externalId): sets deactivatedAt + revokes the shadow user's user_sessions in one tx (idempotent, deactivatedAt only — never deletedAt), returns the resolved fork userId.
    • reactivateShadowUser(externalId): clears deactivatedAt on re-enable.
  • collab — node-local CollaborationGateway.forceDisconnectUser(userId) + POST /api/collab/force-disconnect-user (in the ESM-isolated CollabDisconnectModule), to force-close a deactivated user's live editor sockets.
  • ws.gateway — re-check isUserDisabled + the session row at socket-io connect (policy in authz/ws-connection/), so account disable / session revocation cut the notifications plane too.
  • OpenAPI contract + scope-coverage/contract specs updated; unit + real-PG specs added.

Why

Before this, a disabled platform identity kept a fork-native authToken that honored the wiki content plane (/api/*, collab, notifications) for the fork TTL (30–90d) — the platform kill never reached the fork. isUserDisabled (deactivatedAt) is the one predicate every fork content entrypoint already checks (jwt.strategy, onAuthenticate, mintSession.disqualify); this exposes it to the platform over the sanctioned east-west bridge. Full rationale: wiki-v2 issue 455 + ADR 0023.

How it works

disable() (super-repo) calls session/revoke → deactivate + revoke sessions → returns the fork userId → force-disconnect-user closes live collab sockets. Revoking user_sessions alone is insufficient (the 24h collab token carries no sessionId, so a pre-issued token opens new editors), which is why deactivatedAt is the lever. Node-local disconnect is complete at desired_count=1 (the fork hosts Hocuspocus in-process); multi-node needs an all-nodes RedisSync broadcast (follow-up). Native deactivateUser is deliberately not reused — its admin-context guards + "already deactivated" throw break the idempotent retry-before-enable contract.

Acceptance criteria

  • A deactivated shadow user fails mintSession (disqualify → isUserDisabled) and /api/* (jwt.strategy) — proven end-to-end against real Postgres.
  • reactivateShadowUser restores minting; deactivate/reactivate are idempotent + benign no-ops for a never-provisioned identity.
  • Notifications socket rejects a disabled/revoked identity at connect.
  • Upstream seams documented (super-repo UPSTREAM_MODIFICATIONS.md #3f, #161b); boundary check + import-boundary spec green.

Testing

  • service-bridge.service.spec.ts (deactivate/reactivate orchestration), service-bridge-revoke.pg.spec.ts (real-PG: deactivate → mint refused → reactivate → mint OK, session revoke, idempotency), ws-connection-live.spec.ts, collab-disconnect.controller.spec.ts (per-user disconnect + DTO), service-scope-coverage.spec.ts + service-bridge.contract.spec.ts (new scopes/routes ↔ OpenAPI).
  • Full fork typecheck: 0 errors. scripts/check-upstream-boundary.sh + import-boundary spec: green.

Risk & rollback

Additive: new scopes/routes/methods; no change to existing behavior. The shared secret auto-grants the new scopes (no credential change). Rollback = revert; the platform's fork call is fail-closed, so an un-deployed fork simply makes disable() 503 (retryable) rather than silently degrade.

Checklist

  • Tests added/updated and passing
  • Upstream-modification ledger updated (super-repo) + boundary check green
  • OpenAPI contract updated
  • Reviewed by a human

🤖 Generated with Claude Code

PMQ9 and others added 3 commits September 22, 2026 00:30
The fork half of docmost#455 (ADR 0023): the service-bridge surface + collab seam
the platform calls to revoke a disabled identity's already-issued fork
credential, and the notifications-socket liveness gate — so a disabled
identity cannot keep reading/writing wiki content through the fork.

- service-bridge: session:revoke / session:restore scopes + POST
  /api/service/session/{revoke,restore}. deactivateShadowUser sets
  deactivatedAt + revokes user_sessions in one tx (idempotent; deactivatedAt
  only, never deletedAt; reuses UserRepo/UserSessionRepo, never native
  deactivateUser whose "already deactivated" throw breaks retry). revoke
  returns the resolved fork userId so the platform can also disconnect collab.
  reactivateShadowUser clears deactivatedAt on re-enable.
- collab: node-local CollaborationGateway.forceDisconnectUser(userId) + POST
  /api/collab/force-disconnect-user (ESM-isolated CollabDisconnectModule).
  Complete at desired_count=1; an all-nodes RedisSync broadcast is a follow-up.
- ws.gateway: re-check isUserDisabled + the session row at connect (policy in
  authz/ws-connection/), closing the 30-90d notifications-socket residual.
- OpenAPI contract + scope-coverage/contract specs updated; unit + real-PG
  specs (deactivate -> mintSession refused round-trip) added.

Upstream seams documented in the super-repo UPSTREAM_MODIFICATIONS.md
(collaboration.gateway #3f, ws.gateway #161b).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…on-revoke-on-disable

# Conflicts:
#	apps/server/src/service-bridge/service-bridge.pg.spec.ts
#	apps/server/src/service-bridge/service-bridge.service.spec.ts
#	apps/server/src/service-bridge/service-bridge.service.ts
…e review gaps

Review round 1 (wiki-v2 docmost#477 / docmost #49):

- Security+Correctness (L3): force-close the already-open notifications
  socket.io connection on account disable. The connect-time
  isWsConnectionLive gate only refused NEW sockets, so a disabled user's
  already-open, ping-kept-alive feed kept streaming metadata (titles,
  tree moves/renames, comments) until it happened to reconnect. Add
  WsGateway.forceDisconnectUser (server.in(userRoom).disconnectSockets)
  and fan the /api/collab/force-disconnect-user seam out to BOTH the
  collab (Hocuspocus) and notifications (socket.io) planes.
- Architecture (L3): add a two-way liveness-parity fitness test pinning
  isWsConnectionLive == jwt.strategy.validate so a fail-open divergence
  reds CI, not just a prose comment.
- Testing (L3): extract the collab force-disconnect predicate into an
  importless authz/ helper (disconnectUserConnections) so the actual
  enforcement is unit-tested outside the lib0 ESM graph; the gateway
  method is now a thin delegate. Add a WsGateway.forceDisconnectUser
  unit test and SessionExternalIdDto charset-guard validation tests.
- Architecture/Testing/Security (L2): OpenAPI revoke/restore bodies now
  $ref a SessionExternalIdRequest (externalId-only) instead of
  MintSessionRequest (which carried an extra clientIp).

New authz/ import seam collaboration.gateway.ts added to the
import-boundary SEAM_ALLOWLIST (#3f).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@PMQ9
PMQ9 merged commit bd5c90d into wiki-v2 Sep 22, 2026
@PMQ9
PMQ9 deleted the fix/455-fork-session-revoke-on-disable branch September 22, 2026 14:56
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.

1 participant