~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
ADR-0009: The encrypted per-user database is the isolation boundary
Date: 2026-08-09 Status: Accepted
The rule
Every user's data lives in their own SQLCipher database, encrypted with their own password. That database is the isolation boundary: two users cannot read each other's rows because they cannot decrypt each other's files.
Data stored anywhere else does not inherit that isolation. Not on the filesystem, not in a module-level dict, not in a cache, not in a registry. Those live in one process and one directory tree shared by every user, and they are isolated only to the extent that the code touching them checks ownership by hand.
This is worth stating explicitly because the safety is invisible at the call
site. db_session.query(Document).filter(Document.id == doc_id).first() is
safe against cross-user access for free — the session can only see one
user's data. The visually identical self._runs[run_id] or
library_root / f"{resource_id}.txt" has no such protection, and nothing in
the surrounding code looks different.
The specific trap: per-user IDs collide
Most tables use autoincrement integer primary keys. Because each user has their own database, those sequences restart per user — so user A's first row and user B's first row are both id 1. That is normal and harmless while the id is only ever used inside its own database.
It becomes a cross-user defect the moment such an id is used as a key into anything shared:
# WRONG — `run_id` is only unique within one user's database
self._active[run_id] = {...} # process-global dict
path = library_root / f"doc_{doc_id}.txt" # shared directory
Two users doing the same thing collide on the same key. The failure is not a crash — it is one user silently reading, overwriting, or being handed the other's data. And because small integers are guessable, "collides by accident" and "is reachable on purpose" are the same bug.
Review passes on this codebase have found this shape in more than one subsystem: shared on-disk paths keyed by per-user row ids, and process-global dictionaries keyed the same way. It is not a one-off.
The confirmed instance, four times over
The benchmark progress stream is the worked example, and it is worth recording
in detail because four independent review passes found it, none of them by
reading a single file. Two process-global dicts —
web/services/socketio_asgi.py's _subscriptions and
benchmark_service.active_runs — were both keyed by a bare
BenchmarkRun.id. That id autoincrements inside each user's own database, so
every user's first benchmark run is id=1, and two users' run 1 collided
in a process-global map.
Release status of the confirmed instance
The confirmed instance was fixed by fa466ad13 ("fix(security): cross-user
isolation for benchmark runs, research termination, and follow-up", #5600),
merged to main on 2026-08-26. The fix first shipped in v1.10.6 and is
also present in v1.10.7, the latest public release on 2026-09-01. Users
of earlier releases should upgrade to the current release.
This is a historical remediation record, not a live support or vulnerability-
status page. Consult current release notes and SECURITY.md when assessing a
deployed version.
Current state on main and this branch, verifiable at a glance:
socketio_asgi.py—_subscriptions: dict[tuple[str, str], set[str]]benchmarks/web_api/benchmark_service.py—active_runs: Dict[Tuple[str, int], Dict]
The concrete reproduction stays out of this document. This ADR records the
isolation rule and remediation history, not exploitation steps. See
SECURITY.md for the disclosure route.
The reason it survived so many earlier reviews is the shape described above: the route's ownership check is correct. It looks up the run in the caller's own database and 404s if it is not theirs — which is real protection against reading someone else's row, and reads as sufficient. The leak is one layer down, where the id that just passed that check is used as a global key. No reviewer looking at the handler sees anything wrong, and no reviewer looking at the dict knows where its keys come from. This is why ADR-0008 gained a "partition by behaviour, not only by file" pass: the defect exists between the two files and is invisible in either.
The same PR contains the correct pattern, which is the useful part:
web/routers/rag.py keys _active_sse_indexers and _start_bg_index_locks by
(username, id) tuples. Same codebase, same release, same kind of state — so
the fix is not a new technique to invent, it is an existing local convention
that the benchmark path did not follow.
What to do instead
Prefer the encrypted database. If the data can live in the user's own database, put it there and the problem does not exist.
If it must live outside, do all three:
- Key it by
(username, id), never byidalone — or by a value that is globally unique, such as a UUID or a hash that includes the username. - Check ownership on every access, including reads — a listing endpoint that filters by user is not enough if the detail, mutate, and delete endpoints take a raw id.
- Clear it when the user goes away — on logout, on password change, and on the idle-connection sweep. All three, not just logout: most users close the tab rather than clicking log out.
A good existing example is the RAG index path, which is
cache/rag_indices/<sha256(username)[:16]>/<sha256(config)>.faiss with 0700
on both levels. The username is in the path, so collision is impossible by
construction rather than by remembering to check.
That example is worth reading in full, because it is this exact bug already
found and fixed once. Its docstring records what the previous layout did: a
shared cache/rag_indices/ "would let one user's vectors land in another
user's load path in any deployment running more than one account against the
same data dir." Two users with the same collection name and embedding model
collided on the same file. The fix was to put the username in the path — and
the reason this ADR exists is that the same shape kept reappearing elsewhere,
because the lesson was recorded in one function's docstring rather than as a
rule.
research_library/utils/__init__.py::get_library_storage_path(username) is
another: it returns base_path / username by default and only collapses to a
shared directory when an operator explicitly opts in. Code that needs a
library path should call that helper rather than reading the shared root
directly — a helper only helps if it is the thing being called.
CORRECTED 2026-08-25 — the finding below is CLOSED and was never true of this branch's merge state. It was written on 2026-08-14 against the tree at that moment and fixed the next day in
b254e0ed1; the paragraph was never revised, so it read as a live cross-user data leak long after it stopped being one. At HEAD both call sites scope by user:web/routers/library.py:464andresearch_library/services/download_service.py:176-177both callapply_user_subdir(base_root, username, shared_library). It is not true ofmaineither (see issue #5521). The reasoning it draws is still sound and is why the paragraph is corrected rather than deleted.
A later audit foundThe correct helper existing next to the incorrect call sites is the normal state of affairs, not an anomaly — which is why "call the helper" is too weak a rule to rely on. Where it matters, delete the unsafe path or make the helper the only way to obtain a root, so the wrong call cannot be written. Until then, treat every raw read of aget_library_storage_pathhas zero real callers:library.py'sview_pdf_pageanddownload_service.py'sDownloadService.__init__both build their root straight from the raw sharedresearch_library.storage_pathsetting, with no username component anywhere.*.storage_pathsetting as a finding.
Credentials get a stricter rule
The user's password is the key to their database. Anything holding it in memory — a thread-local cache, a scheduler's session map, a background job's captured context — is holding the means to decrypt that user's data for as long as it lives there.
Such a store must be cleared on logout and password change and the idle sweep. Missing one of the three is the recurring bug: repeated review passes have each found a different store that one of those paths forgot, because each was added at a different time by someone who only knew about the stores that existed then.
If you add a place where a password can rest, add it to all three teardown paths in the same commit.
Why this is an ADR and not a lint rule
We cannot mechanically tell a safe self._cache[key] from an unsafe one — it
depends on whether key is unique across users, which is a fact about the
data, not the syntax. A guard would either miss the real cases or drown in
false positives.
What is mechanisable, and worth adding when a specific store is fixed, is a
test that the store is empty for a user after logout, after password change,
and after the idle sweep. tests/security/test_logout_clears_thread_credentials.py
and the corresponding assertions in tests/web/auth/test_connection_cleanup.py
are the pattern to copy.
Consequences
- Reviewers should treat "is this keyed per user, and who checks?" as a standing question for any module-level mutable state or filesystem path.
- Multi-user deployments are the exposed case. Single-tenant installs are unaffected by collisions, which is precisely why these defects survive: the developer's own instance never reproduces them.
- Operator-facing toggles that relax isolation (shared storage, for example)
belong behind an environment variable rather than a user-editable setting,
so that a user cannot widen the boundary the operator set. This matches how
the
unprotectedegress scope is gated (see ADR-0007).