For security reviewers#
Where to start when reviewing needtoknow: what to read, which code decides what, the contracts it relies on, the APIs worth a second look, the evidence, and how to reproduce it. No independent security audit has been carried out yet. Everything below is the project’s own work, which a review should check rather than take on trust.
Scope#
The needtoknow package: the retriever, the filter language, the authorizers, the caching layer,
the store backends and the framework adapters. The example gateway in examples/gateway is a
separate deployment with its
own threat model.
Read first#
Security model: what is guaranteed, what is assumed, and the invariants S1 to S10 with the tests that hold each one.
Threat model: assets, trust boundaries, seventeen threats, remaining risks.
Concepts: pre-filtering, post-filtering, the re-check, failing closed.
Revocation and consistency: where staleness comes from, and the two ways to configure it.
Operations: the cache, the shared cache, retries and the circuit breaker, audit events, alerts.
Supported configurations: what CI tests, and what it does not.
The code, by what it decides#
Module |
Decides |
Read for |
|---|---|---|
|
Which strategy runs, the pre-filter and its re-check, post-filtering and how far it widens, reranking, the validation of every answer, the events |
Every result passes through it. One plan serves |
|
The filter language and |
Every store translation must agree with |
|
|
Composition, and when a combined filter or scope exists. |
|
Cached decisions, the shared cache, signing, epochs, |
Revocation and replay. |
|
Requests to OPA, OpenFGA, SpiceDB and Cerbos, and the parsing of their answers |
Partial, malformed and truncated answers. |
|
Each store’s translation of a filter into its query |
Injection, type confusion, a filter made broader. |
|
How each framework binds the subject |
Impersonation by a client or a model. |
The contracts#
A backend returns hits best first, applies a filter exactly as
matchesdefines it, returns “nothing can match” as no results (never as no filter), and returns each chunk’s metadata as stored.needtoknow.testing.check_backendchecks all four, and every built-in backend passes it against its real store in CI.An authorizer’s
checkreturns one realboolper hit, in order;filter_forreturns a filter that selects exactly whatcheckallows, or None;scope_for, when present, returns a condition every readable chunk meets.needtoknow.testing.check_authorizerchecks the first two agree. Any failure raises, and the retriever then returns nothing.The subject comes from your authentication. needtoknow cannot verify it.
APIs that deserve a second look#
PermissionedRetriever(recheck=False): pre-filtered hits are matched against the filter locally but not decided by the authorizer again, so a filter broader than the authorizer’s own check goes unnoticed.CachingAuthorizer(shared=...)with the defaultnamespace: two differently configured authorizers sharing one Redis and namespace share answers.RedisCachewithoutsigning_key: whoever can write to that Redis can plant decisions.FunctionAuthorizerwith afilter_forbroader than itscheck: the re-check catches it (as violations);recheck=Falsedoes not.OpenFGAAuthorizer(contextual_groups=True)andSpiceDBAuthorizer(group_subjects=True): the subject’s groups are trusted as given.SpiceDBAuthorizer’s default consistency,minimizeLatency, and OpenFGA’s default,MINIMIZE_LATENCY: answers can trail a write.Subject.attributes: part of every cache key, and the tenant’s source forTenantAuthorizer; it must come from authentication like the rest of the subject.
The evidence#
Tests. Over 500, many of them Hypothesis property tests, compared with oracles written without the library’s filter code. CI runs them on Python 3.11 to 3.14 on Linux, the library tests on macOS and Windows too, and the suites against 10 vector stores and 4 permission services running as real servers. Branch coverage must stay at 90% or more for the package and 95% or more for the code that decides access (the retriever, filters, authorizers and cache).
Fuzzing. ClusterFuzzLite (Atheris) fuzzes filter parsing and the translations that write query text, on pull requests and weekly.
Static analysis. CodeQL on every change; ruff with the bandit rules; mypy
--strict.Supply chain. Every CI and release install is pinned by hash in
uv.lock; releases are built in GitHub Actions, published with trusted publishing, signed with Sigstore, and carry a CycloneDX SBOM, with SLSA provenance from 1.4.0. After each release a workflow installs it from PyPI, pinned to the hash of the file on the GitHub release, and runs it. OpenSSF Scorecard runs on every change, and a check fails when one of its scores drops.Dependencies. The core has none at run time. The optional extras and the test tools are listed with their hashes in
uv.lock, and each release’s SBOM lists what it was built with. Advisories that have no fix yet are listed with reasons inosv-scanner.toml.Benchmarks. Benchmarks: recall, latency and leak checks at up to a million chunks, with the scripts and settings to reproduce them.
Reproducing it#
Without external services:
pip install -e ".[dev]", thenpytest. The suites that need a store or a permission service skip themselves.With them: the
testjob in.github/workflows/ci.ymlstarts each server (images and versions are listed there) and sets theNEEDTOKNOW_TEST_*variables that switch each suite on. Run the same containers and set the same variables.For your own backend or authorizer: the conformance kit.
Findings so far#
Found by the project’s own review and tests, all fixed with regression tests. The first six are published as advisory GHSA-prfv-2pwr-5rx2.
Found |
Problem |
Fixed in |
|---|---|---|
October 2026 |
|
1.2.1, 1.3.1 |
October 2026 |
With a shared cache, a retrieval running during |
1.2.1, 1.3.2 |
October 2026 |
|
1.2.1, 1.3.1 |
October 2026 |
An |
1.2.2, 1.3.3 |
October 2026 |
In the invalidating process, a read of the global epoch already in flight could put back the epoch it replaced, for up to |
1.2.2, 1.3.3 |
October 2026 |
An |
1.2.2, 1.3.3 |
October 2026 |
Epochs stored as raw bytes broke shared caches whose Redis client decodes responses: every lookup went to the permission service |
1.2.2, 1.3.3 |
October 2026 |
A retrieval event that could not be built replaced the retrieval’s result or error |
1.3.3 |
October 2026 |
A ListObjects answer cut short by OpenFGA’s deadline was used as a complete pre-filter (results hidden, reported complete) |
next release |
October 2026 |
With |
next release |
October 2026 |
A subject attribute named |
next release |
October 2026 |
A cancelled retrieval produced no audit event |
next release |
October 2026 |
The example gateway stored API keys as unsalted SHA-256 |
the gateway example |
Reporting#
Report anything you find privately, as SECURITY.md describes.