~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(hooks): close URL-security bypass gaps (#3546)
LearningCircuit33d33b099bb1
diff --git a/.pre-commit-hooks/check-url-security.py b/.pre-commit-hooks/check-url-security.pyindex 7419fbeac9..66619adc92 100755--- a/.pre-commit-hooks/check-url-security.py+++ b/.pre-commit-hooks/check-url-security.py@@ -8,6 +8,7 @@ XSS attacks through javascript:, data:, and vbscript: schemes.import sysimport re+from pathlib import Pathdef check_url_validation(file_path):@@ -44,20 +45,15 @@ def check_url_validation(file_path):or re.search(r"href\s*=\s*['\"]https?://", content))- # If the file handles external URLs but doesn't have validation, that's concerning+ # If the file handles external URLs but doesn't have validation, that's concerning.+ # (Previously there was a "has_basic_protection" short-circuit that checked for+ # "javascript:" plus any of startsWith/includes/indexOf anywhere in the file —+ # trivially satisfied by unrelated code or comments, so it masked real gaps.)if handles_external_urls and not has_url_validator:- # Check for basic javascript: protection at least- has_basic_protection = "javascript:" in content and (- "startsWith" in content- or "includes" in content- or "indexOf" in content+ issues.append(+ f"{file_path}: File handles external URLs but lacks URL validation checks")- if not has_basic_protection:- issues.append(- f"{file_path}: File handles external URLs but lacks URL validation checks"- )-# Check for specific problematic patternsfor line_num, line in enumerate(lines, 1):# Skip comments@@ -113,23 +109,31 @@ def main():all_issues = []+ # Path segments that mark a file as non-production (tests, vendored code, build output).+ # Segment-matching avoids the bug where a bare substring like "test" silently skipped+ # real production files such as attestation_service.js or latest_products.js.+ SKIP_SEGMENTS = {+ "tests",+ "test",+ "spec",+ "specs",+ "__tests__",+ "vendor",+ "node_modules",+ "dist",+ "build",+ }+for file_path in sys.argv[1:]:# Only check JavaScript filesif not file_path.endswith(".js"):continue- # Skip test files and vendor files- if any(- skip in file_path- for skip in [- "test",- "spec",- "vendor",- "node_modules",- "dist",- "build",- ".min.js",- ]+ p = Path(file_path)+ if (+ SKIP_SEGMENTS.intersection(p.parts)+ or p.name.startswith("test_")+ or p.name.endswith((".test.js", ".spec.js", ".min.js"))):continuediff --git a/tests/hooks/test_check_url_security.py b/tests/hooks/test_check_url_security.pynew file mode 100644index 0000000000..c1986252f0--- /dev/null+++ b/tests/hooks/test_check_url_security.py@@ -0,0 +1,125 @@+"""+Tests for the check-url-security pre-commit hook.++Covers regressions for previously-missed patterns:+- substring-based skip list (bare "test"/"spec") silently skipped production+ files such as attestation_service.js, latest_products.js, respectful_handler.js+- `has_basic_protection` short-circuit was trivially satisfied by a comment+ mentioning "javascript:" plus any unrelated .includes()/.startsWith()+"""++import subprocess+import sys+import tempfile+from pathlib import Path+++HOOK_SCRIPT = (+ Path(__file__).parent.parent.parent+ / ".pre-commit-hooks"+ / "check-url-security.py"+)+++def _run_hook(content: str, filename: str) -> subprocess.CompletedProcess:+ """Write content to a temp file with a specific path and run the hook."""+ with tempfile.TemporaryDirectory() as d:+ path = Path(d) / filename+ path.parent.mkdir(parents=True, exist_ok=True)+ path.write_text(content)+ return subprocess.run(+ [sys.executable, str(HOOK_SCRIPT), str(path)],+ capture_output=True,+ text=True,+ )+++UNPROTECTED_EXTERNAL = (+ 'fetch("https://api.example.com/data");\nelement.href = userProvidedUrl;\n'+)+++class TestSkipListDoesNotSilentlyExempt:+ """Files whose names merely contain 'test'/'spec' as substrings must be scanned."""++ def test_attestation_service_is_scanned(self):+ """'attestation_service.js' contains substring 'test' but is not a test file."""+ result = _run_hook(UNPROTECTED_EXTERNAL, "attestation_service.js")+ assert result.returncode == 1+ assert "URL Security Issues" in result.stdout++ def test_latest_products_is_scanned(self):+ """'latest_products.js' contains substring 'test'."""+ result = _run_hook(UNPROTECTED_EXTERNAL, "latest_products.js")+ assert result.returncode == 1++ def test_respectful_is_scanned(self):+ """'respectful_handler.js' contains substring 'spec'."""+ result = _run_hook(UNPROTECTED_EXTERNAL, "respectful_handler.js")+ assert result.returncode == 1+++class TestSkipListStillExemptsRealTestFiles:+ """Legitimate test / vendor / build files must remain skipped."""++ def test_test_prefix_skipped(self):+ result = _run_hook(UNPROTECTED_EXTERNAL, "test_foo.js")+ assert result.returncode == 0++ def test_tests_directory_skipped(self):+ result = _run_hook(UNPROTECTED_EXTERNAL, "tests/helpers.js")+ assert result.returncode == 0++ def test_dot_spec_suffix_skipped(self):+ result = _run_hook(UNPROTECTED_EXTERNAL, "foo.spec.js")+ assert result.returncode == 0++ def test_dot_test_suffix_skipped(self):+ result = _run_hook(UNPROTECTED_EXTERNAL, "foo.test.js")+ assert result.returncode == 0++ def test_vendor_directory_skipped(self):+ result = _run_hook(UNPROTECTED_EXTERNAL, "vendor/lib.js")+ assert result.returncode == 0++ def test_node_modules_directory_skipped(self):+ result = _run_hook(UNPROTECTED_EXTERNAL, "node_modules/lodash/index.js")+ assert result.returncode == 0++ def test_min_suffix_skipped(self):+ result = _run_hook(UNPROTECTED_EXTERNAL, "app.min.js")+ assert result.returncode == 0+++class TestBasicProtectionShortCircuitRemoved:+ """The weak has_basic_protection short-circuit should no longer mask gaps."""++ def test_comment_mentioning_javascript_and_unrelated_includes_does_not_bypass(+ self,+ ):+ """A comment mentioning 'javascript:' + any unrelated .includes() used to pass."""+ content = (+ "// Do not use javascript: schemes anywhere in this app.\n"+ 'if (items.includes("foo")) { doThing(); }\n'+ 'fetch("https://api.example.com/data");\n'+ "element.href = userUrl;\n"+ )+ result = _run_hook(content, "app.js")+ assert result.returncode == 1+ assert "URL validation" in result.stdout++ def test_file_with_real_urlvalidator_passes(self):+ """Files that actually import URLValidator still pass."""+ content = (+ 'import { URLValidator } from "./url-validator.js";\n'+ 'fetch("https://api.example.com/data");\n'+ 'URLValidator.safeAssign(element, "href", userUrl);\n'+ )+ result = _run_hook(content, "app.js")+ assert result.returncode == 0++ def test_file_with_no_external_urls_passes(self):+ """Files that don't handle external URLs should pass."""+ content = 'element.textContent = "hello";\n'+ result = _run_hook(content, "app.js")+ assert result.returncode == 0