Repository navigation
Description
Overview
The cloud access predicate decides whether a user may read or write a node by walking the graph upward to the nearest restricted collection. Whether that walk follows member_of (a node's classification) or only has_child (a node's position in the outline) is the difference between a correct access model and a broad, silent read leak.
The shipped predicate in nodespace-cloud already does the right thing. This issue is not a bug report — it is about locking that behavior in. The correct implementation currently rests on a comment and on tests that were written for a visibility concern (sub-collections not appearing in sync pulls), not for the security property. The security property itself is untested, so a well-intentioned "simplify the walk to just follow the tree" refactor would reintroduce the leak with no test failing.
Problem Statement
The predicate seeds its recursive CTE from both member_of and has_child in-edges of the subject node, recurses upward through has_child unconditionally and through member_of only into collection nodes, bounds depth at 64, and gates on the minimum-depth restricted-ancestor set.
Each of those four properties is load-bearing, and each is currently unpinned:
-
member_ofin the seed. Without it, this ordinary authoring shape evaluates as open to the entire tenant:Date page 2026-07-25 (open — no restricted ancestor) └── has_child → Note "Q3 comp bands" └── member_of → Collection "Compensation" (restrictedToMembers = true)Writing a note where you are working and filing it into a collection afterwards is the normal path — filing does not move the note in the outline. A
has_child-only walk leaks every such node, and makes an outline move a silent access change. -
member_ofrecursion restricted to collection nodes. Collection nesting is real containment; a content node that happens to bemember_ofsomething is not an access parent of anything. Dropping thenode_type = 'collection'guard would let content memberships transitively govern unrelated nodes. -
Minimum-depth tie resolution. Ancestry is a DAG, not a tree, so several restricted collections can tie at the minimum depth (a diamond). Membership in any one of them grants. Gating on all restricted ancestors instead of the minimum-depth set would break ADR-037's nearest-boundary nesting semantics; denying on tie would make explicit grants silently ineffective.
-
Depth bound + set semantics.
UNION(notUNION ALL) dedupes so a cyclic graph terminates; the depth cap is the backstop.
Additionally, the read and write predicates must perform the same walk, differing only in the final permission check. If they drift, read and write disagree about where the boundary is.
Proposed Solution
Pin all four properties with adversarial tests in the cross-tenant / privilege-escalation suite, and make the read/write walk shared rather than duplicated.
Test cases to add (each must fail if the corresponding property is removed):
- A node
member_ofa restricted collection, reachable in the outline only from an open ancestor, is not readable by a tenant user who is not a member. This is the primary regression test — it is the case ahas_child-only walk gets wrong. - The same node is readable by a member of that collection.
- A content node that is
member_ofa collection does not transitively govern nodes that arehas_childchildren of it. - A node under two restricted collections at equal minimum depth is readable by a member of either (tie grants).
- A node under a restricted collection at depth 1 and a different restricted collection at depth 3 requires membership in the depth-1 collection (nearest wins; farther boundary does not grant).
- A relationship cycle in the ancestry graph terminates rather than looping or timing out.
- The write predicate agrees with the read predicate on boundary location for every case above, differing only in requiring
modify/admin.
Shared walk: the read predicate, the write predicate, and the restricted-ancestor existence helper currently repeat the same recursive CTE three times. Factor the traversal so the walk cannot drift between them while the final checks stay distinct.
Architecture Impact
- ADR-037 (
../nodespace-docs/decisions/037-collection-access-model.md) §5 previously described the walk as following thehas_childtree. It has been amended to state that the walk unions both edge types. This issue does not reverse it — it implements and pins what the amended ADR requires. - ADR-059 (
../nodespace-docs/decisions/059-access-classification-not-outline-position.md) is the governing decision: access follows classification, not outline position; ancestry is a DAG; minimum-depth ties grant; access is inherited but membership is never derived. architecture/tenant-isolation-rls.mdrecords this as load-bearing security property P6, which is what this issue asserts by test.- The companion
nodespace-docschanges are already committed; no further docs work is required for this issue.
Acceptance Criteria
- Adversarial test asserts a node
member_ofa restricted collection but reachable only from an open outline ancestor is unreadable by a non-member - Adversarial test asserts the same node is readable by a member
- Test asserts
member_ofrecursion does not follow through content nodes - Test asserts equal-minimum-depth ties grant on membership in either collection
- Test asserts a nearer restricted boundary overrides a farther one
- Test asserts a cyclic ancestry graph terminates
- Test asserts read and write predicates locate the same boundary
- The recursive walk is defined once and shared by the read predicate, write predicate, and restricted-ancestor helper
- Each test fails when its corresponding property is removed from the predicate (verified by temporarily reverting)
- Tests pass (
bun run test:all) - Code passes
bun run quality:fix
Technical Specifications
Reference Files
- Tenant schema:
db/tenant-schema.sqlinnodespace-cloud—user_can_access_node,user_can_write_node,has_restricted_ancestor - Membership view:
collection_members(derived fromrelationships⋈auth_identities); not granted toauthenticated, read only throughSECURITY DEFINERhelpers - Security properties:
../nodespace-docs/architecture/tenant-isolation-rls.md— P6
Implementation Details
- The restriction flag is read at
properties->'collection'->>'restrictedToMembers'— core stores schema fields nested under the node-type namespace, so the synced JSON is{"collection":{"restrictedToMembers":true}}, not a top-level key. - Compare with text equality (
= 'true'), never::boolean. Untrusted client-suppliedproperties(e.g."yes please") would raise inside aSECURITY DEFINERpolicy and 500 every query under that collection. - The function parameter is named
for_user_id, notuser_id, to avoid colliding with thecollection_members.user_idcolumn inside the query. - Person nodes are gated by a separate co-member check, not by this walk — the open-by-default branch would otherwise expose PII to every tenant user.
- The walk is on the hot read path, evaluated per row and per Realtime WAL broadcast. Keep the depth bound and confirm the traversal stays indexed; a regression here degrades every query, not just restricted ones.
Related Issues
- CASCADE delete must abort when the subtree contains nodes the actor cannot read #1736 (access-gated CASCADE delete — depends on the per-node access predicate this issue pins)
- Subtree embedding aggregation must stop at access boundaries; restricted descendants become their own embedding roots #1737 (embedding aggregation access boundary)
- AI chats private by default: seeded personal collection, transactional membership, and implement the non-embeddable revision #1740 (ai-chat private by default — relies on
member_ofbeing in the walk)
Activity
mstomar125 commentedon Jul 28, 2026
Finding while writing the pinning tests: the predicate has a real interior-content leak
Verifying
user_can_access_nodeempirically against livetenant_demo(BEGIN..ROLLBACK) before locking it in surfaced a case where the shipped predicate does not do the right thing — the exact silent-leak class this issue exists to prevent.Behavior: a content root filed into a restricted collection via
member_of(the normal grouping edge #1742 gates) leaks itshas_childdescendants to non-members. The root is correctly gated; its interior children are not.member_ofonlyhas_childonlyReproducible:
Cause: the recursive walk follows
member_ofupward only when the current node is a collection (... OR (member_of AND na.node_type = 'collection')). So a content root's restriction never propagates down its subtree. The clause is duplicated verbatim in all three twin predicates —user_can_access_node,user_can_write_node,has_restricted_ancestor.Reachability:
add_to_collectioncreatesmember_ofonly (nohas_child), so this is the normal shape of every multi-paragraph document filed into a collection — 11,729 such structures exist intenant_demotoday. It's currently dormant only becausetenant_demohas 0 restricted collections; restricting any collection (or filing a doc into a restricted one) exposes the children of every document in it.Fix being implemented (option a)
Enforce ADR-059 §2 at the read layer: a filed root's restriction covers its whole subtree. Change the recursion clause in all three predicates from
na.node_type = 'collection'tona.node_type <> 'person'— followmember_ofup from content roots and collections, but not from person (grantee) nodes (grantee access is checked separately viacollection_members, so this is safe). Read-layer enforcement gates regardless of how the edge was created (stronger than fixing only the write path).Shipping with the pinning tests this issue asks for (leak now gated; a member of the collection still reads the child; open-collection content unaffected; collection-nesting + has_child paths unchanged; person exemption), live-verified vs
tenant_demo+ adversarial review. PR to nodespace-cloud to follow.mstomar125 commentedon Jul 28, 2026
Resolved by nodespace-cloud#99 (squash-merged
d1e5a2a0), deployed + verified live ontenant_demo.The access walk now follows
member_ofupward from content roots and collections (not collections only) in all three twin predicates —user_can_access_node,user_can_write_node,has_restricted_ancestor— viana.node_type <> 'person'. A content root filed into a restricted collection now restricts its wholehas_childsubtree (ADR-059 §2), closing the read and write leak; person (grantee)member_ofedges stay unwalked (grantee access is decided viacollection_members).The four load-bearing walk properties this issue asked to lock in are now pinned by
db/fixes/2026-07-28-access-walk-member-of-from-content-test.sql: member_of in the seed, has_child unconditional, member_of-from-non-person recursion, and the nearest-restricted (min-depth) gate. The test fails on the old clause and passes on the fixed one, so a future 'simplify the walk' refactor trips a test instead of silently reopening the leak.Verification: live vs
tenant_demo(BEGIN..ROLLBACK) — outsider read/write of an interior node under a member_of-restricted root flips TRUE→FALSE; members retain access; open content, has_child gating, collection nesting, and min-depth all unaffected. Two-way verified (live tests + adversarial review: the change is a monotonic tightening, structurally unable to introduce a leak).Follow-up (operational): the
db/fixesmigration is applied totenant_demo; apply it to any other live tenants per the cloud runbook (new tenants get it from the canonical schema at/provision).mstomar125 commentedon Aug 1, 2026
✅ Live-tenant migration applied + verified (2026-08-01). Deployed to all 4 complete tenants —
tenant_demo,tenant_deutnet,tenant_nodespace_internal,tenant_public— via the recheck→apply→post-verify flow (rolled-back recheck on real data, then committedCREATE OR REPLACE(no data change), then behavioral-test.sqlpost-verify all green). Fix-marker confirmed in each tenant's live function definitions.tenant_bskipped (incomplete stub schema — noauth_identities/access functions). New tenants remain auto-covered via canonical. (cloud-side access-walk migration2026-07-28-access-walk-member-of-from-content.sql.)