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.

fix(security): strip settings_snapshot from GET /history/report/<id> (API-key exposure) (#4853)

LearningCircuit4410a3d34f9f
diff --git a/changelog.d/4853.security.md b/changelog.d/4853.security.md
new file mode 100644
index 0000000000..dda78257bf
--- /dev/null
+++ b/changelog.d/4853.security.md
@@ -0,0 +1 @@
+**`GET /history/report/<id>` no longer leaks the settings snapshot (API keys).** The report route returned the persisted `research_meta` wholesale in its response metadata, and `research_meta` includes `settings_snapshot` — which holds all application settings, including API keys, tokens, and base URLs. It now strips `settings_snapshot` via the same `strip_settings_snapshot()` helper its four sibling routes already use, while preserving every other (non-sensitive) metadata field the report view needs.
diff --git a/src/local_deep_research/web/routes/history_routes.py b/src/local_deep_research/web/routes/history_routes.py
index dacd5c325c..dd4cf5bdd2 100644
--- a/src/local_deep_research/web/routes/history_routes.py
+++ b/src/local_deep_research/web/routes/history_routes.py
@@ -21,7 +21,7 @@ from ..routes.globals import get_active_research_snapshot
from ..routes.research_routes import _research_not_found
from ..services.research_service import get_research_strategy
from ...security.rate_limiter import limiter
-from ...security import filter_research_metadata
+from ...security import filter_research_metadata, strip_settings_snapshot
from ..utils.templates import render_template_with_defaults
# Create a Blueprint for the history routes
@@ -319,7 +319,12 @@ def get_report(research_id):
research_id, message="Report content not found"
)
- stored_metadata = research.research_meta or {}
+ # Strip settings_snapshot (API keys, tokens, base URLs, paths)
+ # before returning research_meta to the client — settings_snapshot
+ # is persisted in research_meta but must never reach the API
+ # response. Matches the sibling /details and /api/research/<id>
+ # routes; all other metadata fields are preserved.
+ stored_metadata = strip_settings_snapshot(research.research_meta)
# Create an enhanced metadata dictionary with database fields
enhanced_metadata = {
diff --git a/tests/web/routes/test_report_api_contract.py b/tests/web/routes/test_report_api_contract.py
index 37743a6def..b1587246f7 100644
--- a/tests/web/routes/test_report_api_contract.py
+++ b/tests/web/routes/test_report_api_contract.py
@@ -123,6 +123,12 @@ def seeded_db(tmp_path):
research_meta={
"iterations": 2,
"generated_at": "2026-04-25T12:05:00+00:00",
+ # settings_snapshot is persisted in research_meta but must never
+ # be returned by an API response (it holds API keys / tokens) —
+ # see test_history_report_strips_settings_snapshot.
+ "settings_snapshot": {
+ "llm.openai.api_key": "sk-SECRET-LEAKED-KEY",
+ },
},
)
)
@@ -230,6 +236,20 @@ def test_history_report_includes_sources_and_metrics(
assert "src1.example" in content
+def test_history_report_strips_settings_snapshot(mock_auth_client, seeded_db):
+ """GET /history/report/<id> must NOT return settings_snapshot (API keys,
+ tokens, base URLs) in its metadata — it is stripped like the sibling
+ /details and /api/research/<id> routes (sensitive-data exposure)."""
+ resp = mock_auth_client.get(f"/history/report/{RESEARCH_ID}")
+ assert resp.status_code == 200, resp.data
+ body = resp.get_json()
+ assert "settings_snapshot" not in body["metadata"]
+ # Belt-and-suspenders: the secret value appears nowhere in the response.
+ assert "sk-SECRET-LEAKED-KEY" not in resp.get_data(as_text=True)
+ # Non-sensitive metadata fields are still preserved.
+ assert body["metadata"].get("iterations") == 2
+
+
def test_history_markdown_includes_sources_and_metrics(
mock_auth_client, seeded_db
):