Skip to content

~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.

docs(readme): add an egress-control section to the security overview (#6612)

LearningCircuit1b3d118bc71f
diff --git a/README.md b/README.md
index 7565b85cce..23ca4159d5 100644
--- a/README.md
+++ b/README.md
@@ -161,7 +161,7 @@ flowchart LR
Your data stays yours. Each user gets their own isolated SQLCipher database encrypted with AES-256, with the key derived from your password. Your password is never stored — login works by attempting to decrypt your database, so the database files on their own are unusable to anyone who obtains them. Per-user LLM API keys live encrypted inside the same personal database rather than in a shared server-level store.
-The [Docker setup](docker-compose.yml) ships with `cap_drop: ALL`, `no-new-privileges`, and a non-root runtime, with the bundled Ollama and SearXNG images pinned by digest. Or run fully local with Ollama + SearXNG and nothing ever leaves your machine.
+The [Docker setup](docker-compose.yml) ships with `cap_drop: ALL`, `no-new-privileges`, and a non-root runtime, with the bundled Ollama and SearXNG images pinned by digest. With a model running in the bundled Ollama, inference runs on your own hardware. LDR judges locality mainly by provider and endpoint address, not by where the model runs, so a local endpoint that relays to a hosted model (an Ollama cloud model, or a local LiteLLM or other OpenAI-compatible proxy in front of a hosted API) can still send your prompts off the machine without being detected. A self-hosted SearXNG still forwards your search queries to its upstream engines on the internet. To keep a run on private sources, search only local sources (collections, your library) under the *Private only* egress scope described below. That scope is a best-effort guard rail, not an air gap: see the Egress control section below and [SECURITY.md](SECURITY.md#egress-policy-module).
**In-memory credentials**: Like any application that uses secrets at runtime, credentials are held in process memory during active sessions — mitigated with session-scoped credential lifetimes and core dump exclusion. See the [Security Policy](SECURITY.md#in-memory-credentials) for the full threat model.
@@ -171,6 +171,33 @@ The [Docker setup](docker-compose.yml) ships with `cap_drop: ALL`, `no-new-privi
[Detailed Architecture →](docs/architecture.md) | [Security Policy →](SECURITY.md) | [Security Review Process →](docs/processes/security-review-process/)
+### 🌐 Egress control
+
+Every research run has an **egress scope** that restricts, on a best-effort basis, where its traffic may go: which search engines run, whether the LLM and embeddings may be cloud services, and which result URLs may be fetched. Set it under *Settings → Egress Scope* or in the *Privacy & Egress* panel on the research form; choosing a scope in the panel also saves it as your default setting, so later runs use it too.
+
+| Mode | Search sources | Inference |
+|---|---|---|
+| **Adaptive** *(default)* | follows your primary engine: a public engine behaves like *Public only*, a private collection or your library like *Private only*; a locally stored collection you marked public as primary allows any classified engine, private collections included | forced local only when the run is private |
+| **Public only** | public web and academic engines; private collections and local document stores classified as private are excluded (a document store whose URL resolves to a public host, or does not resolve, is normally treated as public) | your configured providers; a document-store primary with a cloud model is normally refused at start for research run through the web research form (not for entry points that call the research functions directly, such as `/api/v1/quick_summary` or MCP) |
+| **Private only** | local sources only (collections, library, local document stores such as Paperless) | **forced local**; cloud providers are normally refused |
+| **Strict** | your single primary engine, no expansion | not forced local, but cloud models usually do not work under Strict (see the Strict section of [Egress modes](docs/egress-modes.md)) |
+| **Unprotected** | anything; unavailable unless the operator sets `LDR_POLICY_ALLOW_UNPROTECTED_EGRESS=true` | normally anything (an operator's environment lock on the require-local settings still applies) |
+
+*Strict* and *Private only* (including an Adaptive run that resolves to it) also arm a best-effort socket-level guard on the research run that normally refuses connections to public addresses. It is a backstop with known gaps, not a guarantee; the Strict section of [Egress modes](docs/egress-modes.md) lists some of them, such as a forward proxy or a relay on a private address. Under *Strict*, public engines, public result fetches and cloud model calls therefore usually fail, so pair it with a local engine and local models.
+
+A locally-hosted SearXNG counts as a public engine — it proxies searches to the internet — so it is not available under *Private only*. Under *Strict* it may still run as your primary engine, and it then forwards your queries to its upstream engines on the internet.
+
+LDR's guarded HTTP layer, used for most search-result and document fetches, also checks destinations against SSRF rules (including known cloud-metadata addresses such as `169.254.169.254`) and re-checks redirects. With JavaScript rendering enabled (`web.enable_javascript_rendering`, off by default), pages that need it are loaded in headless Chromium, which resolves addresses itself. See the [egress module README](src/local_deep_research/security/egress/README.md) for the details.
+
+Whether a signed-in user can point a search engine at a private address depends on the kind of engine:
+
+- **Public engines with a configurable address** (currently SearXNG): a private or loopback URL is normally refused unless the operator opts in through the environment (`LDR_SEARCH_ALLOW_PRIVATE_ENGINE_URLS=true`, an exact origin in `LDR_SEARCH_PRIVATE_ENGINE_URL_ALLOWLIST`, or pinning the URL itself with `LDR_SEARCH_ENGINE_WEB_SEARXNG_DEFAULT_PARAMS_INSTANCE_URL`). A SearXNG on `localhost` therefore normally needs one of these.
+- **Local document-store engines** (Paperless-ngx and Elasticsearch): their address settings, `search.engine.web.paperless.default_params.api_url` and `search.engine.web.elasticsearch.default_params.hosts`, are meant to point at private hosts, so currently no opt-in applies: any signed-in user can set them to an internal address and the server will connect to it. If that is not acceptable, pin these settings with their environment variables (`LDR_` plus the key in upper case with dots replaced by underscores, for example `LDR_SEARCH_ENGINE_WEB_PAPERLESS_DEFAULT_PARAMS_API_URL`), or lock settings changes with `LDR_APP_LOCK_SETTINGS=true`.
+
+The egress policy is an in-process guard rail against misconfiguration and prompt-injected fetches, not an air gap or a hard security boundary: for example, hostnames are still resolved through the configured DNS resolver before a fetch is refused, and it cannot reliably constrain code that runs inside the LDR process. For a hard boundary, add egress filtering at the container or firewall level as well.
+
+[Egress modes →](docs/egress-modes.md) | [Threat model and caveats →](SECURITY.md#egress-policy-module) | [Enforcement points →](src/local_deep_research/security/egress/README.md)
+
### 🔒 Privacy & Data
Local Deep Research contains **no telemetry, no analytics, and no tracking**. We do not collect, transmit, or store any data about you or your usage. No analytics SDKs, no phone-home calls, no crash reporting, no external scripts. Usage metrics stay in your local encrypted database.
@@ -181,7 +208,7 @@ Since we don't collect any usage data, we rely on you to tell us what works, wha
## 📊 Benchmarks
-Headline results from the [community benchmarks](https://huggingface.co/datasets/local-deep-research/ldr-benchmarks) using the `langgraph-agent` strategy with Serper search, fully local via Ollama:
+Headline results from the [community benchmarks](https://huggingface.co/datasets/local-deep-research/ldr-benchmarks) using the `langgraph-agent` strategy with Serper (cloud) search and the models running locally in Ollama:
| Model | SimpleQA | xbench-DeepSearch |
|---|---|---|
@@ -419,7 +446,7 @@ search(query="agentic research frameworks", engine="github")
- **LM Studio** — connect to its OpenAI-compatible server (default `http://localhost:1234/v1`)
- **llama.cpp** — connect to `llama-server`'s OpenAI-compatible endpoint (default `http://localhost:8080/v1`); start with `llama-server -m <model.gguf>`
- Common models: Llama, Mistral, Gemma, DeepSeek, Qwen
-- LLM processing stays local (search queries still go to web). No API costs.
+- LLM processing runs on your own hardware when the model itself runs locally (search queries still go to the web). A local endpoint that relays to a hosted model, such as an Ollama cloud model or a local LiteLLM proxy, is not detected as remote. No API costs for locally-run models.
> 💡 **Which local model should I pick?** See the [community benchmarks](#-benchmarks) — community-submitted accuracy numbers across local and cloud models, so you can compare before downloading.
diff --git a/SECURITY.md b/SECURITY.md
index d655f50723..23fe32cec4 100644
--- a/SECURITY.md
+++ b/SECURITY.md
@@ -243,14 +243,14 @@ Operators needing a hard boundary **must** layer OS-level controls: network name
| NAT64 wrap of cloud metadata | `_classify_host` consults `is_nat64_wrapped_metadata_ip` before `is_private_ip`, so `64:ff9b::169.254.169.254` classifies as public (not as the link-local it superficially appears to be). |
| DNS race / process-global socket timeout | DNS resolution runs inside a single-shot `ThreadPoolExecutor` with `Future.result(timeout=2.0)` — no `socket.setdefaulttimeout()` mutation of process-global state. The worker is abandoned via `shutdown(wait=False)` so a hung lookup can't block past the timeout. |
| Cloud-metadata fetch under any scope | `evaluate_url()` rejects cloud-metadata IPs (`169.254.169.254`, ECS, IPv4-mapped forms) regardless of scope. They classify as link-local, so STRICT/PRIVATE_ONLY would otherwise *allow* them — notably via the audit-hook net which calls `evaluate_url` on raw `socket.connect` targets (bypassing the SSRF validator the fetch PEPs run first). |
-| Private collection data → cloud model | Each collection carries a public/private flag (default **private**). A private collection is excluded under PUBLIC_ONLY / Adaptive-public scope and forces local LLM/embeddings inference under PRIVATE_ONLY / Adaptive-private. The **Adaptive** scope (default) derives the effective scope from the primary engine, so a private-collection primary keeps the whole run local automatically. |
+| Private collection data → cloud model | Each collection carries a public/private flag (default **private**). A private collection is excluded under PUBLIC_ONLY (including Adaptive with a public-engine primary; a public, locally stored collection as primary resolves Adaptive to the internal BOTH scope, where private collections stay eligible) and forces local LLM/embeddings inference under PRIVATE_ONLY / Adaptive-private. The **Adaptive** scope (default) derives the effective scope from the primary engine, so a private-collection primary resolves the run to PRIVATE_ONLY and forces local inference automatically (best effort: locality is judged by endpoint address, see the caveat below). |
#### Caveats
- **DNS rebinding TOCTOU**: `_classify_host` resolves the hostname once at evaluation time; the actual HTTP request resolves again at connect time. Unlike the `safe_requests` fetch path — which pins its validated address via `security.dns_pinning` (for both `http` and `https`, re-pinning at every redirect hop) so the connection cannot be re-steered — this classification path resolves DNS independently (its own `getaddrinfo`, on a policy worker thread that carries no pin), so it is not covered by that pin and the resolve-vs-connect window remains. Accepted residual; egress restriction at the firewall is the operator-side mitigation.
- **Settings tampering**: `unprotected` is unavailable unless the operator explicitly sets `LDR_POLICY_ALLOW_UNPROTECTED_EGRESS=true`. When enabled, an adversary with write access to a user's per-user settings DB can flip `policy.egress_scope` to that escape hatch and disable normal egress enforcement (the retired `both` value no longer does this — it is coerced to the protective `adaptive` scope). Migration `0027` likewise rewrites legacy stored and queued `unprotected` selections to `adaptive` on upgrade, so turning the gate on later doesn't silently reactivate choices made before the capability boundary existed; while it stays off, new `unprotected` writes are rejected and any residual or tampered queued value is coerced to `adaptive` at dispatch with a `policy_audit` warning. Per-user SQLCipher databases mean one user can't trivially tamper with another's policy, but an attacker who can read/write a user's DB can change anything about that user's runtime. Policy-key changes emit `policy_audit=True` log lines so admins can audit changes after the fact.
- **Audit log routing**: `policy_audit=True` log lines are filtered from the WebSocket sink (`frontend_progress_sink`), so they never reach a CORS-permissive browser observer. They are written to the loguru file/console sinks and persisted to the encrypted research-log DB if a research is active.
-- **LLM/embeddings endpoint locality is best-effort**: the "stays local" guarantee is *strong* for named cloud providers (OpenAI, Anthropic, Google, OpenRouter, etc.) and localhost-default providers (Ollama/LM Studio/llama.cpp) — those are classified by name and reliably blocked/allowed. It is *weaker* for configurable-URL providers (`openai_endpoint`): the endpoint is classified by resolving its host, so an OpenAI-compatible endpoint pointed at a private-looking IP (split-horizon DNS, a tunnel, a proxy) is **trusted as local**. A user who wants to process private-collection data with a cloud LLM is expected to mark the collection **public** (the explicit opt-in); the policy prevents *accidental/silent* egress, not a determined user who deliberately points "local" inference at a cloud endpoint. This is consistent with the guardrail-not-boundary model above.
+- **LLM/embeddings endpoint locality is best-effort**: named cloud providers (OpenAI, Anthropic, Google, OpenRouter, etc.) are normally refused by name, and localhost-default providers (Ollama/LM Studio/llama.cpp) are allowed by name when no URL override is set — locality is judged by provider name and endpoint address, not by where the model actually runs, so a local endpoint that relays to a hosted model (an Ollama cloud model, a local LiteLLM or other OpenAI-compatible proxy) is **not** detected. For configurable-URL providers (`openai_endpoint`, or any provider with a URL override) the endpoint is classified by resolving its host, so an OpenAI-compatible endpoint pointed at a private-looking IP (split-horizon DNS, a tunnel, a proxy) is **trusted as local**. A user who wants to process private-collection data with a cloud LLM is expected to mark the collection **public** (the explicit opt-in); the policy prevents *accidental/silent* egress, not a determined user who deliberately points "local" inference at a cloud endpoint. This is consistent with the guardrail-not-boundary model above.
#### Configuration
@@ -258,7 +258,7 @@ See `docs/CONFIGURATION.md` for the user-facing keys
(`policy.egress_scope` — default **`adaptive`**, which follows your primary
engine; `llm.require_local_endpoint`; `embeddings.require_local`;
`llm.allowed_local_hostnames`), the per-collection public/private flag, the
-per-research overrides, and the audit-log behaviour.
+research-form controls, and the audit-log behaviour.
## Supported Versions
diff --git a/docs/architecture.md b/docs/architecture.md
index 982ae5c3dc..67d81d1053 100644
--- a/docs/architecture.md
+++ b/docs/architecture.md
@@ -143,7 +143,7 @@ flowchart LR
```mermaid
flowchart TB
- subgraph FULL_LOCAL["🏠 Fully Local (Maximum Privacy)"]
+ subgraph FULL_LOCAL["🏠 Self-Hosted (Maximum Privacy)"]
direction LR
L_LDR[LDR] <--> L_OLLAMA[Ollama]
L_LDR <--> L_SEARX[SearXNG]
diff --git a/docs/egress-modes.md b/docs/egress-modes.md
index ec9ed31c08..6941f4e251 100644
--- a/docs/egress-modes.md
+++ b/docs/egress-modes.md
@@ -1,8 +1,9 @@
# Egress modes — what each one does
> ⚠️ **Experimental.** The egress boundary is new and ships as
-> defense-in-depth, not an absolute guarantee. It blocks the known data-egress
-> paths under the scope you pick, but this is an early version — don't rely on
+> defense-in-depth, not an absolute guarantee. It aims to block known data-egress
+> paths under the scope you pick (best effort, with known gaps listed under
+> Strict below), but this is an early version — don't rely on
> it as your *only* protection for highly sensitive data yet. See the threat
> model and limitations linked just below.
@@ -26,9 +27,9 @@ search engine, so most people never need to think about it.
|---|---|---|---|
| **Adaptive** *(default)* | follows your primary engine | forced local **only** when the run is private | "just do the sensible thing" |
| **Unprotected** | any engine (no restriction) | any provider (cloud allowed) | escape hatch — **not recommended**; disables egress protection (hard SSRF / cloud-metadata blocking still applies) |
-| **Public only** | public web/academic engines only | your configured providers | public research; your local collections aren't touched |
-| **Private only** | local engines only (collections, local SearXNG/Ollama) | **forced local** — cloud blocked | sensitive work that must stay on the machine |
-| **Strict** | **only** your one primary engine | your configured providers | a single, exact source with zero expansion |
+| **Public only** | public web/academic engines (plus collections you marked public and document stores whose URL is not classified as private) | your configured providers (a document-store primary with a cloud model is normally refused at start, see Strict below) | public research; your private collections aren't touched |
+| **Private only** | local engines only (collections, your library, local document stores such as Paperless or Elasticsearch) | **forced local** — cloud blocked | sensitive work; best-effort private-only (see below) |
+| **Strict** | **only** your one primary engine | your configured providers, but cloud models usually do not work (see below) | a single, exact source with zero expansion |
---
@@ -39,16 +40,25 @@ mode for each run:
- Primary is a **public** engine (e.g. SearXNG pointed at a public instance,
arXiv, PubMed) → behaves like **Public only**.
-- Primary is a **private** source (a local collection, your library) →
+- Primary is a **private** source (a private collection, your library) →
behaves like **Private only** (and therefore forces local LLM + embeddings).
+- Primary is a collection you **marked public** (stored locally), or a primary
+ that cannot be classified → resolves to an internal,
+ more permissive scope that allows any classified engine, so private
+ collections can also be queried in that run and inference is not forced
+ local. Do not combine a public collection as primary with private
+ collections you want kept away from a cloud model or from public search
+ queries.
Why it's the default: you choose a search engine anyway, and the privacy
posture "just matches" it. If you make a **private collection** your primary,
-the whole run automatically stays local — nothing leaves the box.
+the run behaves like **Private only** (best effort, see the caveats there).
> **Note:** to use a cloud LLM on a private collection, mark the collection
-> **public** (see below) or add the provider to *trusted inference providers*;
-> to drop all restrictions for one run, use **Unprotected**. Adaptive
+> **public** (see below), or use **Unprotected** if the operator has enabled
+> it. Adding the provider to *trusted inference providers* is not expected to
+> help here: a private primary normally resolves the run to **Private only**,
+> which normally refuses cloud providers regardless of that list. Adaptive
> deliberately narrows to match the primary.
## <a id="unprotected"></a>🔓 Unprotected
@@ -57,9 +67,10 @@ the whole run automatically stays local — nothing leaves the box.
for the run: any engine, URL, and LLM/embeddings provider is permitted. The
hard SSRF and cloud-metadata blocks still apply. A loud, non-dismissible banner
shows while it is active. Prefer marking a collection **public**, or adding a
-**trusted destination** (`policy.trusted_inference_providers` /
-`policy.trusted_search_engines`) for the specific case, over disabling
-protection wholesale.
+**trusted inference provider** (`policy.trusted_inference_providers`, which
+relaxes only the run-start check described under Strict) for the specific case,
+over disabling protection wholesale. `policy.trusted_search_engines` currently
+changes no decision, because that check only looks at the primary engine.
> Legacy `unprotected` selections (saved settings and already-queued
> research snapshots) are migrated to **Adaptive** by migration `0027` on
@@ -77,19 +88,38 @@ protection wholesale.
## <a id="public_only"></a>☁️ Public only
-Only **public** web/academic engines run; your **local collections are
-excluded**. URL fetches are allowed to public hosts and blocked for private
-ones. Inference is whatever you configured (cloud allowed). Use it when you
-want public research and don't want your private documents queried at all.
+Only **public** engines run: web/academic engines, plus any collection you
+marked public and any document store (Paperless, Elasticsearch) whose URL is not
+classified as private — for example one that resolves to a public host, or
+whose name does not resolve when the run starts. Your **private collections and
+library, and document stores classified as private, are excluded**. If a
+document store that counts as public is your primary, other public engines can
+be queried in the same run, and the agent may build those queries from its
+documents. URL fetches are normally allowed to public hosts and blocked for
+private ones; the operator opt-in `LDR_SEARCH_ALLOW_PRIVATE_RESULT_FETCH`
+described under Strict below is an exception. Inference is whatever you
+configured (cloud allowed), but the run-start check described under Strict
+below normally refuses a run whose primary is a document store when the model
+is a cloud provider. Use it when you want public research and don't
+want your private documents queried at all.
## <a id="private_only"></a>🔒 Private only
-The privacy mode. **Only local engines** run (collections, library, a local
-SearXNG/Ollama). Crucially, it **forces local LLM and embeddings** — cloud
-providers (OpenAI, Anthropic, Google, OpenRouter, …) are blocked, so your
-query and your retrieved documents never reach a cloud model. Public URL
-fetches are blocked, and a process-wide socket guard blocks stray outbound
-connections. **Nothing leaves the machine.**
+The privacy mode. **Only local engines** run (collections, your library,
+local document stores such as Paperless or Elasticsearch).
+Crucially, it **forces local LLM and embeddings** — cloud providers (OpenAI,
+Anthropic, Google, OpenRouter, …) are normally refused, so LDR's own LLM and
+embedding calls normally go only to endpoints it classifies as local.
+Locality is judged by provider and endpoint address, not by where the model
+runs: a local endpoint that relays to a hosted model (an Ollama cloud model,
+or a local LiteLLM or other OpenAI-compatible proxy in front of a hosted API)
+can pass the check, and your query and retrieved documents then reach that
+hosted model. Public URL fetches are normally refused, and a best-effort
+socket guard on the research run normally refuses connections to public
+addresses (some of its gaps are listed under Strict below). This is a
+best-effort guard rail, not an air gap; operators who need a hard boundary
+should use OS- or network-level controls (see
+[SECURITY.md](../SECURITY.md#egress-policy-module)).
> If you have no local LLM configured, a Private-only run will refuse rather
> than silently fall back to the cloud — that's intentional (fail-closed).
@@ -97,10 +127,56 @@ connections. **Nothing leaves the machine.**
## <a id="strict"></a>🎯 Strict
The tightest mode: **only your single primary engine** runs — no expansion to
-any other engine at all. At the URL
-layer it behaves like Private-only (private hosts allowed, public blocked), but
-it does **not** force local inference — set the *Require local* toggles if you
-also want local LLM/embeddings.
+any other engine at all.
+
+Result and document fetches under Strict normally reach neither public nor
+private hosts. Private hosts are normally refused because LDR's fetch-time
+SSRF checks relax private addresses only under Private only — except when the
+operator has set `LDR_SEARCH_ALLOW_PRIVATE_RESULT_FETCH` for an approved
+public engine such as a self-hosted SearXNG: that engine's result fetches,
+including redirects from its result URLs, can then reach private hosts under
+any scope that lets the engine run, Strict included, whether or not it is the
+primary (link-local and cloud-metadata addresses stay blocked). Public hosts
+are normally stopped by the egress policy check or, on fetch paths without
+one, by the socket guard described below (best effort).
+
+Strict does **not** turn on the *Require local* toggles. A run-start check
+normally refuses a run that pairs a private primary source (a private
+collection, your library, or a local document store such as Paperless) with a
+cloud LLM or, for a collection or the library, a cloud provider in the
+*global* local-search embeddings setting. It does not look at the embedder a
+collection was actually indexed with. Listing a provider under *trusted
+inference providers* relaxes only that run-start check; the socket guard
+below normally still refuses connections to a public address, so a trusted
+cloud provider will usually still fail under Strict. This check (under every mode except Unprotected) runs only
+where research goes through the web app's research pipeline: the start
+request from the research form and the background research worker. Entry
+points that call the research functions directly skip it — among others the
+REST API's `/api/v1/quick_summary`, `/generate_report` and
+`/analyze_documents`, benchmark runs, the MCP server, the in-process Python
+functions such as `quick_summary` and `generate_report`, and scheduled
+subscription runs. Set the *Require local*
+toggles if you want local LLM and embeddings for every Strict run.
+
+Like Private-only, Strict arms a best-effort socket guard on the research run
+that normally refuses connections to public addresses, so a public primary
+engine, public result fetches and cloud LLM or embedding calls usually fail
+under Strict — pair it with a local engine and local models. An **Adaptive**
+run that resolves to Private-only arms the same guard.
+
+The guard is a backstop, not a guarantee. Gaps include, among others:
+
+- traffic sent through a forward proxy (`HTTP_PROXY`/`HTTPS_PROXY`) on a
+ private address: the guard sees only the proxy's address;
+- a relay on a private address that forwards to the internet, such as a
+ self-hosted SearXNG primary engine (the default Docker Compose setup) or a
+ local proxy in front of a hosted model;
+- connections reused from a shared keep-alive pool that another thread
+ opened (some LLM clients share cached HTTP clients process-wide, and reusing
+ a pooled connection opens no new socket for the guard to see);
+- the headless Chromium used for JavaScript rendering
+ (`web.enable_javascript_rendering`), which runs as a separate process;
+- worker threads that do not carry the run's egress context.
---
@@ -108,16 +184,21 @@ also want local LLM/embeddings.
Each RAG collection has a **public/private** flag (default **private**):
-- A **private** collection is excluded under *Public only* / *Adaptive-public*,
- and when used it forces local inference — its chunks never reach a cloud
- model.
+- A **private** collection is excluded under *Public only* and when *Adaptive*
+ resolves to Public only (a public-engine primary; see the Adaptive section for
+ a public-collection primary),
+ and when it makes a run private (*Private only*, or an *Adaptive* run that
+ resolves to Private only) it forces local inference, with the same
+ best-effort limits described under *Private only* above. For *Strict*, see
+ *Strict* above. Under *Unprotected* these restrictions are normally lifted.
- Mark a collection **public** (the *Public collection* checkbox when creating
it) only if its contents are non-sensitive and you're happy to process them
with cloud inference / use them under public scope.
## The two local-inference toggles
-Independent of the scope, you can force local inference any time:
+Independent of the scope, you can force local inference (except under
+*Unprotected*, which normally lifts these toggles):
- **Require local LLM endpoint** — refuse cloud LLM providers / non-local URLs.
- **Require local embeddings** — refuse cloud embedders, and refuse a
@@ -148,13 +229,12 @@ even under a public scope; restore its trusted metadata or select another model.
---
-## Per-research overrides
+## Research-form controls
The three primary controls — **Egress Scope**, **Require local LLM endpoint**,
-and **Require local embeddings** — also appear on the research-form page as
-per-run dropdown / checkbox overrides. Values set there apply **only to that
-research run** and do **not** persist to the settings database, so you can do a
-one-off private run without changing your defaults.
+and **Require local embeddings** — also appear on the research-form page in the
+*Privacy & Egress* panel. Changing one there also saves it to your settings, so
+it stays in effect for later runs until you change it back.
Under `Private only` or `Public only` Egress Scopes, the **Search Engine** dropdown
is scope-aware: engines that would be refused at submit time under the active scope are rendered disabled
diff --git a/docs/faq.md b/docs/faq.md
index 36d901eaf3..f068f508ee 100644
--- a/docs/faq.md
+++ b/docs/faq.md
@@ -19,14 +19,14 @@
### What is Local Deep Research (LDR)?
-LDR is an open-source AI research assistant that performs systematic research by breaking down complex questions, searching multiple sources in parallel, and creating comprehensive reports with proper citations. It can run entirely locally for complete privacy.
+LDR is an open-source AI research assistant that performs systematic research by breaking down complex questions, searching multiple sources in parallel, and creating comprehensive reports with proper citations. With local models and local document sources it can keep research on your own hardware (see [Egress modes](egress-modes.md) for how locality is judged and its limits).
### How is LDR different from ChatGPT or other AI assistants?
LDR focuses specifically on research with real-time information retrieval. Key differences:
- Provides citations and sources for claims
- Searches multiple databases including academic papers
-- Can run completely offline with local models
+- Can run without internet access on local documents with local models (web search needs internet)
- Open source and customizable
- Searches your own documents
diff --git a/docs/features.md b/docs/features.md
index 193227ad70..950b793313 100644
--- a/docs/features.md
+++ b/docs/features.md
@@ -137,7 +137,7 @@ See [Architecture Overview](architecture/OVERVIEW.md) for details.
- Custom GGUF models
**Features:**
-- Complete privacy
+- Inference on your own hardware (when the model itself runs locally, not an Ollama cloud model)
- No API costs
- Model hot-swapping
- GPU acceleration support
diff --git a/docs/mcp-server.md b/docs/mcp-server.md
index 2d9b6dbbaf..c75c203c03 100644
--- a/docs/mcp-server.md
+++ b/docs/mcp-server.md
@@ -133,7 +133,7 @@ The MCP server uses the same settings system as the main LDR application. There
}
```
-**Ollama (fully local, no API key needed):**
+**Ollama (local models, no API key needed):**
```json
{
diff --git a/src/local_deep_research/security/egress/README.md b/src/local_deep_research/security/egress/README.md
index 1c9f2c3d1c..abd0dd5f7d 100644
--- a/src/local_deep_research/security/egress/README.md
+++ b/src/local_deep_research/security/egress/README.md
@@ -5,8 +5,8 @@ may go** — which search engines run, which LLM/embeddings endpoints are
reached, and which URLs may be fetched.
> ⚠️ **Experimental (first release).** Surfaced in the UI as
-> *Egress Scope (Experimental)*. It blocks the known egress paths under the
-> selected scope and has been through two adversarial review rounds, but it is
+> *Egress Scope (Experimental)*. It aims to block known egress paths under the
+> selected scope (best effort; see the known gaps in `docs/egress-modes.md`) and has been through two adversarial review rounds, but it is
> early — treat it as defense-in-depth, not an absolute guarantee, and don't
> make it the sole protection for highly sensitive data.
@@ -27,10 +27,10 @@ engines/destinations are permitted.
| Scope | Meaning |
|---|---|
-| `adaptive` *(default)* | **Follow the primary engine.** A private primary → behaves PRIVATE_ONLY; a public primary → PUBLIC_ONLY; an unclassifiable primary → BOTH. Resolved to a concrete scope at run start. Classification uses the engine's **static class flags** (e.g. SearXNG is always public because it queries the internet), not the network location of its server — with one asymmetric **fail-up** exception: a local-nature engine (Elasticsearch, Paperless) whose configured URL resolves to a *public* host is reclassified public, because querying it sends data off the box. The override only ever tightens. |
+| `adaptive` *(default)* | **Follow the primary engine.** A private primary → behaves PRIVATE_ONLY; a public primary → PUBLIC_ONLY; an unclassifiable primary → BOTH. Resolved to a concrete scope at run start. Classification uses the engine's **static class flags** (e.g. SearXNG is always public because it queries the internet), not the network location of its server — with one asymmetric **fail-up** exception: a local-nature engine (Elasticsearch, Paperless) whose configured URL is not classified private (a public or unresolvable host) is reclassified public, because querying it sends data off the box. For such an engine as primary this resolves Adaptive to PUBLIC_ONLY rather than PRIVATE_ONLY. A public-marked collection primary (`is_public` and `is_local` both true) matches neither branch and resolves to BOTH, under which private collections remain eligible and inference is not forced local. |
| `both` | **Retired as a user scope** (ADR-0007). Kept only as the internal ADAPTIVE resolution target for an unclassifiable primary (allow any classified engine). A saved/queued/env `both` value is **coerced to `adaptive`** by `context_from_snapshot`, and migration 0019 rewrites stored rows — it never re-enables the old blanket-permit behaviour on its own. |
-| `public_only` | Only public web/academic engines. Local collections excluded. |
-| `private_only` | Only local engines (library, collections, Ollama). **Forces local LLM + embeddings inference** so nothing leaves the box. Note: a locally-hosted SearXNG is still treated as *public* because it proxies to internet search engines — only its *connection target* is local, not its *data source*. |
+| `public_only` | Only public engines: web/academic engines, collections marked public, and local-nature engines whose URL fails up to public (a public or unresolvable host). Private collections, the library and document stores classified as private are excluded. Where it runs (the `/api/start_research` precheck and the research worker), the run-start two-axis check normally still refuses a sensitive primary (including a failed-up document store) with exposing inference; entry points that call the research functions directly (`/api/v1/quick_summary`, `/generate_report` and `/analyze_documents`, benchmarks, MCP, the in-process `quick_summary`/`generate_report` functions, scheduled subscriptions, among others) do not run it. |
+| `private_only` | Only local engines (collections, your library, local document stores such as Paperless or Elasticsearch). **Forces local LLM + embeddings inference**, so LDR's inference calls normally go only to endpoints classified as local (best effort: locality is judged by provider and endpoint address, not by where the model runs, so a local endpoint that relays to a hosted model — an Ollama cloud model, a local LiteLLM/OpenAI-compatible proxy — is not detected). Note: a locally-hosted SearXNG is still treated as *public* because it proxies to internet search engines — only its *connection target* is local, not its *data source*. |
| `strict` | Only the user's *primary* engine; no expansion at all. |
| `unprotected` | **Operator-enabled escape hatch (not recommended).** Set `LDR_POLICY_ALLOW_UNPROTECTED_EGRESS=true` to make this mode available; it is disabled by default. When enabled, Egress-scope restrictions are disabled — any engine / URL / provider is permitted; the hard SSRF + cloud-metadata blocks in `evaluate_url` still apply, and the forced-local inference requirements are lifted. A non-dismissible banner shows while active. Migration `0027` rewrites legacy stored and queued `unprotected` selections to `adaptive` so a later opt-in can't silently reactivate them; see the Settings-tampering caveat below for what happens to residual values while the gate is off. |
@@ -43,7 +43,8 @@ PRIVATE_ONLY / Adaptive-private):
**Per-collection classification.** Each RAG collection carries an `is_public`
flag (default **private**). A private collection is excluded under
-PUBLIC_ONLY / Adaptive-public and, when it is the primary under Adaptive,
+PUBLIC_ONLY (including Adaptive with a public-engine primary; not under the
+BOTH resolution of a public-collection primary) and, when it is the primary under Adaptive,
pulls the whole run to PRIVATE_ONLY (→ local inference). To process a
collection with a cloud model, mark it **public** — the explicit opt-in.
@@ -72,11 +73,20 @@ other than `unprotected`. A non-local-file store whose endpoint cannot be
resolved is treated as remote (not contained).
**Two-axis enforcement (ADR-0007).** On top of the scope check, the run-start
-precheck enforces a *two-axis* rule: every source/sink is labelled
-**Sensitivity × Exposure** and a *sensitive* source may not reach an *exposing*
-sink (a public engine or a cloud LLM/embeddings provider). Per-destination trust
-(`policy.trusted_inference_providers` / `policy.trusted_search_engines`) relaxes
-a vouched-for off-machine sink to *contained*; `unprotected` suspends the rule.
+precheck applies a *two-axis* rule. Only the **primary engine** and the
+inference sinks are labelled **Sensitivity × Exposure**, and in practice the
+rule refuses a *sensitive* primary paired with an *exposing* inference sink (a
+cloud LLM/embeddings provider). It does not check search sinks: other engines
+the scope admits alongside a sensitive primary — for example public engines
+offered to the agent next to a document store that failed up to public under
+Public only — are not refused by it, and neither are private collections that a
+permissive scope (such as the BOTH resolution) admits next to the primary. It also runs only at the `/api/start_research` precheck and in
+the research worker, not on direct entry points (see
+`docs/egress-modes.md#strict`). Per-destination trust
+via `policy.trusted_inference_providers` relaxes a vouched-for off-machine
+inference sink to *contained*; `policy.trusted_search_engines` only relabels the
+primary's own exposure, which changes no decision while only the primary is
+checked; `unprotected` suspends the rule.
The pure decision core is `classification.py`; the live resolver + audit/enforce
wiring is `run_classification.py`. See
[`docs/decisions/0007-egress-two-axis-data-classification.md`](../../../../docs/decisions/0007-egress-two-axis-data-classification.md).
@@ -157,7 +167,7 @@ actually enforces the policy":
| Model discovery | `web/routers/settings.py` (`_resolve_model_discovery_policy`, `_model_discovery_provider_allowed`) | resolves scope **before** the model cache is read or any provider is contacted; fails closed |
| Journal-data download | `web/routers/metrics.py` | scope check (refuses when scope is unresolved) |
| RAG embeddings | `web/routers/rag.py` | `evaluate_embeddings` |
-| Secondary net (all sockets) | `audit_hook.py` (installed at `security/__init__`) | `evaluate_url` on every `socket.connect` |
+| Secondary net (IPv4/IPv6 sockets) | `audit_hook.py` (installed at `security/__init__`) | `evaluate_url` on each `socket.connect` from a thread carrying a PRIVATE_ONLY/STRICT run context (best effort; gaps in `docs/egress-modes.md#strict`) |
**Keep this table accurate — it is load-bearing, not documentation.** Two rows
above pointed at `web/routes/*.py` long after the FastAPI migration deleted
@@ -277,13 +287,13 @@ flowchart TD
Scope -->|both| BOTH[BOTH]
Scope -->|strict| STRICT["STRICT\n(primary engine only)"]
- %% PRIVATE_ONLY: nothing leaves the box
+ %% PRIVATE_ONLY: public-address egress refused (best effort; local relays to hosted models are not detected)
PRIV --> P_eng["evaluate_engine:\nlocal engines only\n(public BLOCKED)"]
PRIV --> P_llm["evaluate_llm_endpoint:\ncloud providers BLOCKED\nlocal forced"]
PRIV --> P_emb["evaluate_embeddings:\ncloud BLOCKED\nlocal forced"]
PRIV --> P_url["evaluate_url:\nprivate host ALLOWED\npublic host BLOCKED"]
- PRIV --> P_hook["audit hook ARMED:\nany public socket BLOCKED"]
- P_eng --> NoEgress([No external data egress])
+ PRIV --> P_hook["audit hook ARMED:\npublic sockets BLOCKED\n(best effort)"]
+ P_eng --> NoEgress(["No egress to public addresses\n(best effort, see caveats)"])
P_llm --> NoEgress
P_emb --> NoEgress
P_url --> NoEgress
@@ -305,7 +315,7 @@ flowchart TD
%% STRICT: primary engine only
STRICT --> S_eng["evaluate_engine:\nONLY primary engine\nno expansion"]
STRICT --> S_url["evaluate_url:\nprivate host ALLOWED\npublic host BLOCKED"]
- STRICT --> S_hook["audit hook ARMED:\nany public socket BLOCKED"]
+ STRICT --> S_hook["audit hook ARMED:\npublic sockets BLOCKED\n(best effort)"]
%% Metadata always blocked everywhere
Meta["Cloud-metadata IPs\n(169.254.169.254, NAT64 wraps)"] -.->|BLOCKED under ALL scopes| Scope
@@ -318,23 +328,25 @@ Each cell is the decision produced by the real `evaluate_*` logic / PEP for that
| Egress vector | adaptive (resolves to →) | both | public_only | private_only | strict |
|---|---|---|---|---|---|
| **Search engine selection** (`evaluate_engine`) | PRIVATE_ONLY \| PUBLIC_ONLY \| BOTH | any classified engine ALLOWED; unclassified BLOCKED | public engines ALLOWED; private collections BLOCKED | local engines ALLOWED; public BLOCKED | only PRIMARY engine ALLOWED; all others BLOCKED |
-| **LLM inference** (`evaluate_llm_endpoint` + `get_llm`) | private→forced-local; public→cloud ALLOWED (unless toggle) | ALLOWED unless `llm.require_local_endpoint` set | ALLOWED unless toggle set (not scope-forced) | **forced-local** — cloud providers BLOCKED (`require_local_llm` implied) | ALLOWED unless toggle set (STRICT is orthogonal to inference) |
+| **LLM inference** (`evaluate_llm_endpoint` + `get_llm`) | private→forced-local; public→cloud ALLOWED (unless toggle) | ALLOWED unless `llm.require_local_endpoint` set | ALLOWED unless toggle set (not scope-forced) | **forced-local** — cloud providers BLOCKED (`require_local_llm` implied) | ALLOWED unless toggle set (not scope-forced); the armed audit hook normally refuses cloud inference in practice, and, where it runs, the run-start two-axis check also refuses it when the primary source is sensitive (a private collection, the library or a local document store) — see `docs/egress-modes.md#strict` |
| **Embeddings / index** (`evaluate_embeddings`) | private→forced-local; public→cloud ALLOWED (unless toggle) | ALLOWED unless `embeddings.require_local` set | ALLOWED unless toggle set | **forced-local** — cloud embedders BLOCKED (`require_local_embeddings` implied) | ALLOWED unless toggle set |
| **Arbitrary URL fetch** (`evaluate_url`, content fetcher / full_search) | private→private-host only; public→public-host only | any classified host ALLOWED; unclassified BLOCKED | public host ALLOWED; private host BLOCKED | private host ALLOWED; **public host BLOCKED** | private host ALLOWED; public host BLOCKED |
| **Library download** (`evaluate_url`, download_service) | private→private-host only; public→public-host only | any classified host ALLOWED | public host ALLOWED; private BLOCKED | private host ALLOWED; **public BLOCKED** | private host ALLOWED; public BLOCKED |
| **Notification webhook** (`evaluate_url`, notifications/manager) | private→private-host only; public→public-host only | any classified http/https host ALLOWED | public webhook ALLOWED; private BLOCKED | private webhook ALLOWED; **public webhook BLOCKED** | private webhook ALLOWED; public BLOCKED |
-| **Raw socket** (audit hook → `evaluate_url`) | private→ARMED (public BLOCKED); public→INACTIVE | INACTIVE (passthrough) | INACTIVE (passthrough) | **ARMED** — every public socket.connect BLOCKED | ARMED — every public socket.connect BLOCKED |
+| **Raw socket** (audit hook → `evaluate_url`) | private→ARMED (public BLOCKED, best effort); public→INACTIVE | INACTIVE (passthrough) | INACTIVE (passthrough) | **ARMED** — public-address socket.connect BLOCKED on threads carrying the run's context (best effort, see below) | ARMED — public-address socket.connect BLOCKED on threads carrying the run's context (best effort, see below) |
| **Cloud-metadata IP** (169.254.169.254 / NAT64) | BLOCKED | BLOCKED | BLOCKED | BLOCKED | BLOCKED |
+The URL-fetch rows show the `evaluate_url` decision where that check runs. Under `strict`, search-result and document fetches normally reach neither public nor private hosts. Private hosts are normally refused because LDR's fetch-time SSRF checks relax private addresses only under `private_only` — except when the operator has set `LDR_SEARCH_ALLOW_PRIVATE_RESULT_FETCH` for an approved public engine such as a self-hosted SearXNG: that engine's result fetches, including redirects from its result URLs, can then reach private hosts under any scope that lets the engine run, `strict` included, whether or not it is the primary, because the full-content fetch grant does not depend on scope and the factory supplies no run context, so `evaluate_url` does not run there (see the Full-content fetch row above; link-local and cloud metadata stay blocked). Public hosts are normally stopped by the policy check or, on fetch paths without one, by the socket guard (best effort).
+
### Key invariants (the crystal-clear takeaways)
| Claim | Where it is enforced |
|---|---|
-| **private_only blocks ALL external data egress** | engine selection (`evaluate_engine` → `scope_mismatch_private_only`), URL/library/webhook fetch (`evaluate_url` PRIVATE_ONLY branch), LLM (`require_local_llm` forced in `context_from_snapshot` → `provider_cloud_only`), embeddings (`require_local_embeddings` forced → `provider_cloud`), and the raw-socket audit-hook net armed for PRIVATE_ONLY (`audit_hook.py`). No vector permits a public destination. |
+| **private_only normally refuses public destinations on the enforced vectors (best effort)** | engine selection (`evaluate_engine` → `scope_mismatch_private_only`), URL/library/webhook fetch (`evaluate_url` PRIVATE_ONLY branch), LLM (`require_local_llm` forced in `context_from_snapshot` → `provider_cloud_only`), embeddings (`require_local_embeddings` forced → `provider_cloud`), and the raw-socket audit-hook net armed for PRIVATE_ONLY (`audit_hook.py`). These checks are classification-based and best effort; known gaps (not an exhaustive list) are in `docs/egress-modes.md#strict` and SECURITY.md. |
| **public_only stays open to public sources** | public engines pass `evaluate_engine` (private collections BLOCKED via `scope_mismatch_public_only`); `evaluate_url` allows public hosts, blocks private; inference is NOT scope-forced (toggles still apply); the audit hook stays INACTIVE (only PRIVATE_ONLY/STRICT arm it) so legitimate local infra traffic — local Ollama, settings DB — is never falsely blocked. |
-| **adaptive just matches the primary engine** | `_resolve_adaptive_scope`: private primary → PRIVATE_ONLY, public primary → PUBLIC_ONLY, unknown → BOTH. A registered local retriever primary also resolves PRIVATE_ONLY. Uses the engine's **static class flags** (`is_public`/`is_local` on the Python class), not the network location of the engine's server — so a locally-hosted SearXNG (class `is_public=True`) resolves to PUBLIC_ONLY. Resolved once at run start; the stored `EgressContext` carries the concrete scope, not ADAPTIVE. |
-| **A private RAG collection as ADAPTIVE primary pulls the whole run local** | `_resolve_collection_is_public` defaults private → `classify_engine` returns local → adaptive resolves PRIVATE_ONLY → forces local LLM + embeddings. Mark the collection `is_public` to opt into cloud inference. |
-| **Cloud-metadata is never reachable, under any scope** | `evaluate_url` runs `is_ip_blocked(..., allow_private_ips=True)` before scope logic; `_classify_host` applies the same metadata block on BOTH the literal-IP and DNS-resolved paths; NAT64-wrapped metadata is reclassified PUBLIC. |
+| **adaptive just matches the primary engine** | `_resolve_adaptive_scope`: private primary → PRIVATE_ONLY, public primary → PUBLIC_ONLY, unknown → BOTH; a public, locally stored collection primary (public *and* local) also → BOTH, where private collections stay eligible. A registered local retriever primary also resolves PRIVATE_ONLY. Uses the engine's **static class flags** (`is_public`/`is_local` on the Python class), not the network location of the engine's server — so a locally-hosted SearXNG (class `is_public=True`) resolves to PUBLIC_ONLY. Resolved once at run start; the stored `EgressContext` carries the concrete scope, not ADAPTIVE. |
+| **A private RAG collection as ADAPTIVE primary forces local inference** | `_resolve_collection_is_public` defaults private → `classify_engine` returns local → adaptive resolves PRIVATE_ONLY → forces local LLM + embeddings (best effort: judged by provider and endpoint address, so a local relay to a hosted model is not detected). Mark the collection `is_public` to opt into cloud inference. |
+| **Known cloud-metadata addresses are normally refused by the policy checks under every scope** | `evaluate_url` runs `is_ip_blocked(..., allow_private_ips=True)` before scope logic; `_classify_host` applies the same metadata block on BOTH the literal-IP and DNS-resolved paths; NAT64-wrapped metadata is reclassified PUBLIC. |
| **An engine self-checks scope at run time, even off the factory path** | `BaseSearchEngine._verify_egress_scope()` runs at the top of `run()` (and inside `CollectionSearchEngine.search()` / `LibraryRAGSearchEngine.search()`, which bypass `run()`), re-evaluating `evaluate_engine` against the engine's stored snapshot and **raising `PolicyDeniedError`** on a mismatch. Memoized per snapshot identity + (scope, primary) values so the hot path pays the evaluation once. A defense-in-depth backstop behind the factory PEP for engines built by direct instantiation; it cannot deny anything the factory would have allowed. |
| **Direct MCP searches still arm the socket-level net** | `mcp/server.py::_egress_audit_net()` builds the run's `EgressContext` from the request snapshot and arms the PEP-578 audit hook around `engine.run()`, so a direct MCP search (which never goes through `AdvancedSearchSystem`) still gets the raw-socket backstop under PRIVATE_ONLY/STRICT. Fails open to a no-op when the policy is unevaluable — the factory PEP remains primary. |