Repository navigation
feat(authz): standalone AUTHZ_MODE, service-bridge, native-auth disable (Phase A + 2b) - #11
Merged
Merged
Conversation
…idge (Phase A items 1+2a) Make the fork independently runnable via a server-controlled AUTHZ_MODE (native|remote): - authz/port/: implementation-neutral SpaceAuthzPort/PageAuthzPort/RemoteAuthzClient + a compile-time conformance test (stock repos AND PDP subclasses satisfy them). - authz/mode/: AUTHZ_MODE token, resolveAuthzMode (throws on invalid — no silent default, no URL heuristic), @global AuthzModeModule, and mode-selected useFactory providers for the two authz repos + search. native=stock Docmost authz (standalone), remote=PDP-backed. Selection pinned by test. - Seams #1 (database.module.ts) + #5 (search.module.ts) converted from unconditional useClass to the mode-selected providers; authz/audit/audit.module.ts is mode-aware (native=NoopAuditService) so app.module.ts is untouched. - environment.validation.ts (seam #85): AUTHZ_MODE required + remote cross-fields — the fork refuses to boot on ambiguous config. - static.module.ts (seam #86): inject the derived NATIVE_AUTH_ENABLED capability (never the raw mode); features/auth-native/ renders native Docmost login at /login in native mode; App.tsx/auth-service mode-aware (seams #6/#27). - service-bridge/ (2a): fork-hosted /api/service/{session,users} — session brokerage (mint a Docmost session for a fork-owned shadow member; NO generic impersonation) + provisioning (fork writes its own users table). Scoped ServiceAuthGuard (least privilege, fail-closed, constant-time, per-credential rate limit; ServiceScope supports distinct per-scope credentials later). Recognized by the Layer-C classifier. Verified: server nest build clean; client tsc clean; full fork suite 23 suites/225 tests green; 9 client vitest green. NOT YET DONE (item 2b, next session): NativeAuthModeGuard disabling native /api/auth/* in remote mode + switching the platform BFF onto /api/service/*, verified by a live make dev-build login smoke. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…Id (2b-i)
Both east-west endpoints now take only the caller's opaque externalId; the fork
derives the shadow email (shadowEmailFor) and resolves its OWN default workspace,
so a caller cannot select an arbitrary Docmost identity and never handles a
Docmost user/workspace id. provisionShadowUser returns { userId, workspaceId };
mintSession(externalId) looks up by derived shadow email and keeps the
disqualify() member/shadow/not-deleted checks as defense-in-depth.
Part of Phase A6/2b (issue docmost#157). This is the expand step — native /api/auth/login
stays enabled; the platform BFF switches to these endpoints in the same release.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
…remote (2b-ii) Adds a fork-owned NativeAuthModeGuard + @NativeCredentialRoute() marker (authz/mode/) and wires them class-level onto the upstream AuthController (documented seam #87). In remote mode every marked credential route (login/setup/forgot-password/ password-reset/verify-token/change-password) returns 404 for ALL callers — including a service caller presenting the service secret (no exception); sessions in remote mode are brokered only via POST /api/service/session. Session-scoped routes (collab-token/ logout) are unmarked and stay reachable; the guard is inert in native mode. The guard name is deliberately absent from AUTH_GUARD_NAMES so route classification / the route-inventory fitness test are unchanged. Part of Phase A6/2b (issue docmost#157). This is the CONTRACT step — it must ship only AFTER the platform BFF is switched to /api/service/session (2b-i) is confirmed live; this commit is kept separable so it can be held for its own release. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ssion tests (review round 1) Addresses the 7-lens review of the paired standalone-AUTHZ_MODE PR (cccvu/wiki-v2#163 / #11). Fork-side fixes: - Security (Medium/L3): `POST /api/workspace/invites/accept` is a @public() route that mints a native authToken session + assigns invitation.role (up to owner), but lives on WorkspaceController so the AuthController-scoped NativeAuthModeGuard did not cover it — a residual native session-mint in AUTHZ_MODE=remote. Gate it method-level (@UseGuards(NativeAuthModeGuard) + @NativeCredentialRoute()), so it 404s in remote for ALL callers (seam #88, documented super-side). Audit confirmed it is the ONLY native-session mint outside AuthController + the service-bridge. - Testing (L3) — regression resistance for invariants that are correct today but were pinned only by manual smoke: * static-route-scan.ts: capture @NativeCredentialRoute() markers + a body tell that a handler mints a native session (setCookie('authToken') / setAuthCookie). * native-credential-routes.spec.ts (new): pins the EXACT marked set (six AuthController routes + acceptInvite), asserts each is covered by NativeAuthModeGuard, and — the load-bearing invariant — that EVERY native-session-minting route is marked (except the service-bridge broker). A dropped marker or a new unmarked session route now fails RED, not in prod. Uses a source scan (no import) because importing the real controllers trips the known emails/*.tsx moduleNameMapper gap. * authz-mode.validation.spec.ts (new): pins the fail-closed boot cross-field rules (remote requires URL + >=16-char secret; mode must be exactly native|remote) via validateSync. * service-auth.guard.spec.ts: exercise the wrong-scope 403 branch (least privilege) and the constant-time compare at EQUAL length (the existing wrong-secret test differs in length and short-circuits before timingSafeEqual). nest build + server tsc clean; targeted jest 12 suites / 59 tests green. Co-Authored-By: Claude Opus 4.8 <[email protected]>
This was referenced Sep 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Makes the AGPL Docmost fork independently runnable and turns the CCC platform into an opt-in network integration, selected by a required, server-controlled
AUTHZ_MODE = native | remote. This is the fork half of the standalone-boundary work; the CCC platform side is the paired super-repo PR (see below). Tracking issue: cccvu/wiki-v2#157 (full plan, rationale, progress).native→ Docmost's OWN authorization (stock CASL +space_members/page_access/page_permissions) and native login. The fork boots and runs fully standalone with no external service. A legitimate upstream control, never "allow all".remote→ authorization decisions come from an external service (the CCC platform, or any server implementing the documented contract), fail-closed, and native credential auth is disabled server-side.Base branch:
wiki-v2(our fork integration branch, based on upstreamv0.95.0). 44 files, +1533/-32.Scope (two phases on one branch)
698e3514— built & verified in prior sessions (see Add Source Label to Dockerfile docmost/docmost#157): theAUTHZ_MODEselector (authz/mode/), implementation-neutral ports (authz/port/+ a compile-time conformance test, so we never addimplementsto upstream repos), mode-selected DI for the two authz repos + search + audit, the boot validator, the client capability flagNATIVE_AUTH_ENABLED+ native login UI (features/auth-native/), and theservice-bridge/module.d5125191— re-keyPOST /api/service/{session,users}on the caller's opaqueexternalId. The fork derives the shadow email (shadowEmailFor) and resolves its OWN default workspace, so a caller cannot select an arbitrary Docmost identity and never handles a Docmost user/workspace id.provisionShadowUserreturns{ userId, workspaceId };mintSession(externalId)looks up by derived shadow email and keeps thedisqualify()member/shadow/not-deleted checks as defense-in-depth.58103971—NativeAuthModeGuard+@NativeCredentialRoute()(authz/mode/) wired class-level ontoAuthController(seam feat(collab): Hocuspocus 4.7.1 and collab ingress bounds (wiki-v2 #790) #87). InAUTHZ_MODE=remoteevery marked credential route (login,setup,forgot-password,password-reset,verify-token,change-password) returns 404 for ALL callers, including a service caller presenting the service secret (no exception). Session-scoped routes (collab-token,logout) are unmarked and stay reachable; the guard is inert in native mode.58103971is deliberately a separable commit. It disables native login and must ship in its own release, only AFTER the platform BFF switch (2b-i) is confirmed live in prod. Never before. See the deploy sequencing in the super PR / docmost#157.Upstream seams (the boundary-critical review surface)
All decision logic lives in fork-owned, boundary-excluded
authz//service-bridge/. Upstream-owned files are modified minimally (wiring only) and every edit is documented inUPSTREAM_MODIFICATIONS.mdand enforced byscripts/check-upstream-boundary.sh(both in the super PR):database/database.module.ts— bind the two authz repos to mode-selecteduseFactoryproviders.core/search/search.module.ts— mode-selected search provider.integrations/environment/environment.validation.ts—AUTHZ_MODErequired + remote cross-field validators; the fork refuses to boot on a missing/invalid mode (no silent default, no URL-presence heuristic → no downgrade).integrations/static/static.module.ts— inject the client capabilityNATIVE_AUTH_ENABLED(never the raw mode).core/auth/auth.controller.ts— class-level@UseGuards(ThrottlerGuard, NativeAuthModeGuard)+@NativeCredentialRoute()on the six credential handlers. Pure wiring; the guard name is deliberately absent fromroute-classification.ts'sAUTH_GUARD_NAMESso it does NOT reclassify routes (the five pre-auth routes staypublic-authin the intentional-unguarded ledger;change-passwordstaysJwtAuthGuard-authenticated), and the route-inventory fitness test is unaffected.Security model (please review closely)
resolveAuthzModethrows on anything butnative/remote; the boot validator refuses ambiguous config. In remote mode the transport is fail-closed and NEVER falls back to native (that would be a downgrade; an operator must not "fix" a platform outage by switching to native)./api/service/*are highly-privileged M2M endpoints. ScopedServiceAuthGuard(least privilege, per-routeServiceScope, not mere secret possession; the single shared secret is transitional and per-scope credentials slot in later with no redesign), fail-closed (503 unconfigured / 401 wrong / 403 wrong-scope), constant-time compare, per-credential rate limit (429)./api/service/*onexternalId(the fork derives the shadow email) means a caller can only ever name a@shadow.wiki-v2.internalsubject; it cannot mint a session for a real/privileged/native account by id or email. This is a strong narrowing, not an absolute guarantee, so thedisqualify()check (member role, shadow namespace, not deleted) is retained as defense-in-depth against a tampered/mis-provisioned row.Verification
nest buildclean.@docmost/transactional/emails/*.tsxtemplates viamoduleNameMapper, failing 16 suites / 11 tests identically with and without this change. Not touched by this PR.)scripts/check-upstream-boundary.sh, in the super PR) green with seam feat(collab): Hocuspocus 4.7.1 and collab ingress bounds (wiki-v2 #790) #87.make dev-build PROFILES=platform,AUTHZ_MODE=remote): all six native/api/auth/*credential routes → 404 (including WITH the service secret);logout/collab-token→ 401 (exist, not 404);/api/service/session→ 401 (no/wrong secret), 403 (unknown externalId). Full passwordless login end-to-end minted a session viaPOST /api/service/session(docmost logs confirm no/api/auth/login) and a real page call returned 200; first-use provisioning for a fresh externalId resolved the fork's own workspace, created amember, and minted a working session.Merge order (paired-PR discipline)
Merge THIS fork PR first. Then the super PR repoints its
docmostsubmodule to the merged fork commit and merges. KeepUPSTREAM_MODIFICATIONS.md+ the boundary check green on every bump.🤖 Generated with Claude Code