feat(data): authorized materialized views via auth fingerprint (0226)#277
Merged
crs48 merged 6 commits intoJun 26, 2026
Merged
Conversation
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>
Contributor
|
Preview removed for PR #277. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
subject DID + grant-state version(COUNT/MAX(updated_at)overGrant+/sys/authznodes — ordinary data writes don't move it).NodeReadAuthorizer, wired to the store'sfilterReadableNodes), then serves cache hits with no per-row re-checks.authz-changedrefresh reason → re-materialize. The cached id list can never serve a row a revoked viewer may no longer read.Changes
@xnetjs/sqlite):node_query_materializations.auth_fingerprint(schema v7 + DDL + migration + defensivePRAGMAcolumn guard for in-place upgrades).@xnetjs/data): authorizer applied at refresh;getAuthorizationStateVersion();authz-changedreason; skip the authz-blind parity audit.@xnetjs/data): newquery()path that materializes under authz;authFingerprint()+ support guard; wires the authorizer.Tests
authz-changedre-materialization (the critical revocation test), and authz-state versioning (grants +/sys/authz, not data writes).query()path persists under authz + re-materializes excluding a revoked row; and falls back safely when storage can't fingerprint.formatPlanRowssurfaces view id / cache outcome / refresh reason.All green;
@xnetjs/data,@xnetjs/sqlite,@xnetjs/devtools,@xnetjs/data-bridge,@xnetjs/reacttypecheck.Deferred (follow-up)
Part 3 of the exploration — at-rest encryption of the local store (
nodeContentCipherwiring inapps/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