Skip to content

fix(#80): authenticate GET /collab/stats with the service-secret guard - #45

Merged
PMQ9 merged 1 commit into
wiki-v2from
fix/80-collab-stats-auth
Sep 21, 2026
Merged

PMQ9 merged 1 commit into
wiki-v2from
fix/80-collab-stats-auth

Conversation

@PMQ9

@PMQ9 PMQ9 commented Sep 21, 2026

Copy link
Copy Markdown

Summary

GET /collab/stats (the collab process's stats endpoint) had no authorization decision — no guard, no @Public. It leaks aggregate live connection/document counts to any caller when COLLAB_SHOW_STATS is enabled. It was tracked as a Layer C known-gap in the route-inventory ledger (cccvu/wiki-v2#80).

The #13 global PlatformAuthorizationGuard can't reach it: the route is registered only in CollabAppModule, which collab-main.ts boots as a separate process with no APP_GUARD.

Change

Apply a class-level @UseGuards(CollabServiceSecretGuard) to CollaborationController — the exact auth primitive collab-disconnect/collab-flush already use. It requires the platform's x-authz-service-secret (constant-time compare) and fails closed: 503 when the secret is unconfigured, 401 on a missing/invalid secret.

  • Dependency-free guard → the class-level @UseGuards enforces in the collab process without a CollabAppModule provider: Nest's scanner auto-registers a @UseGuards-referenced class as a module injectable (verified against @nestjs/core 11.1.27, and proven by the boot test, which omits the provider). This keeps the change to a single upstream file (one seam), honoring "modify-minimally".
  • Removes the CollaborationController.getStats known-gap entry from intentional-unguarded.ledger.ts — the route-inventory fitness test enforces the biconditional (guarded ⇔ not ledgered).
  • Adds collaboration/server/collaboration.controller.ts to import-boundary.spec.ts SEAM_ALLOWLIST (the new upstream→authz seam).

Not RemoteOnlyGuard as well: it needs the @Global AUTHZ_MODE token that isn't wired into CollabAppModule, it isn't in AUTH_GUARD_NAMES, and stats isn't inherently remote-only. CollabServiceSecretGuard alone is the simplest robust decision.

The paired super-repo PR bumps the submodule and documents this seam as UPSTREAM_MODIFICATIONS.md #163.

Tests

New authz/collab/collab-stats-guard.spec.ts boots the controller through the real Nest HTTP layer (guard deliberately omitted from providers, mirroring production CollabAppModule wiring):

  • no x-authz-service-secret → 401
  • wrong secret (same length + different length) → 401
  • correct secret → 200 with the gateway counts
  • secret unset → 503 (fail closed)
  • static: the controller carries @UseGuards(CollabServiceSecretGuard)

Validation (from apps/server):

  • npx jest authz/collab/collab-stats-guard → 6/6 pass
  • npx jest authz/route-guard authz/collab/collab-disconnect → 7 suites / 57 pass (route-inventory + import-boundary green)
  • npx tsc --noEmit -p tsconfig.build.json → clean; eslint --fix → clean, no reformatting

Relates to cccvu/wiki-v2#80.

🤖 Generated with Claude Code

The collab stats route is registered only in the separate CollabAppModule
process (collab-main.ts), which the main app's fail-closed
PlatformAuthorizationGuard cannot reach — so it leaked aggregate
connection/document counts to any caller when COLLAB_SHOW_STATS was enabled.

Guard it with CollabServiceSecretGuard (parity with collab-disconnect): it
requires the platform's x-authz-service-secret and fails CLOSED (503 when the
secret is unconfigured, 401 on missing/invalid). The guard is dependency-free,
so a class-level @UseGuards enforces in the collab process without a provider
(Nest's scanner auto-registers it — verified against @nestjs/core 11.1.27).

Drops the now-closed known-gap ledger entry (the route-inventory fitness test
then requires it removed) and records the new upstream->authz seam in the
import-boundary allowlist.

Adds a security regression test that boots the controller through the real Nest
HTTP layer (guard deliberately omitted from providers, mirroring production
CollabAppModule wiring): 401 on no/wrong secret, 200 + counts on the correct
secret, 503 when the secret is unset.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@PMQ9
PMQ9 merged commit 427d2f4 into wiki-v2 Sep 21, 2026
@PMQ9
PMQ9 deleted the fix/80-collab-stats-auth branch September 21, 2026 22:57
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