Skip to content

fix(wiki-v2#542,#573,#574): native routes decide what the PDP decides - #64

Merged
PMQ9 merged 4 commits into
wiki-v2from
fix/542-573-574-native-authz
Nov 4, 2026
Merged

PMQ9 merged 4 commits into
wiki-v2from
fix/542-573-574-native-authz

Conversation

@PMQ9

@PMQ9 PMQ9 commented Nov 3, 2026 •

Copy link
Copy Markdown

TL;DR

In remote mode, the native engine now decides page access exactly as the PDP does:

  • A space binding without space#view gets no native role.
  • Native member add/remove/change-role are refused.
  • Breadcrumbs stop at the first ancestor the caller can't view.
  • Duplicate refuses (409) a copy that would drop a restriction. The check runs inside the insert's own transaction, under the workspace guard lock.

Context

These are three wiki-v2 issues: 542 (space roles without view read content), 573 (duplicate drops restrictions) and 574 (breadcrumbs disclose restricted ancestors). The design record is the wiki-v2 ADR 0025 amendment (docmost#542) and the ADR 0027 amendment (docmost#573, docmost#574). The super PR carries the matching schema change (space#edit/page#edit end in & view), the content smoke, docs, and the gitlink bump.

Related issues

  • Relates to wiki-v2 issues 542, 573 and 574 (closed by the super PR). Follow-ups: wiki-v2 issues 660–664.

What changed

  • authz/pdp-space-member.repo.ts maps the role strictly:

    • no view → no role;
    • view without edit → reader;
    • writer needs edit + view;
    • admin needs administer + edit + view.

    CASL and collab both read this role. That closes, for a view-less space admin, info (by id or slug), update, trash, restore, move, create, import, sidebar, comments, shares, uploads, collab and permanent delete. live-access/collab-access.decision.ts mirrors the mapping, pinned by the parity spec.

  • page-restriction.service.ts authorize(): in remote mode it decides with PDP space#administer (null → 503), so the /v1 ACL relay keeps working for a view-less space admin. Native mode still uses CASL.

  • authz/native-routes/ (new, NativeRouteAuthzModule, imported by AuthzModule):

    • SpaceMemberMutationInterceptor 404s and audits SpaceController add/remove/change-role in remote mode. Those native routes skip rule M and the platform audit, so a manage_members-only admin could add themselves as writer.
    • BreadcrumbsRedactionInterceptor:
      • It makes one PDP filter call, walks up through parentPageId, and keeps the contiguous viewable chain.
      • When it cuts the chain, it nulls the top kept row's parent. A PDP error yields [self].
      • It unwraps {data,…}; any other shape → 500.
  • authz/page-copy/ (new) + seam Feature request: sort by preference docmost/docmost#121 in PageService.duplicatePage:

    • The pages insert runs in executeTx. Before inserting, the remote repo's assertCopyKeepsRestrictions checks the exact copied set under the workspace lock that g0/g1/g2 take.
    • It refuses with 409 ccc_page_restricted_copy when a copied page has its own page_access row, or when a cross-space copy leaves a restricted lineage.
    • A dropped root or a lock timeout → 503.
    • Native mode is unchanged.
  • Stale comments fixed: "trash reaps edges" (no longer true since [Feature request] Public invite links docmost/docmost#493).

How this was tested

  • Unit lane jest src/authz src/service-bridge src/editor-compat src/common/helpers/prosemirror: 144/145 suites, 1900 tests. The one red test is service-page-import.service.spec.ts, a feat: add new languages to selection docmost/docmost#626 content-parse deadline that fails only under full-lane load on a laptop. It passes 17/17 on its own. It's untouched here; watch it in CI.
  • pg lane (real Postgres) 'src/(service-bridge|authz)/.*\.pg\.spec\.ts$': 29/29 suites, 372 tests. New specs:
    • duplicate-restriction.pg.spec.ts: restricted root, restricted descendant and stale PDP allow → 409 with zero rows inserted.
    • Deterministic races in the same spec: a restrict during the PDP call → 409; an in-flight restrict → waits, then 409; a serialized duplicate→restrict → both succeed; a lock held elsewhere → 503.
    • Same spec: hidden content is never copied.
    • breadcrumbs.pg.spec.ts: the real getPageBreadCrumbs plus the interceptor.
  • Anti-vacuity:
    • Disabling the seam gate reds all 10 refusal/race tests. Removing the advisory lock reds exactly the 3 lock tests.
    • The old role mapping reds 48 tests.
    • 7 fitness mutations and 11 seam mutations each go red.
  • End to end: wiki-v2 content smoke §10h on a fresh compose stack (real SpiceDB) passes 291/291. Against this fork's base, every fork-side leg fails.
  • tsc -p tsconfig.build.json is clean. The wiki-v2 check-upstream-boundary.sh passes.

AWS / infra apply

N/A

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. (All except the load-sensitive feat: add new languages to selection docmost/docmost#626 timing spec noted above; confirm in CI.)

Docs & contracts

  • Docs added/updated where needed (README / docs/ / an ADR), or N/A. (In the super PR.)
  • 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

  • Accepted loss: an administer+view holder without edit is a native reader, so they lose the native-only space settings: space update, icon, comment moderation and native space export. Permanent delete, native or relayed from /v1, now needs a full admin on the human.
  • The separate collab server app (collab-app.module.ts, collab:* scripts, not deployed) can't resolve the new module's audit client. This is the same pre-existing gap ServiceBridgeModule already has.
  • Follow-ups: wiki-v2 issues 660 (shares title leak), 661 (admin purge/trash of hidden restricted pages), 662 (console: edit-without-view role), 663 (duplicate with restrictions copied), 664 (latent nits).

🤖 Generated with Claude Code

Implementation plan (canonical, kept current): https://github.com/cccvu/wiki-v2/issues/542#issuecomment-6616313283 . Review comments for this set live on wiki-v2 PR 672.

PMQ9 and others added 4 commits November 3, 2026 15:25
… for admin/writer)

getUserSpaceRoles maps administer/edit/view strictly: no view -> no role,
view without edit -> reader, admin/writer need edit + view. Closes every
CASL and collab content path for a view-less space admin, including
permanent delete. The collab revalidator decision mirrors it (parity spec).
PageRestrictionService.authorize decides space#administer on the PDP in
remote mode so the /v1 ACL relay keeps working for such an admin.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…dcrumbs at hidden ancestors

Remote mode 404s (and audits) SpaceController add/remove/change-role: the
native routes skip rule M and the platform audit, so a manage_members-only
admin could add themselves as a writer. Breadcrumbs keep only the
contiguous chain the caller can view (one PDP filter, fail closed to
[self]) and null the top kept parent, mirroring /v1 ancestors. Both
interceptors live in fork-owned NativeRouteAuthzModule, pinned by a
fitness spec.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Seam docmost#121: duplicatePage's insert runs in a transaction where the remote
repo checks the exact copied set under the workspace guard lock (the lock
g0/g1/g2 take): any own page_access row, or a cross-space copy out of a
restricted lineage, refuses with 409 ccc_page_restricted_copy; a dropped
root or lock timeout is 503. Race-free against concurrent restrict/move.
Also fixes stale 'trash reaps edges' comments (docmost#493).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… the custom bigint type

authz-outbox-commit-safety and authz-outbox-retention annotated their reserved connections and
insert helpers as the bare postgres.Sql/ReservedSql (= <{}>) while the pools carry
types.bigint. ts-jest's per-worker language service reports that mismatch depending on which
specs share the worker, so the new pg specs in this PR surfaced it in the authz-compat lane.
tsc --noEmit over every spec is now clean.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@PMQ9
PMQ9 merged commit 7d109e4 into wiki-v2 Nov 4, 2026
@PMQ9
PMQ9 deleted the fix/542-573-574-native-authz branch November 4, 2026 18:48
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