Skip to content

test(service-storage): give the attachment read-visibility harness real Filter Protocol semantics - #3787

Closed
os-zhuang wants to merge 3 commits into
mainfrom
claude/angry-merkle-9ccc4d
Closed

os-zhuang wants to merge 3 commits into
mainfrom
claude/angry-merkle-9ccc4d

Conversation

@os-zhuang

@os-zhuang os-zhuang commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Problem

packages/services/service-storage/src/attachment-read-visibility.test.ts faked its engine with a matcher that understood implicit equality and $in — and nothing else. No $and, no $or, no $not.

Every assertion in the file could therefore only check the shape of the filter computeParentVisibilityFilter emits, never the rows that filter selects. That is a poor bargain for a predicate whose entire job is narrowing: it pairs a discriminator with an id list per branch, and any bug that widens $or — the class fixed in the SQL compiler by #3776 — loosens that pairing while leaving every shape assertion green.

Changes

  • Real Filter Protocol semantics in the harness matcher, mirroring memory-matcher.ts and matches-filter.ts: every key inside one filter object ANDs, a $or array ORs its branches, and a branch's contents still AND. $and / $not handled too; field specs support $eq/$ne/$in/$nin.
  • Unimplemented operators now throw instead of being silently ignored. A test double that quietly under-implements the protocol is precisely the failure mode this PR closes, so incompleteness is loud.
  • A row-level assertion — the case the old harness structurally could not express. A fixture with a visible and an invisible record per parent type, plus a row whose parent_object belongs to one branch while its parent_id appears only in the other branch's id list. The emitted scope must return ['a1','a3']; nothing but a genuine per-branch AND excludes the other three.
  • A conformance block for the matcher itself, on the same 2x2 fixture and the same expectations as memory-matcher-or-semantics.test.ts, matches-filter-or-semantics.test.ts and sql-driver-or-filter.test.ts, so the four evaluators cannot drift apart — plus a case proving the matcher actually distinguishes a correctly paired scope from a widened one.

Proof the gate can go red

I temporarily flattened each $or branch's keys into key-level ORs in the matcher and re-ran. 9 tests failed, the row assertion loudest:

× the multi-parent $or admits only rows matching BOTH keys of one branch
  AssertionError: expected [ 'a1', 'a2', 'a3', 'a4', 'a5' ] to deeply equal [ 'a1', 'a3' ]

Every row in the fixture, where two should match. The injection was reverted; a BUG INJECTION grep over the branch returns nothing.

Verification

  • @objectstack/service-storage: 212/212 passing, 17/17 files.
  • Baseline check: the 58 failures seen on a fresh worktree reproduce identically at pristine HEAD and are stale-dist artifacts (isFileIdToken / RAW_FILE_VALUES_CONTEXT_KEY exist in packages/spec/src but not in the Jul-25 dist). Rebuilding spec + platform-objects clears all of them.
  • The changed file is type-clean; pnpm --filter @objectstack/service-storage build succeeds with DTS.

Test-only — no runtime change, hence an empty-frontmatter changeset (releases nothing).

🤖 Generated with Claude Code

…al Filter Protocol semantics (#3774)

`attachment-read-visibility.test.ts` faked its engine with a matcher that
understood implicit equality and `$in` and nothing else — no `$and`, no
`$or`, no `$not`. Every assertion could therefore only check the *shape* of
the filter `computeParentVisibilityFilter` emits, never the rows it selects.

That gap was load-bearing. The middleware's multi-parent read scope is
`{$or:[{parent_object, parent_id:{$in:[…]}}, …]}`, and driver-sql used to
compile each `$or` branch's own keys with OR instead of AND (#3774, fixed in
#3776) — widening exactly this shape into an in-tenant unauthorized read of
other users' attachments. The suite stayed green throughout: a fake that
never evaluates `$or` cannot see a `$or` widening bug.

- The matcher now implements the protocol for real, mirroring
  driver-memory's `memory-matcher.ts` and formula's `matches-filter.ts`:
  every key in a filter object ANDs, `$or` ORs its branches, a branch's own
  contents still AND. Unimplemented operators now throw rather than being
  ignored — a silently under-implemented test double is the failure mode
  this change exists to close.
- New case asserts the ROWS a multi-parent-type scope returns: attachments
  whose `parent_object` matches a branch but whose `parent_id` is absent
  from that branch's id list — including one borrowing the sibling branch's
  id — are excluded. Under the driver-sql bug this scope returned every
  attachment in the tenant instead of two.
- A conformance block pins the harness against the same 2x2 fixture and
  expectations as `memory-matcher-or-semantics.test.ts`,
  `matches-filter-or-semantics.test.ts` and `sql-driver-or-filter.test.ts`,
  so the four cannot drift apart, plus a case proving the matcher tells the
  correct scope from the widened one.

Test-only; no runtime change. service-storage: 212/212 green.

Co-Authored-By: Claude <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
objectstack Ignored Ignored Jul 28, 2026 5:40am

Request Review

@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Jul 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): packages/services.

6 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:

  • content/docs/automation/webhooks.mdx (via packages/services)
  • content/docs/kernel/runtime-services/audit-service.mdx (via packages/services)
  • content/docs/kernel/runtime-services/index.mdx (via packages/services)
  • content/docs/kernel/runtime-services/settings-service.mdx (via packages/services)
  • content/docs/plugins/packages.mdx (via packages/services)
  • content/docs/protocol/kernel/i18n-standard.mdx (via packages/services)

Advisory only. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs origin/main → pass the list as args.docs.

os-zhuang and others added 2 commits July 28, 2026 13:26
…tenant"

The #3774 widening leaked attachments to other users inside the same tenant;
it did not cross a tenant boundary. Overstating the blast radius in a
security test's comment is its own kind of wrong.

Co-Authored-By: Claude <noreply@anthropic.com>
Per this repo's split-disclosure practice for filter-widening (the exploitation
path lives in the private advisory, not in public issue/PR/changeset/test
prose), drop the specific impact framing from the test comments, the changeset
and the case name. The engineering rationale is unchanged and the assertions
are untouched: the harness could only check filter shape, not the rows a
narrowing predicate selects.

Co-Authored-By: Claude <noreply@anthropic.com>
@os-zhuang os-zhuang changed the title test(service-storage): give the attachment read-visibility harness real Filter Protocol semantics (#3774) test(service-storage): give the attachment read-visibility harness real Filter Protocol semantics Jul 28, 2026
@os-zhuang

Copy link
Copy Markdown
Contributor Author

Superseded by #3792 — same change, reopened from a branch whose commit messages follow this repo's neutral-prose practice for filter-widening work. Closing this one and deleting its branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/m tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant