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.

test(security): pin PDF leaf-symlink write refusal (#7035)

LearningCircuitb4110d6fc73a
diff --git a/tests/research_library/services/test_pdf_storage_manager.py b/tests/research_library/services/test_pdf_storage_manager.py
index 4e2983e63a..983e900726 100644
--- a/tests/research_library/services/test_pdf_storage_manager.py
+++ b/tests/research_library/services/test_pdf_storage_manager.py
@@ -1,5 +1,6 @@
"""Tests for PDF Storage Manager."""
+import os
from unittest.mock import MagicMock, patch
import pytest
@@ -502,6 +503,31 @@ class TestPDFStorageManagerUpgradeToPdf:
class TestPDFStorageManagerFilesystemWrite:
"""Tests for actual filesystem write operations."""
+ @pytest.mark.skipif(
+ not hasattr(os, "O_NOFOLLOW"), reason="O_NOFOLLOW unavailable"
+ )
+ def test_refuses_preplanted_pdf_leaf_symlink(
+ self, tmp_path, mock_pdf_content
+ ):
+ """A PDF filename must not overwrite a symlink target outside the library."""
+ library_root = tmp_path / "library"
+ pdf_dir = library_root / "pdfs"
+ pdf_dir.mkdir(parents=True)
+ outside_pdf = tmp_path / "outside.pdf"
+ outside_pdf.write_bytes(b"ORIGINAL")
+ symlink = pdf_dir / "evil.pdf"
+ try:
+ symlink.symlink_to(outside_pdf)
+ except (OSError, NotImplementedError):
+ pytest.skip("Cannot create symlinks in this environment")
+
+ manager = PDFStorageManager(library_root, "filesystem")
+ with pytest.raises((OSError, ValueError)):
+ manager._save_to_filesystem(mock_pdf_content, "evil.pdf")
+
+ assert symlink.is_symlink()
+ assert outside_pdf.read_bytes() == b"ORIGINAL"
+
def test_saves_to_filesystem_without_encoding_error(
self, tmp_path, mock_pdf_content
):