Skip to content

feat(data): authorized materialized views via auth fingerprint (0226)#277

Merged
crs48 merged 6 commits into
mainfrom
claude/0226-persistent-and-secure-materialized-views
Jun 26, 2026
Merged

feat(data): authorized materialized views via auth fingerprint (0226)#277
crs48 merged 6 commits into
mainfrom
claude/0226-persistent-and-secure-materialized-views

Conversation

@crs48

@crs48 crs48 commented Jun 26, 2026

Copy link
Copy Markdown
Owner

What

Implements part 1 of exploration 0226 — Persistent And Secure Materialized Views: the auth-fingerprint mechanism that lets a materialized view persist across reloads and coexist with read authorization, without per-cell checks.

The problem

Materialized views (node_query_materializations, OPFS-backed) persist across reloads today — but the store disabled them entirely whenever a read-authorization evaluator was active, throwing away the cross-reload cache exactly when authz exists. The alternative the user worried about — "authorize once at login, never re-check" — is unsafe: a grant revoked between materializations would leak rows (the well-known stale-RLS-over-materialized-view bug).

The fix — authorize once per materialization, not per cell and not per login

  • Each materialization is stamped with a reload-stable auth fingerprint = subject DID + grant-state version (COUNT/MAX(updated_at) over Grant + /sys/authz nodes — ordinary data writes don't move it).
  • Storage authorizes the id list once at refresh (new injected NodeReadAuthorizer, wired to the store's filterReadableNodes), then serves cache hits with no per-row re-checks.
  • Any grant change shifts the fingerprint → a new authz-changed refresh reason → re-materialize. The cached id list can never serve a row a revoked viewer may no longer read.
  • Fails closed: if storage can't fingerprint/authorize, the store falls back to the existing authorize-then-paginate path (no caching).

Changes

  • schema (@xnetjs/sqlite): node_query_materializations.auth_fingerprint (schema v7 + DDL + migration + defensive PRAGMA column guard for in-place upgrades).
  • adapter (@xnetjs/data): authorizer applied at refresh; getAuthorizationStateVersion(); authz-changed reason; skip the authz-blind parity audit.
  • store (@xnetjs/data): new query() path that materializes under authz; authFingerprint() + support guard; wires the authorizer.
  • devtools: plan inspector now shows the materialized view id + refresh reason.
  • docs: materialized views documented as local-derived, never-synced.

Tests

  • Adapter: reload (fresh adapter on same DB → cache hit), authorize-once + authz-changed re-materialization (the critical revocation test), and authz-state versioning (grants + /sys/authz, not data writes).
  • Store: full query() path persists under authz + re-materializes excluding a revoked row; and falls back safely when storage can't fingerprint.
  • devtools: formatPlanRows surfaces view id / cache outcome / refresh reason.

All green; @xnetjs/data, @xnetjs/sqlite, @xnetjs/devtools, @xnetjs/data-bridge, @xnetjs/react typecheck.

Deferred (follow-up)

Part 3 of the exploration — at-rest encryption of the local store (nodeContentCipher wiring in apps/web + a Settings toggle, checklist items 6–7) — is intentionally not in this PR. It's a larger, security-sensitive feature spanning identity → app → worker → store with a data-migration dimension and needs real browser/passkey/OPFS verification. The exploration stays [_] until it lands, matching the doc's "ship part 1 first" staging.

🤖 Generated with Claude Code

xNet Test and others added 5 commits June 25, 2026 17:25
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Materialized views were disabled whenever a read-authorization evaluator
was active, throwing away the cross-reload cache exactly when authz
exists. Stamp each materialization with a reload-stable authorization
fingerprint (subject DID + grant-state version) so a view can be
authorized ONCE at refresh and served from cache without per-row
re-checks — while any grant change forces an 'authz-changed'
re-materialization. The persisted id list can never serve a row a
revoked viewer may no longer read.

- schema: add node_query_materializations.auth_fingerprint (v7 + DDL +
  defensive PRAGMA column guard for in-place upgrades)
- adapter: inject a NodeReadAuthorizer that filters the id list at
  refresh; getAuthorizationStateVersion() over grants + /sys/authz;
  'authz-changed' refresh reason; skip authz-blind parity audit
- store: wire filterReadableNodes as the authorizer; new query() path
  that materializes under authz; authFingerprint() + support guard

Exploration 0226.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…inspector

The Data panel plan inspector now surfaces the materialized view id and,
on a cache miss, the refresh reason (including the new 'authz-changed'
from exploration 0226) alongside the existing hit/miss row.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add a doc comment at queryMaterializedView making explicit that a
materialized view is a purely local, derived cache (id list + order),
never part of the change log and never synced — it carries no authority
and is safe to rebuild or drop. Add a reload test proving a fresh
adapter on the same DB serves the view from persisted SQLite.

Exploration 0226.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Check off the validation items proven by automated tests (reload,
invalidation, authz-revocation, fingerprint coverage), note that at-rest
encryption (items 6-7) is deferred to a follow-up, and add the changeset
+ changelog fragment for the @xnetjs/data + @xnetjs/sqlite feature.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@crs48 crs48 temporarily deployed to pr-277 June 26, 2026 00:51 — with GitHub Actions Inactive
@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Preview removed for PR #277.

github-actions Bot added a commit that referenced this pull request Jun 26, 2026
@crs48 crs48 temporarily deployed to pr-277 June 26, 2026 01:06 — with GitHub Actions Inactive
@crs48 crs48 merged commit 869f060 into main Jun 26, 2026
15 checks passed
@crs48 crs48 deleted the claude/0226-persistent-and-secure-materialized-views branch June 26, 2026 01:15
github-actions Bot added a commit that referenced this pull request Jun 26, 2026
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