Skip to content

fix(authz): restriction check fails closed when the PDP bulk call errors (wiki-v2#492) - #51

Merged
PMQ9 merged 1 commit into
wiki-v2from
fix/g3-checkbulk-fail-closed
Sep 22, 2026
Merged

PMQ9 merged 1 commit into
wiki-v2from
fix/g3-checkbulk-fail-closed

Conversation

@PMQ9

@PMQ9 PMQ9 commented Sep 22, 2026 •

Copy link
Copy Markdown

TL;DR

The fork's page-restriction check (locked) failed open when the PDP bulk call errored. The failure read as "unrestricted", so upstream fell back to the space role and a restricted page opened to every space member. With this change an unknown restriction state is treated as restricted with no access. The change is CCC authz code only (apps/server/src/authz/); no upstream-owned file is touched.

Context

HttpAuthzClient.checkBulk collapses every failure (transport, timeout, non-2xx, malformed body) into all-false. That is safe for view/edit, where false means deny. PdpPagePermissionRepo.canUserEditPage reads locked from the same batch, but for locked a false means unrestricted. PageAccessService then trusts the space role (CASL), which is fetched by a separate call that may have succeeded. So a PDP error could expose a restricted page. This is the AGENTS.md "a missing restriction fails open" class, P0-adjacent.

Found while planning the page-lifecycle work in wiki-v2 issue 485. Those /v1 routes use validateCanEdit/validateCanView as defense in depth, so this should land first. Plan, progress and tradeoffs are on the tracking issue: https://github.com/cccvu/wiki-v2/issues/492#issuecomment-5781600903

Related issues

  • Fixes cccvu/wiki-v2#492. The issue closes when super-repo PR 494 (its gitlink bump, Closes #492) merges.
  • Related: cccvu/wiki-v2#493 (native restore / move-to-space declassification, a separate follow-up).

What changed

  • authz/http-authz.client.ts: new tryCheckBulk(), which returns null on any failure, including any non-boolean result element, so a Byzantine locked: "yes" can't read as unrestricted. checkBulk() keeps its exact contract (all-false on failure, per-element coercion); both share one private bulkResults(), which now also logs a malformed envelope.
  • authz/port/remote-authz-client.port.ts: tryCheckBulk added to the RemoteAuthzClient port.
  • authz/pdp-page-permission.repo.ts: canUserEditPage uses tryCheckBulk. An unknown result becomes {hasAnyRestriction: true, canAccess: false, canEdit: false}, so upstream denies.
  • docs/architecture/external-services.md: states that a failed locked means restricted, for third-party PDP implementers.
  • No wire or contract change. The published authorization-service.openapi.json is unchanged.

How this was tested

  • pnpm exec jest src/authz src/service-bridge src/editor-compat (the CI docmost-authz lane): 80 suites, 750 passed, 57 skipped (real-Postgres specs, which self-skip without a DB).
  • New or changed specs:
    • http-authz.client.spec.ts: tryCheckBulk returns strict results on a 200, [] without a call for an empty batch, and null on a network error, non-200, non-array, wrong length, and a non-boolean element.
    • leakage/primitives.spec.ts:
      • The outage block now asserts canUserEditPage returns restricted with no access.
      • A new end-to-end test drives the real upstream PageAccessService with the exact precondition: the page call fails while the space role allows. validateCanEdit and validateCanViewWithPermissions throw ForbiddenException.
      • A control case shows the pre-fix all-false reading did fall through to the space role, so the test isn't vacuous.
  • npx tsc --noEmit -p tsconfig.build.json: clean.
  • bash scripts/check-upstream-boundary.sh (super repo, against the committed fork HEAD): passes, upstream boundary intact.

AWS / infra apply

N/A. Fork code only, and it ships with the next release after the super-repo gitlink bump.

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

  • Intentional behaviour change under PDP degradation. Page access goes from "fall back to the space role" to deny. Users may see 403s on page opens during a PDP outage where they previously saw the page. That is the correct failure mode, but operators should know.
  • Only locked needed this. It is the one bulk-checked permission where false relaxes access. filterResources returning empty on failure, which orphans children during movePageToSpace, is a separate case. It's tracked with the wiki-v2 issue 485 follow-ups.
  • The native-path declassification that trash edge-reaping causes (restore, move-to-space) is out of scope; see wiki-v2 issue 493.

🤖 Generated with Claude Code

…ors (docmost#492)

`HttpAuthzClient.checkBulk` collapses any failure (transport, timeout, non-2xx,
malformed body) into all-`false`. `PdpPagePermissionRepo.canUserEditPage` read
`locked` from that same batch, and `locked=false` RELAXES access: upstream
`PageAccessService` then falls back to the space role, which comes from a
separate call that may well have succeeded. So during a PDP error a restricted
page read as unrestricted and opened to every space member.

- HttpAuthzClient.tryCheckBulk: like checkBulk, but reports failure as `null`
  (including any non-boolean element, so a Byzantine `locked: "yes"` can't read
  as unrestricted). checkBulk keeps its exact contract. Added to the
  RemoteAuthzClient port.
- canUserEditPage: an unknown result means {hasAnyRestriction: true,
  canAccess: false, canEdit: false}, so upstream trusts the PDP decision and denies.
- Specs: client failure polarity (null on every failure mode); repo outage
  now covers canUserEditPage; an end-to-end PageAccessService test pins the
  exact precondition (page call fails, space role allows), plus a control
  proving the pre-fix reading fell through to the space role.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@PMQ9
PMQ9 merged commit 3b2a5b6 into wiki-v2 Sep 22, 2026
@PMQ9
PMQ9 deleted the fix/g3-checkbulk-fail-closed branch September 23, 2026 03:22
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