Skip to content

Add accessor field to authorizer rules#216

Merged
penberg merged 1 commit intotursodatabase:mainfrom
beauwc:beau/add-accessor-to-authorizer-rules
Apr 4, 2026
Merged

Add accessor field to authorizer rules#216
penberg merged 1 commit intotursodatabase:mainfrom
beauwc:beau/add-accessor-to-authorizer-rules

Conversation

@beauwc
Copy link
Copy Markdown
Contributor

@beauwc beauwc commented Apr 4, 2026

Description

Adds an optional accessor field to authorization rules, exposing SQLite's 4th authorizer callback argument — the innermost trigger or view that caused the authorization check.

When querying through a view, SQLite's authorizer fires READ callbacks with the underlying table name, not the view name. Without the accessor field, the only way to allow view-based access while blocking direct table access is to materialize the view into a temporary table.

With the accessor field, rules can scope reads by the view context:

{ action: Action.READ, table: "data", accessor: "my_view", policy: Authorization.ALLOW }

This allows SELECT * FROM my_view (accessor = "my_view") but blocks SELECT * FROM data directly (accessor = null). The accessor field supports exact strings and { glob: "pattern" }, same as other pattern fields.

The libsql Rust crate already exposes this as AuthContext.accessor: Option<&str> — this PR wires it through to the JS rule-matching system.

How was this change tested?

  • Automated test (unit, integration, etc.)
  • Manual test (provide reproducible testing steps below)

Four integration tests added covering view-scoped access, direct access blocking, glob pattern matching on accessor, and subquery escape prevention.

Expose SQLite's 4th authorizer callback argument (the innermost trigger
or view that caused an authorization check) as an optional `accessor`
field on authorization rules.

This enables view-scoped authorization: a rule can allow reads from an
underlying table only when accessed through a specific view, while
blocking direct table access. For example:

  { action: Action.READ, table: "data", accessor: "my_view", policy: Authorization.ALLOW }

This rule allows reads from "data" only when the read is driven by
"my_view" (accessor = "my_view"), and blocks direct SELECT on "data"
(where accessor is null).

The accessor field supports the same pattern matching as other fields:
plain strings for exact match, or { glob: "pattern" } for wildcards.
@beauwc beauwc marked this pull request as ready for review April 4, 2026 21:37
@penberg penberg merged commit 8d2a263 into tursodatabase:main Apr 4, 2026
7 checks passed
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.

3 participants