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): stop returning absolute report_path from status endpoints (#6443)

LearningCircuit83eceec984cf
diff --git a/changelog.d/+status-report-path-disclosure.security.md b/changelog.d/+status-report-path-disclosure.security.md
new file mode 100644
index 0000000000..c9a7ac5e06
--- /dev/null
+++ b/changelog.d/+status-report-path-disclosure.security.md
@@ -0,0 +1,2 @@
+The research status, details, and report endpoints (`/history/status/{id}`, `/research/api/status/{id}`, `/api/research/{id}/status`, `/api/research/{id}`, and `/api/report/{id}`) no longer return `report_path`, an absolute server-side path that rows written by earlier versions can still carry. No client consumed the field, and `/library/api/check-downloads` plus the history list endpoint already withhold server paths for the same reason.
+`/history/status/{id}` also no longer returns the raw `progress_log` column, where rows written by <=v0.4.4 embed `report_path` inside the completion entry's metadata. Its parsed `log` entries are additionally scrubbed of the same key as a second guard.
diff --git a/src/local_deep_research/web/routers/api.py b/src/local_deep_research/web/routers/api.py
index 87c0f99b5e..9165f16caa 100644
--- a/src/local_deep_research/web/routers/api.py
+++ b/src/local_deep_research/web/routers/api.py
@@ -120,7 +120,10 @@ def api_research_status(
"status": research.status,
"progress": research.progress,
"completed_at": research.completed_at,
- "report_path": research.report_path,
+ # report_path deliberately omitted: absolute server-side
+ # path, which leaks directory layout — same rule as
+ # /library/api/check-downloads and the history
+ # status/detail endpoints.
"metadata": strip_settings_snapshot(research.research_meta),
}
diff --git a/src/local_deep_research/web/routers/history.py b/src/local_deep_research/web/routers/history.py
index a73120b579..8cc01b4436 100644
--- a/src/local_deep_research/web/routers/history.py
+++ b/src/local_deep_research/web/routers/history.py
@@ -166,6 +166,28 @@ def get_history(
)
+def _scrub_server_paths(value):
+ """Recursively drop server-path keys from a parsed progress-log entry.
+
+ Rows written by <=v0.4.4 persisted the completion entry with
+ ``metadata.report_path`` — the absolute server-side path of the
+ generated report — inside the ``progress_log`` column. The raw
+ column itself is never returned to the client; this scrub is
+ defence in depth for the parsed entries returned as ``log``, in
+ case a path-bearing key is ever nested back into the column.
+ ``report_path`` is the only such key any writer has ever emitted.
+ """
+ if isinstance(value, dict):
+ return {
+ k: _scrub_server_paths(v)
+ for k, v in value.items()
+ if k != "report_path"
+ }
+ if isinstance(value, list):
+ return [_scrub_server_paths(item) for item in value]
+ return value
+
+
@router.get("/status/{research_id}")
@limiter.exempt
def get_research_status(
@@ -184,6 +206,7 @@ def get_research_status(
# Extract attributes while session is active
# to avoid DetachedInstanceError after the with block exits
+ raw_progress_log = research.progress_log
result = {
"id": research.id,
"query": research.query,
@@ -191,8 +214,13 @@ def get_research_status(
"status": research.status,
"created_at": research.created_at,
"completed_at": research.completed_at,
- "progress_log": research.progress_log,
- "report_path": research.report_path,
+ # report_path deliberately omitted: it's the absolute
+ # server-side path, which leaks directory layout — same rule
+ # as /library/api/check-downloads and the history LIST
+ # endpoint. progress_log is omitted for the same reason:
+ # rows written by <=v0.4.4 embed report_path inside the
+ # completion entry's metadata, and no client reads the raw
+ # field — the sanitized parsed form is returned as "log".
}
# Add progress information from active research (atomic snapshot)
@@ -203,7 +231,7 @@ def get_research_status(
elif result.get("status") == ResearchStatus.COMPLETED:
result["progress"] = 100
try:
- result["log"] = json.loads(result.get("progress_log", "[]"))
+ result["log"] = json.loads(raw_progress_log or "[]")
except Exception:
logger.warning(
"Error parsing progress_log for research {}", research_id
@@ -212,13 +240,21 @@ def get_research_status(
else:
result["progress"] = 0
try:
- result["log"] = json.loads(result.get("progress_log", "[]"))
+ result["log"] = json.loads(raw_progress_log or "[]")
except Exception:
logger.warning(
"Error parsing progress_log for research {}", research_id
)
result["log"] = []
+ # Scrub once at egress so the invariant holds structurally for every
+ # branch above, instead of being enumerated at each assignment site.
+ # This also covers the snapshot branch's "log": its only writer
+ # (the termination handler in research.py) has never nested
+ # report_path into an entry's metadata, so scrubbing it is a no-op
+ # today — and stays defence in depth if that ever changes.
+ result["log"] = _scrub_server_paths(result["log"])
+
return result
diff --git a/src/local_deep_research/web/routers/research.py b/src/local_deep_research/web/routers/research.py
index 84b31b4be6..2ff43408f8 100644
--- a/src/local_deep_research/web/routers/research.py
+++ b/src/local_deep_research/web/routers/research.py
@@ -2056,7 +2056,6 @@ def get_research_details(
"mode": research.mode,
"created_at": research.created_at,
"completed_at": research.completed_at,
- "report_path": research.report_path,
"metadata": strip_settings_snapshot(research.research_meta),
}
except Exception:
@@ -2444,7 +2443,6 @@ def get_research_report(
"completed_at": research.completed_at
if research.completed_at
else None,
- "report_path": research.report_path,
**safe_metadata,
},
}
@@ -2596,7 +2594,6 @@ def get_research_status(
status = research.status
progress = research.progress
completed_at = research.completed_at
- report_path = research.report_path
metadata = research.research_meta or {}
# Extract and format error information for better UI display
@@ -2701,7 +2698,6 @@ def get_research_status(
"status": status,
"progress": progress,
"completed_at": completed_at,
- "report_path": report_path,
"metadata": filtered_metadata,
}
diff --git a/tests/security/test_status_payload_server_path_disclosure.py b/tests/security/test_status_payload_server_path_disclosure.py
new file mode 100644
index 0000000000..b295ef6bcc
--- /dev/null
+++ b/tests/security/test_status_payload_server_path_disclosure.py
@@ -0,0 +1,323 @@
+"""The research-status, details, and report endpoints must not disclose
+server-side file paths.
+
+Five endpoints return a research row's data to an authenticated user:
+``GET /history/status/{research_id}``,
+``GET /research/api/status/{research_id}``,
+``GET /api/research/{research_id}/status`` (the endpoint the frontend
+polls), ``GET /api/research/{research_id}`` (details), and
+``GET /api/report/{research_id}`` (report). All five used to return the
+row's ``report_path`` — the absolute server-side filesystem path of the
+generated report file — either at the top level or nested inside
+``metadata``. The codebase already treats exactly this class of
+disclosure as a bug: ``/library/api/check-downloads`` deliberately
+withholds ``document.file_path`` because it "leaks directory layout to
+any authenticated user". No client reads ``report_path`` from any of
+the five. Each test also asserts the sentinel path is absent from the
+whole response body, not only that the key is missing, and a
+router-wide AST guard below fails on any dict literal in
+``web/routers/`` that carries the key; non-literal shapes (a subscript
+assignment, ``dict(report_path=...)``) are what the body assertions
+cover.
+
+A second channel exists on ``GET /history/status/{research_id}``: the
+``progress_log`` column. Rows written by <=v0.4.4 embed the completion
+entry's ``metadata.report_path`` — the absolute server-side report
+path — inside that column, and the endpoint used to return the raw
+column verbatim as well as parsing it into ``log``. No client reads the
+raw field, so it is now omitted and the parsed entries are scrubbed.
+"""
+
+import ast
+import json
+from contextlib import contextmanager
+from pathlib import Path
+from unittest.mock import patch
+
+import pytest
+from sqlalchemy import create_engine
+from sqlalchemy.orm import sessionmaker
+from sqlalchemy.pool import StaticPool
+
+_HISTORY = "local_deep_research.web.routers.history"
+_API = "local_deep_research.web.routers.api"
+_RESEARCH = "local_deep_research.web.routers.research"
+
+_ENGINE_KW = {
+ "connect_args": {"check_same_thread": False},
+ "poolclass": StaticPool,
+}
+
+
+def db():
+ """A real in-memory database with the full schema; yields a session."""
+ from local_deep_research.database.models import Base
+
+ engine = create_engine("sqlite:///:memory:", **_ENGINE_KW)
+ Base.metadata.create_all(engine)
+ session = sessionmaker(bind=engine)()
+ try:
+ yield session
+ finally:
+ session.close()
+ engine.dispose()
+
+
+def _patch_session(module, session):
+ @contextmanager
+ def _ctx(*_args, **_kwargs):
+ yield session
+
+ return patch(f"{module}.get_user_db_session", _ctx)
+
+
+def _add_research(session, rid, report_path=None, **extra):
+ from local_deep_research.database.models import ResearchHistory
+
+ row = ResearchHistory(
+ id=rid,
+ query="q",
+ mode="quick",
+ status="completed",
+ created_at="2025-01-01T00:00:00+00:00",
+ report_path=report_path,
+ **extra,
+ )
+ session.add(row)
+ session.commit()
+ return row
+
+
+def test_history_status_omits_report_path(authenticated_client, db):
+ sentinel = "/var/lib/ldr-private/reports/abc123.md"
+ _add_research(db, "leaky-1", report_path=sentinel)
+
+ with (
+ _patch_session(_HISTORY, db),
+ patch(f"{_HISTORY}.get_active_research_snapshot", return_value=None),
+ ):
+ response = authenticated_client.get("/history/status/leaky-1")
+
+ assert response.status_code == 200, response.text[:300]
+ assert sentinel not in response.text, "server path leaked in the body"
+ data = response.get_json()
+ assert "report_path" not in data, (
+ "history status discloses the absolute server-side report_path"
+ )
+ # The useful fields stay.
+ assert data["id"] == "leaky-1"
+ assert data["status"] == "completed"
+
+
+def test_legacy_api_status_omits_report_path(authenticated_client, db):
+ sentinel = "/var/lib/ldr-private/reports/abc123.md"
+ _add_research(db, "leaky-2", report_path=sentinel)
+
+ with _patch_session(_API, db):
+ response = authenticated_client.get("/research/api/status/leaky-2")
+
+ assert response.status_code == 200, response.text[:300]
+ assert sentinel not in response.text, "server path leaked in the body"
+ data = response.get_json()
+ assert "report_path" not in data, (
+ "legacy api status discloses the absolute server-side report_path"
+ )
+ assert data["status"] == "completed"
+
+
+def test_research_status_omits_report_path(authenticated_client, db):
+ """``GET /api/research/{id}/status`` — the endpoint the frontend polls."""
+ sentinel = "/var/lib/ldr-private/reports/abc123.md"
+ _add_research(db, "leaky-3", report_path=sentinel)
+
+ with _patch_session(_RESEARCH, db):
+ response = authenticated_client.get("/api/research/leaky-3/status")
+
+ assert response.status_code == 200, response.text[:300]
+ assert sentinel not in response.text, "server path leaked in the body"
+ data = response.get_json()
+ assert "report_path" not in data, (
+ "research status discloses the absolute server-side report_path"
+ )
+ assert data["status"] == "completed"
+
+
+def test_research_details_omits_report_path(authenticated_client, db):
+ sentinel = "/var/lib/ldr-private/reports/abc123.md"
+ _add_research(db, "leaky-4", report_path=sentinel)
+
+ with _patch_session(_RESEARCH, db):
+ response = authenticated_client.get("/api/research/leaky-4")
+
+ assert response.status_code == 200, response.text[:300]
+ assert sentinel not in response.text, "server path leaked in the body"
+ data = response.get_json()
+ assert "report_path" not in data, (
+ "research details discloses the absolute server-side report_path"
+ )
+ assert data["id"] == "leaky-4"
+ assert data["status"] == "completed"
+
+
+def test_research_report_omits_report_path(authenticated_client, db):
+ sentinel = "/var/lib/ldr-private/reports/abc123.md"
+ _add_research(
+ db, "leaky-5", report_path=sentinel, report_content="The answer."
+ )
+
+ with _patch_session(_RESEARCH, db):
+ response = authenticated_client.get("/api/report/leaky-5")
+
+ assert response.status_code == 200, response.text[:300]
+ assert sentinel not in response.text, "server path leaked in the body"
+ data = response.get_json()
+ assert "report_path" not in data["metadata"], (
+ "research report discloses the absolute server-side report_path"
+ )
+ # The useful field stays.
+ assert data["content"] == "The answer."
+
+
+def test_history_status_sanitizes_legacy_text_progress_log(
+ authenticated_client, db
+):
+ """A progress_log stored as a JSON string: the shape json.loads parses.
+
+ The <=v0.4.4 writer persisted the completion entry as
+ ``{"time": ..., "message": ..., "progress": 100, "metadata":
+ {"phase": "complete", "report_path": <absolute path>}}``. This case
+ seeds ``progress_log`` as a JSON string — the one shape whose
+ ``json.loads`` in the handler succeeds, so the parsed entries reach
+ the scrub. The raw column is omitted regardless of shape; see
+ ``test_history_status_omits_production_shaped_progress_log`` below
+ for the list shape every writer actually produces (production rows,
+ and legacy rows too once read back through today's JSON-typed
+ column), where the parse raises instead and only the field removal
+ protects the row.
+ """
+ sentinel = "/var/lib/ldr-private/reports/legacy123.md"
+ _add_research(
+ db,
+ "leaky-6",
+ progress_log=json.dumps(
+ [
+ {
+ "time": "2025-01-01T00:00:01+00:00",
+ "message": "Research completed successfully",
+ "progress": 100,
+ "metadata": {
+ "phase": "complete",
+ "report_path": sentinel,
+ },
+ },
+ {
+ "time": "2025-01-01T00:00:02+00:00",
+ "message": "path at entry top level",
+ "progress": 100,
+ "report_path": sentinel,
+ },
+ ]
+ ),
+ )
+
+ with (
+ _patch_session(_HISTORY, db),
+ patch(f"{_HISTORY}.get_active_research_snapshot", return_value=None),
+ ):
+ response = authenticated_client.get("/history/status/leaky-6")
+
+ assert response.status_code == 200, response.text[:300]
+ assert sentinel not in response.text, "server path leaked in the body"
+ data = response.get_json()
+ assert "progress_log" not in data, (
+ "history status returns the raw progress_log column, which "
+ "leaks the legacy completion entry's report_path"
+ )
+ assert "report_path" not in json.dumps(data["log"]), (
+ "history status discloses report_path inside parsed log entries"
+ )
+ # The sanitized log still serves the UI.
+ assert len(data["log"]) == 2
+ assert data["log"][0]["metadata"] == {"phase": "complete"}
+ assert data["id"] == "leaky-6"
+ assert data["status"] == "completed"
+
+
+def test_history_status_omits_production_shaped_progress_log(
+ authenticated_client, db
+):
+ """The shape every writer actually produces: a list, not a string.
+
+ ``research.py``, ``chat.py`` and ``followup.py`` all persist
+ ``progress_log`` as a Python list through the ORM's JSON column, so
+ ``research.progress_log`` reads back as a list — a legacy row is no
+ different, since SQLAlchemy's JSON column deserializes whatever
+ valid JSON is stored regardless of which version wrote it.
+ ``json.loads`` in the handler raises ``TypeError`` on a list, so the
+ parsed ``log`` degrades to ``[]`` before the scrub ever runs on it.
+ The field removal, not the scrub, is what keeps this — the real,
+ shipped — shape safe.
+ """
+ sentinel = "/var/lib/ldr-private/reports/legacy789.md"
+ _add_research(
+ db,
+ "leaky-7",
+ progress_log=[
+ {
+ "time": "2025-01-01T00:00:01+00:00",
+ "message": "Research completed successfully",
+ "progress": 100,
+ "metadata": {
+ "phase": "complete",
+ "report_path": sentinel,
+ },
+ }
+ ],
+ )
+
+ with (
+ _patch_session(_HISTORY, db),
+ patch(f"{_HISTORY}.get_active_research_snapshot", return_value=None),
+ ):
+ response = authenticated_client.get("/history/status/leaky-7")
+
+ assert response.status_code == 200, response.text[:300]
+ assert sentinel not in response.text, "server path leaked in the body"
+ data = response.get_json()
+ assert "progress_log" not in data, (
+ "history status returns the raw progress_log column, which "
+ "leaks the legacy completion entry's report_path"
+ )
+ assert data["id"] == "leaky-7"
+ assert data["status"] == "completed"
+
+
+def test_no_router_response_returns_report_path():
+ """AST guard: no router response dict may carry a ``report_path`` key.
+
+ Pins the literal-key form of the invariant for every handler in
+ ``web/routers/``, not just the five exercised by name above. It
+ catches a ``"report_path": ...`` entry at any nesting depth; the
+ value assertions in the tests above cover the non-literal shapes.
+ """
+ routers_dir = (
+ Path(__file__).resolve().parents[2]
+ / "src"
+ / "local_deep_research"
+ / "web"
+ / "routers"
+ )
+ files = sorted(routers_dir.glob("*.py"))
+ assert len(files) >= 20, f"router sweep found too few files: {files}"
+ offenders = []
+ for path in files:
+ tree = ast.parse(path.read_text(encoding="utf-8"), filename=str(path))
+ for node in ast.walk(tree):
+ if isinstance(node, ast.Dict):
+ offenders.extend(
+ f"{path.name}:{k.lineno}"
+ for k in node.keys
+ if isinstance(k, ast.Constant) and k.value == "report_path"
+ )
+ assert not offenders, f"report_path key found in: {offenders}"