~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.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
fix(security): accept the unstructured HTML-output XSS with an OSV ignore, a release exception and a tripwire (#7467)
LearningCircuita6dfcaeb8aa2
diff --git a/.github/release-security-exceptions.json b/.github/release-security-exceptions.jsonindex 8a00ff91ec..7fdf259884 100644--- a/.github/release-security-exceptions.json+++ b/.github/release-security-exceptions.json@@ -1,5 +1,17 @@{"version": 1,"repository": "LearningCircuit/local-deep-research",- "exceptions": []+ "exceptions": [+ {+ "alert_number": 9736,+ "rule_id": "CVE-2026-104250",+ "tool": "Trivy",+ "category": "container-security",+ "path": "install/.venv/lib/python3.14/site-packages/unstructured-0.18.32.dist-info/METADATA",+ "severity": "medium",+ "expires_on": "2026-12-19",+ "reason": "GHSA-v5mq-3xhg-98m9 stored XSS in unstructured's HTML output (metadata.text_as_html, elements_to_html). The only fix, 0.24.1, requires Python <3.14 like every release since 0.24.0, so it cannot be locked. LDR never produces or reads that HTML: unstructured-backed loaders run in langchain's single mode (joined element text, no element metadata) and extracted text is escaped when rendered. Enforced by tests/security/test_unstructured_html_output_tripwire.py. Lock a 3.14-compatible fixed release, rescan and remove this entry.",+ "tracking_url": "https://github.com/LearningCircuit/local-deep-research/pull/7467"+ }+ ]}diff --git a/osv-scanner.toml b/osv-scanner.tomlindex d2b3b40bad..9a36cddf90 100644--- a/osv-scanner.toml+++ b/osv-scanner.toml@@ -1,7 +1,7 @@# Release-gate exceptions for vulnerability sinks the application does not# expose. OSV-Scanner reads this file beside pdm.lock. These IDs are narrow:-# aliases are covered, but other findings in either package still fail scans.-# Expiry makes the gate revisit both decisions after the v2 release window.+# aliases are covered, but other findings in these packages still fail scans.+# Expiry makes the gate revisit each decision after the v2 release window.[[IgnoredVulns]]id = "GHSA-8mgp-746c-j5xp"@@ -12,3 +12,8 @@ reason = "NLTK is transitive; LDR does not enable pathsec or expose model-artifaid = "GHSA-4mvj-m6j5-pmf7"ignoreUntil = 2026-10-31reason = "LDR partitions validated local filenames, not URLs; tests/security/test_unstructured_url_partition_tripwire.py guards URL-taking sinks. Fixed unstructured >=0.24 requires Python <3.14, while LDR supports 3.14. Recheck when a compatible fix is available."++[[IgnoredVulns]]+id = "GHSA-v5mq-3xhg-98m9"+ignoreUntil = 2026-10-31+reason = "Stored XSS in unstructured's HTML output (ontology to_html / metadata.text_as_html / elements_to_html). LDR's unstructured-backed loaders use langchain's single mode (joined element text, no element metadata) and extracted text is escaped when rendered; tests/security/test_unstructured_html_output_tripwire.py guards the HTML-output sinks. Fixed unstructured >=0.24.1 requires Python <3.14, while LDR supports 3.14. Recheck when a compatible fix is available."diff --git a/tests/security/test_osv_reachability_exceptions.py b/tests/security/test_osv_reachability_exceptions.pyindex ef3adbc3f7..2cf64955fc 100644--- a/tests/security/test_osv_reachability_exceptions.py+++ b/tests/security/test_osv_reachability_exceptions.py@@ -27,8 +27,9 @@ def test_osv_exceptions_are_exact_and_expiring() -> None:assert {entry["id"] for entry in exceptions} == {"GHSA-8mgp-746c-j5xp","GHSA-4mvj-m6j5-pmf7",+ "GHSA-v5mq-3xhg-98m9",}- assert len(exceptions) == 2+ assert len(exceptions) == 3for entry in exceptions:assert set(entry) == {"id", "ignoreUntil", "reason"}assert isinstance(entry["ignoreUntil"], dt.date)diff --git a/tests/security/test_unstructured_html_output_tripwire.py b/tests/security/test_unstructured_html_output_tripwire.pynew file mode 100644index 0000000000..488a305c31--- /dev/null+++ b/tests/security/test_unstructured_html_output_tripwire.py@@ -0,0 +1,179 @@+"""Tripwire for the unstructured HTML-output stored XSS (GHSA-v5mq-3xhg-98m9).++unstructured 0.18.32 — the newest release that installs on Python 3.14 — is+affected by GHSA-v5mq-3xhg-98m9 / CVE-2026-104250 (Medium): the v2 ontology+HTML emitter copies document markup into ``metadata.text_as_html`` and the+output of ``elements_to_html()`` without escaping, so a crafted document's+``<img onerror=...>`` runs wherever that HTML is shown. The fix (0.24.1)+declares ``Requires-Python: <3.14``, like every release since 0.24.0, so it+cannot be locked. The OSV finding is ignored in osv-scanner.toml and the+Trivy alert is an expiring entry in .github/release-security-exceptions.json.++The compensating control this file pins: LDR never produces or reads+unstructured's HTML output. Every unstructured-backed loader is a+langchain-community ``Unstructured*Loader`` in its default ``"single"`` mode,+which returns ``"\\n\\n".join(str(element))`` with only ``{"source": path}``+as metadata, and ``es_utils.index_file`` uses element text the same way.++Element text is not markup-free: a document whose text literally reads+``<img onerror=...>`` keeps those characters. Escaping at render time+(autoescaped templates, ``textContent``, DOMPurify) is what keeps that text+inert, independent of this advisory.++Remove this tripwire together with the suppression entries (and the+GHSA-4mvj-m6j5-pmf7 tripwire) when the lock can move to unstructured+>= 0.24.1.+"""++from __future__ import annotations++import ast+from pathlib import Path++import pytest++from local_deep_research.document_loaders import loader_registry+from local_deep_research.document_loaders.loader_registry import (+ LOADER_REGISTRY,+ get_loader_for_path,+)++SRC = Path(loader_registry.__file__).resolve().parents[1]++# Names that only appear when code produces or reads unstructured's HTML+# rendering of a document.+FORBIDDEN_NEEDLES = (+ "text_as_html",+ "elements_to_html",+ "html_parser_version",+ "unstructured.documents.ontology",+ "unstructured.staging",+ "metadata.to_dict",+ "element.to_dict(",+ ".to_html(",+)++# Loader keywords that switch langchain's loaders away from plain joined text+# ("elements"/"paged" return per-element Documents carrying text_as_html).+FORBIDDEN_LOADER_KWARGS = ("mode", "html_parser_version")++# class="Document" is what routes a page to the vulnerable v2 ontology+# emitter when html_parser_version="v2" is passed; the loaders never pass it.+MALICIOUS_HTML = """<!doctype html>+<html><body class="Document">+<p>Visible paragraph <img src=x onerror="alert(1)"></p>+<a href="javascript:alert(2)">click</a>+<svg onload="alert(3)"><text>svg text</text></svg>+<table><tr><td>cell <img src=y onerror="alert(4)"></td></tr></table>+</body></html>+"""+++def test_no_source_touches_unstructured_html_output() -> None:+ modules = sorted(SRC.rglob("*.py"))+ assert len(modules) > 100, "source tree not found"+ offenders = [+ f"{path.relative_to(SRC)}: {needle}"+ for path in modules+ for needle in FORBIDDEN_NEEDLES+ if needle in path.read_text(encoding="utf-8")+ ]+ assert offenders == [], (+ "Code now produces or reads unstructured's HTML output while the "+ "GHSA-v5mq-3xhg-98m9 stored XSS is only suppressed (no fixed release "+ "supports Python 3.14). Use plain element text, or re-evaluate the "+ "suppression:\n" + "\n".join(offenders)+ )+++def _is_unstructured_entry_point(name: str) -> bool:+ return (+ name.startswith("Unstructured") and name.endswith("Loader")+ ) or name.startswith("partition")+++def test_no_unstructured_loader_is_built_outside_single_mode() -> None:+ """Checks every call in src/, not only the registry.++ Calls are matched by name, including names bound through+ ``from ... import UnstructuredHTMLLoader as Alias``. A ``**kwargs`` splat+ into such a call is flagged too, because its keys cannot be read+ statically. A loader class stored in a variable or container and called+ later (as the registry does) is not seen here; the registry is covered by+ test_unstructured_loaders_stay_in_single_mode.+ """+ offenders = []+ for path in sorted(SRC.rglob("*.py")):+ tree = ast.parse(path.read_text(encoding="utf-8"), filename=str(path))+ aliases = {+ alias.asname: alias.name+ for node in ast.walk(tree)+ if isinstance(node, ast.ImportFrom)+ for alias in node.names+ if alias.asname and _is_unstructured_entry_point(alias.name)+ }+ for node in ast.walk(tree):+ if not isinstance(node, ast.Call):+ continue+ func = node.func+ name = (+ func.id+ if isinstance(func, ast.Name)+ else func.attr+ if isinstance(func, ast.Attribute)+ else ""+ )+ name = aliases.get(name, name)+ if not _is_unstructured_entry_point(name):+ continue+ keywords = {keyword.arg for keyword in node.keywords}+ bad = sorted(keywords & set(FORBIDDEN_LOADER_KWARGS))+ if None in keywords:+ bad.append("**")+ if bad:+ offenders.append(+ f"{path.relative_to(SRC)}:{node.lineno}: "+ f"{name}({', '.join(bad)}=...)"+ )+ assert offenders == [], (+ "unstructured is called in a mode that surfaces its HTML output "+ "(GHSA-v5mq-3xhg-98m9), or with a **kwargs splat that hides its "+ "keywords:\n" + "\n".join(offenders)+ )+++def test_unstructured_loaders_stay_in_single_mode() -> None:+ unstructured_entries = {+ extension: entry+ for extension, entry in LOADER_REGISTRY.items()+ if entry["loader_class"].__name__.startswith("Unstructured")+ }+ assert ".html" in unstructured_entries, "HTML loader not found"+ offenders = [+ f"{extension}: {entry['loader_class'].__name__}({key}=...)"+ for extension, entry in unstructured_entries.items()+ for key in FORBIDDEN_LOADER_KWARGS+ if key in entry.get("loader_kwargs", {})+ ]+ assert offenders == [], (+ "An unstructured loader leaves the default single mode, which would "+ "surface per-element text_as_html (GHSA-v5mq-3xhg-98m9):\n"+ + "\n".join(offenders)+ )+++def test_html_loader_returns_text_without_markup(tmp_path) -> None:+ pytest.importorskip("unstructured")+ path = tmp_path / "crafted.html"+ path.write_text(MALICIOUS_HTML, encoding="utf-8")+ loader = get_loader_for_path(path)+ assert loader is not None+ documents = loader.load()++ assert len(documents) == 1+ text = documents[0].page_content+ assert "Visible paragraph" in text+ assert "cell" in text+ for markup in ("<img", "onerror", "onload", "javascript:", "<svg"):+ assert markup not in text, f"{markup!r} survived into loader text"+ assert "text_as_html" not in documents[0].metadatadiff --git a/tests/security/test_unstructured_url_partition_tripwire.py b/tests/security/test_unstructured_url_partition_tripwire.pyindex 8f6851b23a..5a7ed28975 100644--- a/tests/security/test_unstructured_url_partition_tripwire.py+++ b/tests/security/test_unstructured_url_partition_tripwire.py@@ -132,7 +132,11 @@ def test_locked_unstructured_still_needs_suppression() -> None:)assert all(version < Version("0.24.0") for version in versions), (f"pdm.lock contains fixed unstructured {versions}: remove the "- ".trivyignore/.grype.yaml suppressions and this temporary tripwire"+ "GHSA-4mvj-m6j5-pmf7 .trivyignore/.grype.yaml/osv-scanner.toml "+ "suppressions and this temporary tripwire. From 0.24.1 also remove "+ "the GHSA-v5mq-3xhg-98m9 osv-scanner.toml ignore, its entry in "+ ".github/release-security-exceptions.json and "+ "test_unstructured_html_output_tripwire.py")