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.

security: fix content validation bypass on upload dedup path (#3145)

LearningCircuitc6a4df580f78
diff --git a/src/local_deep_research/research_library/routes/rag_routes.py b/src/local_deep_research/research_library/routes/rag_routes.py
index 3cabd504f8..687d48f61a 100644
--- a/src/local_deep_research/research_library/routes/rag_routes.py
+++ b/src/local_deep_research/research_library/routes/rag_routes.py
@@ -1421,11 +1421,23 @@ def upload_to_collection(collection_id):
pdf_storage == "database"
and pdf_storage_manager is not None
):
- pdf_upgraded = pdf_storage_manager.upgrade_to_pdf(
- document=existing_doc,
- pdf_content=file_content,
- session=db_session,
- )
+ # NOTE: Only the PDF magic-byte check is needed here.
+ # File count validation is already handled by Flask's MAX_CONTENT_LENGTH.
+ # Filename sanitization already happens via sanitize_filename() above.
+ # See PR #3145 review for details.
+ if file_content[:4] != b"%PDF":
+ logger.debug(
+ "Skipping PDF upgrade for %s: not a PDF file",
+ filename,
+ )
+ else:
+ pdf_upgraded = (
+ pdf_storage_manager.upgrade_to_pdf(
+ document=existing_doc,
+ pdf_content=file_content,
+ session=db_session,
+ )
+ )
# Check if already in collection
existing_link = (