~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(ci): restore DevSkim's weak-hash rule with line-level exceptions (#6650)
LearningCircuit13170c8672d1
diff --git a/.github/SECURITY_ALERTS.md b/.github/SECURITY_ALERTS.mdindex e696bb6ef4..c105d97b5f 100644--- a/.github/SECURITY_ALERTS.md+++ b/.github/SECURITY_ALERTS.md@@ -115,37 +115,41 @@ to track technical debt and future work.## DS126858 - Weak/Broken Hash Algorithm-**Status:** Excluded in DevSkim workflow via `exclude-rules`--### Explanation--DevSkim flags any literal occurrence of `sha1` as a "weak/broken hash-algorithm". In this codebase the only matches are:--1. **SLSA provenance JSON keys** in `.github/workflows/prerelease-docker.yml` —- the `"sha1"` key inside `digest` objects is part of the- [SLSA in-toto provenance schema](https://slsa.dev/spec/v0.2/provenance) and- identifies the algorithm Git itself uses for commit hashes. We are not- choosing SHA-1 as a cryptographic primitive — Git's commit identifier- format is fixed.--2. **SQLCipher KDF/HMAC algorithm enums** in- `src/local_deep_research/settings/env_definitions/db_config.py`- (`PBKDF2_HMAC_SHA1`, `HMAC_SHA1`). These exist for backwards-compatibility- with existing user databases; the default is SHA-512. Each occurrence- carries an inline `# DevSkim: ignore DS126858` annotation with rationale.--### Why Exclusion Is Safe--1. **Not a cryptographic choice** - The `sha1` strings in SLSA provenance are- *protocol-mandated key names*, not crypto operations we control.-2. **Git's commit hashing is SHA-1 by design** - The Linux kernel and every- git-backed project produces SHA-1 commit IDs; SLSA records them honestly.-3. **Real SHA-1 misuse would be reviewed** - The SQLCipher backwards-compat- uses are documented and reviewed; new uses of SHA-1 as a cryptographic- primitive would be caught in code review and by CodeQL.-4. **No password/signature SHA-1 in this codebase** - Authentication uses- `secrets`/Argon2-class KDFs and SQLCipher's SHA-512 default.+**Status:** Enabled, with documented inline exceptions++The rule runs across the scanned source tree. Exceptions are attached to+specific source lines so new uses remain visible:++- `.github/workflows/prerelease-docker.yml` records the existing Git commit+ identifier in SLSA provenance. Its `GIT_DIGEST_ALGORITHM` assignment has an+ inline suppression; the emitted digest objects retain the `sha1` key.+- `src/local_deep_research/settings/env_definitions/db_config.py` retains+ legacy SQLCipher KDF/HMAC enum values for opening existing databases.+ Their existing inline suppressions remain; the default is SHA-512.+- Existing non-security cache identifiers retain their documented inline+ exceptions in the benchmark and research services+ (`benchmarks/web_api/benchmark_service.py`, `web/services/research_service.py`).+- `src/local_deep_research/journal_quality/data_sources/_openalex_common.py`+ hashes each downloaded OpenAlex partition with `hashlib.md5(...,+ usedforsecurity=False)` and compares it against the manifest's declared+ `meta.md5` to detect transport corruption of a public dataset download.+ This is an integrity check against accidental corruption, not a security+ use of MD5 (there is no adversarial signer to forge), so it carries an+ inline suppression.+- `.github/scripts/file-whitelist-check.sh` greps changed files for the+ literal strings `sha256`/`md5`/etc. as part of its high-entropy-string+ false-positive allowlist; the pattern itself is not a hash computation+ and carries an inline suppression.+- `bearer.yml` references the Bearer rule name `python_lang_weak_hash_md5`+ when disabling that Bearer check; the string is a rule identifier, not+ MD5 usage, and carries an inline suppression at line 31.++CodeQL's `py/weak-sensitive-data-hashing` query is currently excluded+repository-wide via `.github/codeql/codeql-config.yml` (see the+`query-filters` block there for the rationale). Replacing that repo-wide+exclusion with per-alert dismissals of the two reviewed false positives+(the `encrypted_db` cache verifier and the benchmarks `derive_key` helper)+is tracked in #6792; this PR does not change the CodeQL configuration.---@@ -179,7 +183,6 @@ The following rules are excluded in `.github/workflows/devskim.yml`:| DS137138 | Hardcoded Credentials | All matches are test fixtures (mock data) || DS148264 | Use cryptographic random | All `random` usages are non-security (ML shuffle, jitter) || DS172411 | setTimeout code injection | All setTimeout calls pass function refs, never strings |-| DS126858 | Weak/Broken Hash Algorithm | SLSA-schema-required `sha1` JSON key + SQLCipher backwards-compat enums |### Review Cadencediff --git a/.github/scripts/file-whitelist-check.sh b/.github/scripts/file-whitelist-check.shindex 507663e735..61e79831ee 100755--- a/.github/scripts/file-whitelist-check.sh+++ b/.github/scripts/file-whitelist-check.sh@@ -449,7 +449,7 @@ if ! echo "$file" | grep -qE "news_strategy\.py$"; then# Look for base64-like strings or hex strings that are suspiciously longif grep -E "[a-zA-Z0-9+/]{40,}={0,2}|[a-f0-9]{40,}" "$file" >/dev/null 2>&1; then# Exclude common false positives-if ! grep -iE "(sha256|md5|hash|test|example|fixture|integrity)" "$file" >/dev/null 2>&1; then+if ! grep -iE "(sha256|md5|hash|test|example|fixture|integrity)" "$file" >/dev/null 2>&1; then # DevSkim: ignore DS126858HIGH_ENTROPY_VIOLATIONS+=("$file")fifidiff --git a/.github/workflows/devskim.yml b/.github/workflows/devskim.ymlindex cf23b9e1ad..8aa44499eb 100644--- a/.github/workflows/devskim.yml+++ b/.github/workflows/devskim.yml@@ -1,6 +1,10 @@name: DevSkim Security Linteron:+ pull_request:+ paths:+ - ".github/workflows/devskim.yml"+ - ".github/workflows/prerelease-docker.yml"workflow_dispatch:workflow_call: # Called by release-gate.ymlschedule:@@ -88,22 +92,18 @@ jobs:# setTimeout(() => {...}, delay) or setTimeout(functionName, delay).# No string-based setTimeout usage exists.#- # DS126858 - "Weak/Broken Hash Algorithm"- # Flags any occurrence of the literal string "sha1". In this codebase- # the only matches are the JSON key name `"sha1"` inside SLSA provenance- # attestations (.github/workflows/prerelease-docker.yml) — that key name- # is *required* by the SLSA in-toto schema for git-commit digests, and- # Git itself uses SHA-1 for commit identifiers. It is not a cryptographic- # choice we make. Legitimate SHA-1 references elsewhere (PBKDF2_HMAC_SHA1,- # HMAC_SHA1 in db_config.py for SQLCipher backwards compatibility) carry- # their own inline `# DevSkim: ignore DS126858` annotations explaining the- # rationale. See .github/SECURITY_ALERTS.md for the full assessment.- #- exclude-rules: 'DS176209,DS162092,DS137138,DS148264,DS172411,DS126858'+ # Weak-hash exceptions are documented on their specific source lines,+ # including the Git commit algorithm in prerelease-docker.yml.+ exclude-rules: 'DS176209,DS162092,DS137138,DS148264,DS172411'+ # Fork PRs cannot upload because GitHub gives their token read-only+ # permissions for security-events. Only the pull_request trigger (added+ # above, scoped to devskim.yml/prerelease-docker.yml changes) can run+ # against a fork's head; the other triggers (workflow_dispatch,+ # workflow_call, schedule) always run with repo-owned credentials.- name: Upload DevSkim results to GitHub Securityuses: github/codeql-action/upload-sarif@b96794f015dfd88f77b49b1c93e0fa7110f94c63 # v4.38.0- if: always()+ if: always() && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)with:sarif_file: 'devskim-results.sarif'category: devskimdiff --git a/.github/workflows/prerelease-docker.yml b/.github/workflows/prerelease-docker.ymlindex 6892a9991b..beebba1a8c 100644--- a/.github/workflows/prerelease-docker.yml+++ b/.github/workflows/prerelease-docker.yml@@ -353,6 +353,8 @@ jobs:# but shell-var expansion happens at runtime in a confined string# context, eliminating any theoretical injection surface from a# ref/branch name containing shell metacharacters.+ # The provenance records Git's object ID; it does not hash secrets.+ GIT_DIGEST_ALGORITHM=sha1 # DevSkim: ignore DS126858cat > provenance.json <<EOF{"buildType": "https://github.com/${GITHUB_REPOSITORY}/docker-build@v1",@@ -363,7 +365,7 @@ jobs:"configSource": {"uri": "https://github.com/${GITHUB_REPOSITORY}","digest": {- "sha1": "${GITHUB_SHA}"+ "${GIT_DIGEST_ALGORITHM}": "${GITHUB_SHA}"},"entryPoint": ".github/workflows/release.yml"}@@ -382,7 +384,7 @@ jobs:{"uri": "https://github.com/${GITHUB_REPOSITORY}","digest": {- "sha1": "${GITHUB_SHA}"+ "${GIT_DIGEST_ALGORITHM}": "${GITHUB_SHA}"}}]diff --git a/src/local_deep_research/journal_quality/data_sources/_openalex_common.py b/src/local_deep_research/journal_quality/data_sources/_openalex_common.pyindex 0b3ff9f444..09f6a625ae 100644--- a/src/local_deep_research/journal_quality/data_sources/_openalex_common.py+++ b/src/local_deep_research/journal_quality/data_sources/_openalex_common.py@@ -139,12 +139,12 @@ def _partition_decompressed_cap(entry: dict) -> int:return _DEFAULT_MAX_PARTITION_DECOMPRESSED_BYTES-_MD5_HEX_LENGTH = 32+_DIGEST_HEX_LENGTH = 32_HEX_DIGIT_CHARS = frozenset("0123456789abcdefABCDEF")-def _normalize_md5(declared: object) -> str | None:- """Return a lowercase 32-hex digest from a manifest ``meta.md5`` value.+def _normalize_digest(declared: object) -> str | None:+ """Return a lowercase 32-hex digest from a manifest ``meta.md5`` value. # DevSkim: ignore DS126858Accepts a bare hex digest or the same digest wrapped in one matchingpair of double quotes (the S3 ETag wire form for a non-multipart@@ -152,18 +152,18 @@ def _normalize_md5(declared: object) -> str | None:(``<hex>-<n>``), a base64 digest, the wrong length, non-hexcharacters, or a non-string value — so the caller can skipverification for this partition instead of comparing bytes against- a value that was never a valid md5 hex digest.+ a value that was never a valid digest."""if not isinstance(declared, str):return Nonecandidate = declared.strip()if (- len(candidate) == _MD5_HEX_LENGTH + 2+ len(candidate) == _DIGEST_HEX_LENGTH + 2and candidate[0] == '"'and candidate[-1] == '"'):candidate = candidate[1:-1]- if len(candidate) == _MD5_HEX_LENGTH and all(+ if len(candidate) == _DIGEST_HEX_LENGTH and all(c in _HEX_DIGIT_CHARS for c in candidate):return candidate.lower()@@ -229,7 +229,7 @@ def iter_partitions(Raises:ValueError: If a partition's declared ``meta.content_length``doesn't match the number of bytes actually received, or- its declared ``meta.md5`` (once normalized to a bare+ its declared ``meta.md5`` (once normalized to a bare # DevSkim: ignore DS126858digest) doesn't match the digest of the bytes received —either aborts before anything is written to disk, so theprevious snapshot is left in place. Also if a partition's@@ -377,29 +377,29 @@ def iter_partitions(# declared md5 too. A declared value that isn't a 32-hex# digest (plain or ETag-quoted) is logged and skipped# rather than treated as a mismatch.- declared_md5 = meta.get("md5")- if declared_md5 is not None:- normalized_md5 = _normalize_md5(declared_md5)- if normalized_md5 is None:+ declared_digest = meta.get("md5") # DevSkim: ignore DS126858+ if declared_digest is not None:+ normalized_digest = _normalize_digest(declared_digest)+ if normalized_digest is None:shape = (- f"{len(declared_md5)}-character string"- if isinstance(declared_md5, str)- else type(declared_md5).__name__+ f"{len(declared_digest)}-character string"+ if isinstance(declared_digest, str)+ else type(declared_digest).__name__)logger.warning(- f"{label} partition {idx}: manifest md5 is not "+ f"{label} partition {idx}: manifest md5 is not " # DevSkim: ignore DS126858f"a 32-character hex digest ({shape}); skipping ""the integrity check for this partition")else:- actual_md5 = hashlib.md5(+ actual_digest = hashlib.md5( # DevSkim: ignore DS126858resp.content, usedforsecurity=False).hexdigest()- if actual_md5 != normalized_md5:+ if actual_digest != normalized_digest:raise ValueError(- f"{label} partition {idx}: md5 mismatch — "- f"manifest declares {normalized_md5!r} but "- f"received {actual_md5!r}; refusing possibly "+ f"{label} partition {idx}: md5 mismatch — " # DevSkim: ignore DS126858+ f"manifest declares {normalized_digest!r} but "+ f"received {actual_digest!r}; refusing possibly ""corrupted partition")diff --git a/src/local_deep_research/journal_quality/db.py b/src/local_deep_research/journal_quality/db.pyindex 8eb3f0299e..92883f9bd5 100644--- a/src/local_deep_research/journal_quality/db.py+++ b/src/local_deep_research/journal_quality/db.py@@ -1387,7 +1387,7 @@ def _as_number(value):The datasets come from a public upstream over HTTPS — the samehostile-upstream threat model as the manifest URL allowlist (and,- once merged, the pending md5 verification, decompression caps+ once merged, the pending digest verification, decompression capsand https-pin PRs). Junk-typed numerics must land as NULL, notcrash the build's comparisons or the dashboard reads. Thatincludes values SQLite cannot round-trip or store: floats thatdiff --git a/tests/ci/test_devskim_workflow.py b/tests/ci/test_devskim_workflow.pyindex b263999e83..5d8f55e413 100644--- a/tests/ci/test_devskim_workflow.py+++ b/tests/ci/test_devskim_workflow.py@@ -1,5 +1,9 @@"""Contracts for repository-local DevSkim scan scope."""+# allow: no-sut-import — this test parses .github/workflows/devskim.yml+# directly; the "system under test" is CI configuration, not application+# code, so there is nothing under local_deep_research to import.+from pathlib import Pathimport yaml@@ -53,3 +57,19 @@ def test_repository_directory_ignores_match_absolute_scan_target():}& globs)+++def test_ds126858_weak_hash_rule_is_not_excluded():+ """DS126858 (weak/broken hash algorithm) must stay enabled.++ The rule was re-enabled (#6650) after every legitimate weak-hash use in+ the scanned tree was given a line-level ``# DevSkim: ignore DS126858``+ suppression (see .github/SECURITY_ALERTS.md). Re-adding DS126858 to+ ``exclude-rules`` here would silently disable the rule repository-wide+ again instead of relying on those targeted suppressions, so this test+ fails a revert of that change.+ """+ raw_excludes = _devskim_action_step()["with"]["exclude-rules"]+ excluded = {rule.strip() for rule in raw_excludes.split(",")}++ assert "DS126858" not in excluded