~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
feat: add Hypothesis fuzzing tests for OSSF Scorecard compliance
LearningCircuit0c0e76f8b952
diff --git a/.github/workflows/fuzz.yml b/.github/workflows/fuzz.ymlnew file mode 100644index 0000000000..e6365cf893--- /dev/null+++ b/.github/workflows/fuzz.yml@@ -0,0 +1,60 @@+name: Fuzzing Tests++on:+ schedule:+ - cron: '0 0 * * 0' # Weekly on Sunday at midnight+ workflow_dispatch: # Allow manual triggering+ push:+ branches:+ - main+ paths:+ - 'tests/fuzz/**'+ - 'src/local_deep_research/security/**'+ - 'src/local_deep_research/utilities/**'+ pull_request:+ paths:+ - 'tests/fuzz/**'+ - 'src/local_deep_research/security/**'+ - 'src/local_deep_research/utilities/**'++permissions: {}++jobs:+ fuzz-tests:+ name: Hypothesis Fuzz Tests+ runs-on: ubuntu-latest+ permissions:+ contents: read++ steps:+ - name: Checkout code+ uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0++ - name: Set up Python+ uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6+ with:+ python-version: '3.12'++ - name: Install dependencies+ run: |+ python -m pip install --upgrade pip+ pip install pdm+ pdm install --dev --no-editable++ - name: Run fuzz tests+ run: |+ pdm run pytest tests/fuzz/ -v --tb=short \+ --hypothesis-show-statistics \+ --hypothesis-seed=0+ env:+ HYPOTHESIS_PROFILE: ci++ - name: Run extended fuzz tests (scheduled only)+ if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'+ run: |+ # Run with more examples for scheduled/manual runs+ pdm run pytest tests/fuzz/ -v --tb=short \+ --hypothesis-show-statistics \+ -x # Stop on first failure for investigation+ env:+ HYPOTHESIS_PROFILE: extendeddiff --git a/tests/fuzz/__init__.py b/tests/fuzz/__init__.pynew file mode 100644index 0000000000..fc41565ae6--- /dev/null+++ b/tests/fuzz/__init__.py@@ -0,0 +1 @@+# Fuzz testing module using Hypothesisdiff --git a/tests/fuzz/conftest.py b/tests/fuzz/conftest.pynew file mode 100644index 0000000000..affc08df5a--- /dev/null+++ b/tests/fuzz/conftest.py@@ -0,0 +1,31 @@+"""+Pytest configuration for fuzz tests.++Configures Hypothesis profiles for different testing scenarios.+"""++from hypothesis import settings, Verbosity++# CI profile - faster, fewer examples+settings.register_profile(+ "ci",+ max_examples=100,+ verbosity=Verbosity.normal,+ deadline=None, # Disable deadline for CI stability+)++# Extended profile - more thorough testing+settings.register_profile(+ "extended",+ max_examples=500,+ verbosity=Verbosity.verbose,+ deadline=None,+)++# Default profile for local development+settings.register_profile(+ "default",+ max_examples=50,+ verbosity=Verbosity.normal,+ deadline=None,+)diff --git a/tests/fuzz/test_fuzz_security.py b/tests/fuzz/test_fuzz_security.pynew file mode 100644index 0000000000..bdccd92a15--- /dev/null+++ b/tests/fuzz/test_fuzz_security.py@@ -0,0 +1,105 @@+"""+Fuzz tests for security-critical functions using Hypothesis.++These tests verify that security functions don't crash on arbitrary input+and properly reject malicious inputs.+"""++import tempfile++import pytest+from hypothesis import given, settings, strategies as st++from local_deep_research.security.path_validator import PathValidator+++class TestPathValidatorFuzzing:+ """Fuzz tests for PathValidator security functions."""++ @pytest.fixture+ def temp_dir(self):+ """Create a temporary directory for testing."""+ with tempfile.TemporaryDirectory() as tmpdir:+ yield tmpdir++ @given(user_input=st.text(max_size=1000))+ @settings(max_examples=200)+ def test_validate_safe_path_no_crash(self, user_input, temp_dir):+ """Test that validate_safe_path never crashes on arbitrary input."""+ try:+ PathValidator.validate_safe_path(user_input, temp_dir)+ except ValueError:+ # Expected for invalid paths - this is correct behavior+ pass+ except Exception as e:+ # Any other exception type is a bug+ pytest.fail(f"Unexpected exception type: {type(e).__name__}: {e}")++ @given(+ user_input=st.text(+ alphabet=st.characters(+ blacklist_categories=("Cs",), # Exclude surrogates+ ),+ max_size=500,+ )+ )+ @settings(max_examples=200)+ def test_validate_config_path_no_crash(self, user_input):+ """Test that validate_config_path never crashes on arbitrary input."""+ try:+ PathValidator.validate_config_path(user_input, "/tmp")+ except ValueError:+ # Expected for invalid paths+ pass+ except Exception as e:+ # Any other exception type is a bug+ pytest.fail(f"Unexpected exception type: {type(e).__name__}: {e}")++ @given(+ path=st.from_regex(r"\.\./[a-zA-Z0-9/]+", fullmatch=True),+ )+ @settings(max_examples=100)+ def test_path_traversal_blocked(self, path, temp_dir):+ """Test that path traversal attempts are always blocked."""+ with pytest.raises(ValueError):+ PathValidator.validate_safe_path(path, temp_dir)++ @given(+ path=st.sampled_from(+ [+ "/etc/passwd",+ "/etc/shadow",+ "/proc/self/environ",+ "/sys/kernel",+ "/dev/null",+ "etc/passwd",+ "proc/self/environ",+ ]+ )+ )+ def test_restricted_paths_blocked(self, path):+ """Test that restricted system paths are always blocked."""+ with pytest.raises(ValueError):+ PathValidator.validate_config_path(path, "/tmp")++ @given(+ path=st.text(+ alphabet=st.characters(+ whitelist_characters="\x00",+ ),+ min_size=1,+ max_size=100,+ ).map(lambda x: f"test{x}file.json")+ )+ @settings(max_examples=50)+ def test_null_byte_injection_blocked(self, path):+ """Test that null byte injection attempts are handled."""+ try:+ PathValidator.validate_config_path(path, "/tmp")+ except ValueError:+ # Expected - null bytes should be rejected or sanitized+ pass+ except Exception as e:+ pytest.fail(+ f"Unexpected exception for null byte input: {type(e).__name__}"+ )diff --git a/tests/fuzz/test_fuzz_utilities.py b/tests/fuzz/test_fuzz_utilities.pynew file mode 100644index 0000000000..9978d2772a--- /dev/null+++ b/tests/fuzz/test_fuzz_utilities.py@@ -0,0 +1,111 @@+"""+Fuzz tests for utility functions using Hypothesis.++These tests verify that text processing and parsing functions+handle arbitrary input without crashing.+"""++from hypothesis import given, settings, strategies as st++from local_deep_research.utilities.search_utilities import (+ extract_links_from_search_results,+ format_links_to_markdown,+ remove_think_tags,+)+++class TestSearchUtilitiesFuzzing:+ """Fuzz tests for search utility functions."""++ @given(text=st.text(max_size=10000))+ @settings(max_examples=200)+ def test_remove_think_tags_no_crash(self, text):+ """Test that remove_think_tags never crashes on arbitrary input."""+ result = remove_think_tags(text)+ # Should always return a string+ assert isinstance(result, str)++ @given(+ text=st.text(max_size=5000).map(+ lambda x: f"<think>{x}</think>content<think>more{x}</think>"+ )+ )+ @settings(max_examples=100)+ def test_remove_think_tags_removes_tags(self, text):+ """Test that think tags are properly removed."""+ result = remove_think_tags(text)+ assert "<think>" not in result+ assert "</think>" not in result++ @given(+ search_results=st.lists(+ st.fixed_dictionaries(+ {+ "title": st.one_of(st.none(), st.text(max_size=500)),+ "link": st.one_of(st.none(), st.text(max_size=1000)),+ "index": st.one_of(st.none(), st.text(max_size=50)),+ }+ ),+ max_size=100,+ )+ )+ @settings(max_examples=200)+ def test_extract_links_no_crash(self, search_results):+ """Test that extract_links_from_search_results handles arbitrary dicts."""+ result = extract_links_from_search_results(search_results)+ # Should always return a list+ assert isinstance(result, list)+ # All items should be dicts with expected keys+ for item in result:+ assert isinstance(item, dict)+ assert "title" in item+ assert "url" in item++ @given(+ links=st.lists(+ st.fixed_dictionaries(+ {+ "title": st.text(max_size=200),+ "url": st.text(max_size=500),+ "index": st.text(max_size=20),+ }+ ),+ max_size=50,+ )+ )+ @settings(max_examples=100)+ def test_format_links_to_markdown_no_crash(self, links):+ """Test that format_links_to_markdown handles arbitrary link data."""+ result = format_links_to_markdown(links)+ # Should always return a string+ assert isinstance(result, str)++ @given(search_results=st.just([]))+ def test_extract_links_empty_input(self, search_results):+ """Test that empty input returns empty list."""+ result = extract_links_from_search_results(search_results)+ assert result == []++ @given(search_results=st.just(None))+ def test_extract_links_none_input(self, search_results):+ """Test that None input returns empty list."""+ result = extract_links_from_search_results(search_results)+ assert result == []++ @given(+ search_results=st.lists(+ st.fixed_dictionaries(+ {+ "unexpected_key": st.text(max_size=100),+ "another_key": st.integers(),+ }+ ),+ max_size=20,+ )+ )+ @settings(max_examples=50)+ def test_extract_links_missing_keys(self, search_results):+ """Test handling of dicts with missing expected keys."""+ result = extract_links_from_search_results(search_results)+ # Should not crash, returns empty list when required keys missing+ assert isinstance(result, list)