Access rules
A published table without rules exposes every row to any caller that passes both API switches. Access rules restrict records per caller.
Each table has four rules, set on the table's access panel: create, read, update and delete. Each rule is a SQLite boolean expression. An empty rule means no restriction.
_ROW_.owner = _USER_.idReferences
| Reference | Resolves to |
|---|---|
_USER_.id |
Id of the calling account. |
_USER_.role |
Role of the calling account: admin, consumer or user. |
_USER_.scope |
Customer the calling account is limited to. NULL when the account has none. |
_ROW_.<field> |
A field on the stored record. NULL on create. |
_REQ_.<field> |
A field in the request body. |
References are rewritten into json_extract calls and bound parameters; the rest of the expression is passed to SQLite unchanged. Any expression valid in a SQLite WHERE clause is accepted.
_ROW_.status = 'open' AND _ROW_.owner = _USER_.id_REQ_.total < 1000_USER_.role = 'consumer'The last example refuses end-user JWTs and allows service tokens.
Evaluation
| Operation | Rule result false or NULL |
|---|---|
List (GET /records) |
Row omitted from the result |
| Get, create, update, delete | 403 |
| Live updates (SSE) | Event not delivered |
A rule that refers to a deleted record evaluates as a refusal. Live updates re-read the rule for every event; a changed rule applies to open streams. The role reaches every evaluation: single-record checks, list filters, relation expansion, transactions, SSE and the wire views.
Per-customer scope
To limit each account to one customer's rows, set the account's Scope (for example ACME) and choose a Scope by field on the endpoint. The field must be a text, select or reference field.
On a scoped endpoint:
- lists, gets, live updates and the wire views show only rows whose field equals the caller's scope;
- a create stores the caller's scope in the field, whatever the request sent;
- an update cannot change the field, and update or delete of another customer's row is
403; - an account without a scope sees no rows and cannot create.
The scope is applied on top of the four rules above and cannot be removed by editing them. The field is marked read-only in the OpenAPI document. Forms are not scoped.
Field rules
A field can carry its own read rule and write rule, set in the field editor. They use the same references and syntax as the table rules.
- A read rule that is
falsefor a record removes the field from that record in lists, gets, write responses, expansions and live updates. On the wire views the column readsNULL. A read rule cannot use_REQ_. - A write rule is checked when a request sets the field.
falseanswers403. APUTreplaces every field, so it is checked against every field that has a write rule. - A field with a read rule cannot be used in
filterorsort, and search skips it.
_USER_.role = 'consumer'A calculated or derived field computed from a guarded field shows the result to everyone; give it the same read rule.
Validation
Rules are validated when the table is saved. The save is refused for:
- an unknown field name or alias (only
_USER_,_ROW_and_REQ_); ;, comments (--,/*),{or};- parameter markers (
?,$,:,@) outside a quoted string; - an unclosed quote or bracket, or unbalanced parentheses;
_USER_,_ROW_or_REQ_inside a quoted string;- anything SQLite rejects.
Scope
- The console (
/api/_admin/*) is never filtered. - The Postgres and TDS listeners apply read rules like the REST API. They authenticate with an API token and expose published tables only, each as a view filtered by its read rule. A SQLite authorizer blocks direct reads of the underlying tables, including
_usersand_settings.
Baseport