Skip to content

fix(wiki-v2 636/401/503): remote mode refuses native admin routes, inert users.role, fenced purge - #63

Merged
PMQ9 merged 4 commits into
wiki-v2from
fix/636-401-503-remote-native-authority
Nov 4, 2026
Merged

PMQ9 merged 4 commits into
wiki-v2from
fix/636-401-503-remote-native-authority

Conversation

@PMQ9

@PMQ9 PMQ9 commented Nov 3, 2026 •

Copy link
Copy Markdown

TL;DR

Remote-mode hardening of the engine's native admin and purge paths:

  • one table-driven 404 refusal for the native workspace, group, space-member and email-change admin routes;
  • users.role confers no workspace authority in AUTHZ_MODE=remote;
  • native page-ACL writes now write a domain audit row;
  • in remote mode a permanent delete is one locked, settle-fenced routine that needs page#edit on every page it removes.

This is the fork half of a paired change. The super PR (https://github.com/cccvu/wiki-v2/pull/666, private) is the one cohesive PR and carries the rationale, the owner decisions and the residuals. Review the two together.

Context

In remote mode the platform owns identity, membership and group administration. These native routes duplicated that authority, and the permanent delete decided on space settings alone. Contract version 1.10.0. Design record: wiki-v2 ADR amendments 0001, 0025, 0026, 0028 and 0029 (super repo).

Related issues

What changed

  • W1: authz/remote-refusal/. RemoteNativeRefusalInterceptor and remote-refusal.table.ts replace the Dev docmost/docmost#502 and custom drawio server by docker not ok docmost/docmost#598 interceptors. The table has six families and 20 Controller.handler keys:

    • spaceHardDelete, spaceNativeCreate (unchanged events);
    • workspaceAdmin, groupAdmin, spaceMember;
    • userEmail, refused whenever the body has an email key.

    Each refusal is a 404 before CASL, plus one best-effort audit row. The row never reads the body.

    The Dev docmost/docmost#502 and custom drawio server by docker not ok docmost/docmost#598 specs moved here with git mv. static-route-scan.ts exposes handlerText, handlerCalls and httpPath in place of the per-feature booleans. app.module.ts seam fix(authz): harden PLATFORM_AUTHZ_TIMEOUT_MS parse (empty/typo → deny-all self-DoS) #4: two providers become one.

  • W2: authz/mode/workspace-ability.ts. In remote mode, RemoteWorkspaceAbilityFactory computes the stock MEMBER ability for every known role, on a copy of the user. An unknown role throws (fail closed). New upstream seam: core/casl/casl.module.ts (No way to delete users docmost/docmost#177), one provider swap.

  • W3: authz/page-restriction/acl-audit.ts. PageRestrictionService emits one domain audit row per applied ACL write, after commit, using upstream event names. Rows carry ids and roles only (never titles), with metadata.surface:'engine'.

    • AUDIT_SERVICE is @Optional, because the collab app has no audit module.
    • A sink failure logs PAGE_ACL_AUDIT_FAILED and leaves the write committed.
  • W6: authz/page-delete/. RemotePurgeService is the only remote purge routine. Both entry points use it:

    The steps, in order:

    1. Open a transaction with bounded waits.
    2. Lock the whole subtree (trashed pages included) FOR UPDATE in id order, and re-walk until it is stable.
    3. Check the ETag.
    4. Settle fence: maxCommittedPosition read after the locks, then settleProjection.
    5. Re-check space admin, then check page#edit on every locked id.
    6. Run forceDelete, and require the deleted set to equal the locked set.

    New codes: 403 purge_needs_edit; 503 purge_unconfirmed (retryable); 409 purge_subtree_changed. Log tokens: REMOTE_PURGE_BUSY, REMOTE_PURGE_UNCONFIRMED, REMOTE_PURGE_UNSTABLE and REMOTE_PURGE_SET_MISMATCH.

  • Contract 1.9.0 → 1.10.0. The integrator README lists the refused families, inert users.role and the purge rule. contract-smoke.sh gains a native-phase control and a remote leg (e) that refuses five routes for the OWNER, each proven against the database.

How this was tested

  • Fork unit: jest src/authz src/service-bridge src/editor-compat …, 149 suites, 2175 pass (333 pg-gated skips).

  • pg specs: 28 suites, 361 pass on real Postgres. This includes the deterministic purge race specs: a concurrent restrict on a descendant, a concurrent child insert, a deleted-set mismatch rolling back, and a lock timeout giving 503.

  • Server build: nest build green. check-upstream-boundary.sh green.

  • Isolated real-boot smokes:

    • fork-contract-replacement-smoke: ALL CHECKS PASSED, including the new leg (e);
    • fork-standalone-smoke: ALL CHECKS PASSED.
  • HTTP specs boot the real controllers on Fastify for every refusal key (refused in remote; 200 with the interceptor removed, as anti-vacuity), for the W2 icon routes, and for PageController.delete.

  • Mutation proof:

    Workstream Mutants Result
    W1 refusal 19 all red
    W2 CASL 5 all red
    W3 audit 7 all red
    W6 purge ~22 all red

    Examples: drop a table key or the email predicate; always use the stock factory; pass the user through unchanged; emit the audit inside the transaction; skip the fence; skip one descendant.

AWS / infra apply

N/A. Fork code only.

Checklist

Scope

  • Complete and scoped to one logical concern — no unrelated drive-by changes (or follow-ups noted below).

Tests

  • New/changed behavior has appropriate tests — unit / integration / e2e / security / regression as applicable (or N/A, with why).
  • Existing tests pass, and any new tests pass.

Docs & contracts

  • Docs added/updated where needed (README / docs/ / an ADR), or N/A.
  • Any API/contract, config, migration, permission, or deployment impact is called out in this PR, or N/A.
  • Any AWS/infra apply is described precisely, scoped (no mass-apply), and captured in a reviewable one-time script — see "AWS / infra apply" above, or N/A.

Safety (this is a security-first, deny-by-default platform)

  • Security, authorization, data integrity, failure paths, and backward compatibility considered, or N/A.
  • Upstream boundary respected — no undocumented edits to Docmost-owned files (see UPSTREAM_MODIFICATIONS.md); proprietary/authz logic stays out-of-process.

Housekeeping

  • Related issue(s) linked above.
  • Known limitations, follow-ups, or intentionally deferred work identified below.

Known limitations / follow-ups

Tracked in the super PR and its follow-up issues. Behaviour notes for integrators:

  • POST /api/users/update refuses any body that has an email key in remote mode, even an unchanged email.
  • A session whose users.role is owner/admin sees native admin UI that answers 404 or 403 in remote mode.

🤖 Generated with Claude Code

https://claude.ai/code/session_012MtB3UoudTUG3zK7fjrBpC

PMQ9 and others added 4 commits November 3, 2026 15:37
…ase sessions and self-dealers no authority

- authz/remote-refusal: one table-driven RemoteNativeRefusalInterceptor absorbs the
  docmost#502/docmost#598 refusals and 404s (with an audit row) native workspace admin, group admin,
  space-member writes and /api/users/update email changes in AUTHZ_MODE=remote.
  Every family is pinned both ways by fitness specs.
- authz/mode/workspace-ability (seam docmost#177, core/casl/casl.module.ts): in remote mode
  workspace CASL gives every role the member ability, so users.role confers no authority.
- authz/page-restriction: one domain-audit row per applied native page-ACL write.
- authz/page-delete: in remote mode a permanent delete runs one locked, settle-fenced
  routine that requires page#edit on every page it removes (native route via
  RemotePurgeInterceptor, conditional route directly).
- Contract 1.10.0: README + openapi version; contract smoke gains native controls and
  the remote leg (e) refusals.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012MtB3UoudTUG3zK7fjrBpC
…tbox pg specs

`ReservedSql` and the insert helpers' bare `Sql | ReservedSql` are `<{}>`, while
the factories return `<{ bigint: number }>`. `tsc --noEmit` reports 13 errors
across both specs. ts-jest surfaced them on one CI runner (wiki-v2 PR 666's
authz compat lane), which turned it red. Annotation only; no behaviour change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012MtB3UoudTUG3zK7fjrBpC
In remote mode the server ignores users.role and refuses the native
workspace, group and space-member admin routes, so a native-phase
owner/admin session saw enabled admin controls that only failed with
"Not Found". useUserRole now derives its flags from member in remote
mode; native mode is unchanged. Vitest pins both modes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012MtB3UoudTUG3zK7fjrBpC
… fix/636-401-503-remote-native-authority

Conflicts: narrowing-routes.ts and static-route-scan.ts keep this branch's
side (the table-driven refusal header; handlerText/handlerCalls/httpPath in
place of per-feature booleans). The two outbox pg specs take wiki-v2's
identical typing fix.

docmost#542's SpaceMemberMutationInterceptor refused the same three native
space-member routes as this branch's spaceMember refusal family, under a
second audit event. It is folded into the table: the interceptor and its
two specs are removed, the table gains a targetUserField so a self-targeted
attempt is still flagged targetsActor, and NativeRouteAuthzModule keeps only
the breadcrumb redaction. native-route-authz.fitness.spec.ts keeps the
breadcrumb pins on handlerCalls; space-member.fitness.spec.ts pins the
member writes. The event stays space.native_member_refused (neither name
has shipped).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012MtB3UoudTUG3zK7fjrBpC
@PMQ9
PMQ9 merged commit 8cbaeb3 into wiki-v2 Nov 4, 2026
@PMQ9
PMQ9 deleted the fix/636-401-503-remote-native-authority branch November 4, 2026 19: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