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(web): read collection identifiers from page metadata (#8241)

LearningCircuit900aac72e940
diff --git a/changelog.d/+collection-template-metadata.security.md b/changelog.d/+collection-template-metadata.security.md
new file mode 100644
index 0000000000..fab5d400d8
--- /dev/null
+++ b/changelog.d/+collection-template-metadata.security.md
@@ -0,0 +1 @@
+Keep collection page identifiers in HTML metadata outside script source.
diff --git a/src/local_deep_research/web/templates/pages/collection_details.html b/src/local_deep_research/web/templates/pages/collection_details.html
index 7a02dc2b02..6622d7c8b9 100644
--- a/src/local_deep_research/web/templates/pages/collection_details.html
+++ b/src/local_deep_research/web/templates/pages/collection_details.html
@@ -4,6 +4,7 @@
{% block title %}Collection Details{% endblock %}
{% block extra_head %}
+<meta name="collection-id" content="{{ collection_id }}">
<link rel="stylesheet" href="/static/css/collection_details.css">
<link rel="stylesheet" href="/static/css/components/semantic-search.css">
{% endblock %}
@@ -221,7 +222,7 @@
<!-- Pass collection_id to JavaScript -->
<script nonce="{{ csp_nonce }}">
- const COLLECTION_ID = "{{ collection_id }}";
+ const COLLECTION_ID = document.querySelector('meta[name="collection-id"]').content;
</script>
<script defer src="/static/js/deletion/confirmation_modal.js"></script>
<script defer src="/static/js/deletion/delete_manager.js"></script>
diff --git a/src/local_deep_research/web/templates/pages/collection_upload.html b/src/local_deep_research/web/templates/pages/collection_upload.html
index 755054445a..3ff6245583 100644
--- a/src/local_deep_research/web/templates/pages/collection_upload.html
+++ b/src/local_deep_research/web/templates/pages/collection_upload.html
@@ -3,6 +3,7 @@
{% block title %}Upload Files - {{ collection_name or 'Collection' }}{% endblock %}
{% block extra_head %}
+<meta name="collection-id" content="{{ collection_id }}">
<link rel="stylesheet" href="/static/css/collection_details.css">
<style nonce="{{ csp_nonce }}">
/* Storage Mode Options - reused from storage_mode_modal.html */
@@ -237,7 +238,7 @@
<!-- Pass collection_id to JavaScript -->
<script nonce="{{ csp_nonce }}">
- const COLLECTION_ID = "{{ collection_id }}";
+ const COLLECTION_ID = document.querySelector('meta[name="collection-id"]').content;
</script>
<script defer src="/static/js/collection_upload.js"></script>
{% endblock %}
diff --git a/tests/security/test_collection_template_metadata.py b/tests/security/test_collection_template_metadata.py
new file mode 100644
index 0000000000..db5af38a25
--- /dev/null
+++ b/tests/security/test_collection_template_metadata.py
@@ -0,0 +1,53 @@
+"""Collection page data stays in HTML metadata rather than script source."""
+
+import pytest
+from bs4 import BeautifulSoup
+from starlette.requests import Request
+
+from local_deep_research.web.template_config import templates
+
+
+ "template",
+ ["pages/collection_details.html", "pages/collection_upload.html"],
+)
+ "collection_id",
+ ["00000000-0000-4000-8000-000000000001", "ordinary ' \" & < > \\ π", ""],
+ ids=["canonical-uuid", "punctuation", "empty"],
+)
+def test_collection_identifier_is_html_data(app, template, collection_id):
+ request = Request(
+ {
+ "type": "http",
+ "method": "GET",
+ "path": "/library/collections/fixture",
+ "root_path": "",
+ "scheme": "http",
+ "headers": [],
+ "query_string": b"",
+ "session": {},
+ "app": app,
+ "router": app.router,
+ "server": ("testserver", 80),
+ }
+ )
+ response = templates.TemplateResponse(
+ request,
+ template,
+ {"collection_id": collection_id, "collection_name": "Fixture"},
+ )
+ document = BeautifulSoup(response.body, "html.parser")
+ metadata = document.select('head meta[name="collection-id"]')
+ assert len(metadata) == 1
+ assert metadata[0]["content"] == collection_id
+ assert set(metadata[0].attrs) == {"name", "content"}
+
+ bootstraps = [
+ script.get_text()
+ for script in document.find_all("script", src=False)
+ if "const COLLECTION_ID" in script.get_text()
+ ]
+ assert len(bootstraps) == 1
+ if collection_id:
+ assert collection_id not in bootstraps[0]