Polar partial evaluation: keep authorization filters inside the query boundary

Authorization usually answers a yes or no question. Data filtering asks a harder one: which records may this subject see? Oso's Polar language supports partial evaluation, allowing policy logic to become a filter that is applied to a data source. The technique is useful because sending every candidate record to an authorization service is slow and can leak the size or shape of the result set.

The security property depends on how the filter is built. A policy that says an analyst may list cases in an organization should become a constraint on tenant, membership, and the requested case state, not a string concatenation of user input. The query builder must preserve types, quote values, and reject unsupported comparisons. If the application evaluates the policy in one layer and then drops or rewrites the resulting condition in another, the decision no longer matches the filter.

Oso describes data filtering as translating authorization logic into a query for an existing data source. That translation should be reviewed with the same care as a hand-written access-control query. Tests need to cover nullable fields, wildcard relations, nested groups, and a resource that matches multiple rules. A union of permitted conditions can be correct, but one accidental true branch turns the whole filter into a broad read.

Partial evaluation also changes the trust boundary with clients. A client-side or local authorization path may receive a filter rather than a list of allowed IDs. The filter must be treated as sensitive policy output, not a hint that a client can modify. If a browser applies the filter to a local dataset, the server still needs to authorize any mutation or sensitive read that returns data. Client enforcement can reduce user-visible leakage, but it cannot be the only guard for data the client does not already possess.

The policy's data model matters. Relationships should have explicit directions, and the application should not infer that a nested membership automatically grants every operation on every child object. Field-level access is separate from record-level access. A filter that returns a visible row does not necessarily make every property in that row readable.

Good tests compare the policy result with a database result for the same subject. For a small fixture, evaluate every action and every object, then compare the allowed set with what the filtered query returns. Add a canary record that no ordinary role should see. If the canary appears after a policy refactor, the problem is visible before it reaches a production page.

The implementation record should name the policy version, the data model version, and the query builder used by each service. Partial evaluation is a way to move policy closer to data without hiding the decision. The filter is part of the authorization system, and it deserves observability and a rollback plan.

References