By NHI Mgmt Group Editorial TeamPublished 2025-06-26Domain: Best PracticesSource: Cerbos

TL;DR: Centralised authorization only solves part of the problem if applications still fetch broad datasets and filter later, because post-filtering creates over-fetching, pagination drift, and brief in-memory exposure, according to Cerbos. Pre-filtering pushes authorization conditions into the query plan, making data access more efficient and safer by design.


At a glance

What this is: This is an analysis of post-filtering versus pre-filtering for authorization-aware data access, showing that source-level filtering reduces over-fetching, memory exposure, and pagination problems.

Why it matters: It matters because IAM, NHI, and app security teams need authorization patterns that scale without leaking data into application memory or creating brittle access checks.

👉 Read Cerbos' guide to pre-filtering versus post-filtering authorization


Context

Post-filtering is when an application retrieves a broad result set and removes unauthorized records after the fact. That pattern seems simple, but it shifts the real control point away from the database and into application memory, where performance and exposure risks increase. In identity-governed systems, that matters because access decisions are only useful if they shape what data is retrieved in the first place.

Pre-filtering reverses that sequence by turning policy into a query plan before the database returns rows. For teams building authorization around IAM and application data access, the key question is not whether access checks exist, but whether they are applied early enough to prevent unnecessary disclosure and preserve reliable pagination.


Key questions

Q: How should teams implement authorization-aware filtering in data queries?

A: Teams should compile policy into datastore queries whenever possible so the database enforces access before rows enter the application. That approach reduces exposure, improves performance, and makes pagination deterministic. If the datastore cannot enforce the rule directly, use a carefully bounded fallback and treat any post-retrieval filtering as a higher-risk exception.

Q: Why does post-filtering create security and scaling problems?

A: Post-filtering forces the application to handle a broader dataset than the user is allowed to see, which increases network load, memory pressure, and the chance of accidental exposure. It also makes pagination unreliable because the app pages through a hidden superset rather than the final authorized result set.

Q: How do organisations know whether pre-filtering is actually working?

A: Look for reduced row retrieval volumes, stable pagination behavior, and the absence of unauthorized records in application memory, logs, or caches. If the application still fetches large hidden result sets before filtering, the control is only partially working and the exposure window remains open.

Q: Who is accountable when authorization logic is split between the application and the data layer?

A: Accountability sits with the team that owns the end-to-end data access path, not just the policy author. If the application translates policy incorrectly or retrieves too much data before filtering, the control failed in architecture, implementation, or governance, and ownership must be clear across those layers.


Technical breakdown

Why post-filtering creates over-fetching and memory exposure

Post-filtering means the application fetches a large candidate set first, then evaluates authorization record by record. That works in small systems, but it scales poorly because the database, network, and application memory all absorb cost for data the user will never see. The security issue is not just final disclosure. Sensitive objects may exist briefly in application memory before being discarded, which expands the blast radius of an implementation mistake, logging bug, or memory inspection issue.

Practical implication: avoid designs where unauthorized data must enter application memory before enforcement.

How pre-filtering turns policy into a query plan

Pre-filtering uses partial evaluation or a similar policy compilation step to convert authorization rules into conditions the data layer can execute directly. Instead of asking whether each row is allowed, the application asks what conditions define eligible rows, then translates those conditions into SQL WHERE clauses or an equivalent datastore filter. The result is source-level enforcement, where the database returns only data already constrained by policy. That pattern also keeps pagination deterministic because the filtered dataset is the actual dataset being paged.

Practical implication: push authorization constraints into the query layer wherever the datastore can enforce them natively.

Why the hybrid model adds a final verification layer

The hybrid pattern combines pre-filtering with a final authorization check on the returned rows. Architecturally, that gives teams two control points: one to prevent unnecessary retrieval and another to catch policy gaps, translation mistakes, or edge cases that may slip through query compilation. This is not a substitute for correct pre-filtering. It is a second control plane for environments where the cost of a mistake is high and policy complexity makes single-stage enforcement too brittle.

Practical implication: use hybrid verification only where the assurance gain justifies the extra runtime cost.


NHI Mgmt Group analysis

Source-level authorization is the real control boundary, not the application loop. Post-filtering keeps the decision too late in the request path, which means the application becomes a temporary custodian of data the user should never have received. That is a governance flaw, not just an implementation inconvenience, because it moves enforcement away from the place that can most reliably constrain exposure. Practitioners should treat the retrieval layer as part of the authorization surface, not as a neutral transport step.

Pagination breaks when enforcement happens after retrieval. If the system fetches a large unfiltered set and then discards unauthorized rows, page size no longer maps cleanly to user-visible results. That creates inconsistent UX, unpredictable load, and hidden compliance risk because the system cannot prove that what was retrieved is what was permitted. The practical conclusion is that access policy must shape the query before paging semantics are applied.

Query-plan authorization is the named concept that matters here. This is the point where policy becomes executable data-layer logic rather than a post-hoc application check. Cerbos uses partial evaluation to produce conditional filters, but the broader governance lesson is that authorization should be compiled into the fetch path wherever possible. That is how teams reduce both operational waste and accidental exposure.

The hybrid pattern is an assurance design, not a default architecture. Pre-filtering handles efficiency and primary containment, while a final PDP check can catch translation errors or policy edge cases. That extra step makes sense in high-risk systems, but it also increases complexity, so teams should reserve it for cases where verification risk outweighs implementation overhead. The practitioner takeaway is to match assurance depth to the sensitivity of the data and the brittleness of the policy logic.

From our research:

What this signals

Query-plan authorization is becoming the practical dividing line between systems that merely check access and systems that actually contain it. As applications move more decisions into the data layer, the security conversation shifts from policy expression to enforcement placement, which is where operational risk is either reduced or amplified.

The data point that should concern programme owners is that 96% of organisations store secrets outside of secrets managers in vulnerable locations including code, config files, and CI/CD tools, according to the Ultimate Guide to NHIs. That is the same governance pattern in a different form: controls that sit too late in the lifecycle leave sensitive material exposed before policy can act.

Teams that are standardising around zero trust should align access filtering with the NIST Cybersecurity Framework 2.0 function of protecting data at the point of retrieval, not after exposure has already occurred. That is where architecture becomes governance, and where governance becomes measurable.


For practitioners

  • Move authorization into the query path Translate policy conditions into datastore-native filters so the database returns only rows already constrained by access rules. This reduces over-fetching and prevents unauthorized records from entering application memory.
  • Audit pagination after filtering Test whether page size, offsets, and result counts remain stable when authorization conditions are applied before retrieval. Pagination should reflect the visible dataset, not a hidden superset.
  • Reserve hybrid verification for high-assurance paths Add a final authorization check after pre-filtering only where policy complexity, sensitivity, or regulatory exposure justifies the added runtime cost. Do not use it to compensate for weak query design.
  • Instrument retrieval-layer exposure Measure how much unauthorized data is fetched, cached, or logged before filtering occurs, then set reduction targets for any system that still depends on post-filtering.

Key takeaways

  • Post-filtering is easy to understand but costly to operate because it forces applications to retrieve data they will later discard.
  • Pre-filtering makes authorization part of the query itself, which improves security, pagination reliability, and performance at the same time.
  • The right architecture depends on assurance needs, but high-risk environments should treat hybrid verification as a targeted control, not a replacement for source-level filtering.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

OWASP Non-Human Identity Top 10 address the attack and risk surface, while NIST CSF 2.0 and NIST Zero Trust (SP 800-207) set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
NIST CSF 2.0PR.AC-4Access enforcement must happen before data retrieval to limit exposure.
NIST Zero Trust (SP 800-207)JITContinuous verification is undermined if unauthorized data enters application memory first.
OWASP Non-Human Identity Top 10NHI-03The article's control logic depends on timely policy enforcement, similar to lifecycle and access scope governance.

Treat data retrieval paths as governed assets and remove broad access wherever policy can be compiled into queries.


Key terms

  • Post-Filtering: A data access pattern where an application retrieves a broad result set first and removes unauthorized records afterward. It is simple to build, but it increases load, complicates pagination, and briefly exposes sensitive data inside the application before enforcement completes.
  • Pre-Filtering: A data access pattern where authorization conditions are applied before the datastore returns rows. The query itself is constrained by policy, so the system only receives data the user can already see, reducing exposure and making paging more reliable.
  • Partial Evaluation: A policy-processing technique that converts authorization rules into conditional expressions the data layer can execute. It separates what is known at request time from what can be decided later, allowing the system to compile policy into a usable query plan.
  • Query Plan: An executable set of conditions that tells the data layer what rows may be returned for a given request. In authorization-aware systems, the query plan turns access policy into retrieval logic so enforcement happens at the source, not after data has already been fetched.

Deepen your knowledge

NHI governance, agentic AI identity, and machine identity lifecycle are core topics in our NHI Foundation Level course, the industry's only accredited NHI security programme. If you are responsible for identity security strategy or NHI governance in your organisation, it is worth exploring.

This post draws on content published by Cerbos: pre-filtering versus post-filtering authorization for data access. Read the original.

NHIMG Editorial Note
Published by the NHIMG editorial team on 2025-06-26.
NHI Mgmt Group — the independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org