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.

ci: scope scheduled secret scans to checkout history (#8198)

LearningCircuit196020ee3cc7
diff --git a/.github/workflows/gitleaks.yml b/.github/workflows/gitleaks.yml
index 4a696ebf42..4b2e5ae26b 100644
--- a/.github/workflows/gitleaks.yml
+++ b/.github/workflows/gitleaks.yml
@@ -43,6 +43,10 @@ jobs:
- name: Run Gitleaks Secret Scanner
id: gitleaks
shell: bash
+ env:
+ SCAN_EVENT: ${{ github.event_name }}
+ SCAN_BASE_SHA: ${{ github.event.pull_request.base.sha }}
+ SCAN_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
args=(detect
--config=.gitleaks.toml
@@ -51,10 +55,12 @@ jobs:
--report-path=gitleaks-results.sarif
--redact
--verbose)
- if [[ "${{ github.event_name }}" == "pull_request" ]]; then
- args+=(--log-opts="${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}")
+ if [[ "$SCAN_EVENT" == "pull_request" ]]; then
+ args+=(--log-opts="${SCAN_BASE_SHA}..${SCAN_HEAD_SHA}")
else
- args+=(--log-opts=--all)
+ # Report only history reachable from this checkout. Other fetched
+ # branches have their own PR scans and must not be attributed here.
+ args+=(--log-opts=HEAD)
fi
gitleaks "${args[@]}"
diff --git a/tests/ci/standalone/test_gitleaks_scan_scope.py b/tests/ci/standalone/test_gitleaks_scan_scope.py
new file mode 100644
index 0000000000..51c572084f
--- /dev/null
+++ b/tests/ci/standalone/test_gitleaks_scan_scope.py
@@ -0,0 +1,114 @@
+"""Run the workflow's scan against independent synthetic Git histories."""
+
+# allow: no-sut-import -- exercises the repository's scanner workflow.
+
+import json
+import os
+from pathlib import Path
+import shutil
+import subprocess
+
+import pytest
+import yaml
+
+
+ROOT = Path(__file__).resolve().parents[3]
+
+
+ ("event", "expected"),
+ [
+ ("schedule", {"historical.txt", "current.txt"}),
+ ("workflow_dispatch", {"historical.txt", "current.txt"}),
+ ("pull_request", {"current.txt"}),
+ ],
+)
+def test_scan_preserves_reachable_history_and_excludes_other_branches(
+ tmp_path, event, expected
+):
+ scanner = os.environ.get("GITLEAKS_PATH") or shutil.which("gitleaks")
+ if scanner is None:
+ if os.environ.get("REQUIRE_GITLEAKS") == "1":
+ pytest.fail("Gitleaks is required for this selection")
+ pytest.skip("Gitleaks is not installed")
+
+ def git(*args):
+ return subprocess.run(
+ ["git", *args],
+ cwd=tmp_path,
+ check=True,
+ capture_output=True,
+ text=True,
+ timeout=10,
+ ).stdout.strip()
+
+ git("init", "--initial-branch=main")
+ git("config", "user.name", "Synthetic Fixture")
+ git("config", "user.email", "[email protected]")
+ # These markers exercise revision selection; they are not credentials.
+ (tmp_path / ".gitleaks.toml").write_text(
+ 'title = "Synthetic scope fixture"\n'
+ '[[rules]]\nid = "scope-fixture"\n'
+ 'regex = "SCAN_SCOPE_FIXTURE_[A-Z_]+"\n',
+ encoding="utf-8",
+ )
+ (tmp_path / ".gitleaksignore").write_text("", encoding="utf-8")
+ historical = tmp_path / "historical.txt"
+ historical.write_text("SCAN_SCOPE_FIXTURE_HISTORICAL\n", encoding="utf-8")
+ git("add", ".")
+ git("commit", "-m", "Add historical fixture")
+ historical.unlink()
+ git("add", ".")
+ git("commit", "-m", "Remove historical fixture")
+ base = git("rev-parse", "HEAD")
+ git("switch", "-c", "unrelated")
+ (tmp_path / "unrelated.txt").write_text(
+ "SCAN_SCOPE_FIXTURE_OTHER_BRANCH\n", encoding="utf-8"
+ )
+ git("add", ".")
+ git("commit", "-m", "Add unrelated fixture")
+ git("switch", "main")
+ (tmp_path / "current.txt").write_text(
+ "SCAN_SCOPE_FIXTURE_CURRENT\n", encoding="utf-8"
+ )
+ git("add", ".")
+ git("commit", "-m", "Add current fixture")
+ head = git("rev-parse", "HEAD")
+
+ workflow = yaml.safe_load(
+ (ROOT / ".github/workflows/gitleaks.yml").read_text(encoding="utf-8")
+ )
+ step = next(
+ step
+ for step in workflow["jobs"]["gitleaks"]["steps"]
+ if step.get("id") == "gitleaks"
+ )
+ for name in ("SCAN_EVENT", "SCAN_BASE_SHA", "SCAN_HEAD_SHA"):
+ assert name in step["env"]
+ bin_dir = tmp_path / "bin"
+ bin_dir.mkdir()
+ (bin_dir / "gitleaks").symlink_to(Path(scanner).resolve())
+ result = subprocess.run(
+ ["bash", "-e", "-o", "pipefail", "-c", step["run"]],
+ cwd=tmp_path,
+ env={
+ **os.environ,
+ "PATH": str(bin_dir) + os.pathsep + os.defpath,
+ "SCAN_EVENT": event,
+ "SCAN_BASE_SHA": base,
+ "SCAN_HEAD_SHA": head,
+ },
+ capture_output=True,
+ text=True,
+ timeout=30,
+ check=False,
+ )
+ assert result.returncode == 1, result.stderr
+ report = json.loads(
+ (tmp_path / "gitleaks-results.sarif").read_text(encoding="utf-8")
+ )
+ findings = report["runs"][0]["results"]
+ assert {
+ result["locations"][0]["physicalLocation"]["artifactLocation"]["uri"]
+ for result in findings
+ } == expected