~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
"""Drift guard: the pinned Gitleaks install has exactly one source (#6686).
The version + SHA256 pair for the checksum-verified Gitleaks install used
to be copy-pasted into four workflows, so a partial version bump left
lanes scanning with different binaries while every per-file checksum still
passed. The pair now lives only in
``.github/actions/install-gitleaks/action.yml``; every workflow that needs
the binary must use that action, and a literal inline copy must not
reappear -- in a ``.yml`` or ``.yaml`` workflow, or in any other composite
action under ``.github/actions``.
The action also verifies the archive's checksum before extracting it; that
ordering is load-bearing (a corrupted or substituted archive must never be
unpacked) and is pinned here too.
The pinned version is derived from the release download URL, not from the
archive filename: the archive filename also names the *local* download
path, so a partial bump that moves the URL but not the local filename (or
vice versa) is itself checked for and failed here.
A workflow or action file re-adopting a different, unpinned Gitleaks
distribution channel -- a Docker Hub image, the third-party
"gitleaks-action", or the "gitleaks/v8@" marketplace action -- is flagged
too, even though none of those routes literally copies the version or
checksum.
Separately, ``.pre-commit-config.yaml`` pins its own copy of the Gitleaks
*version* for the pre-commit mirror hook (it runs the ``gitleaks``
pre-commit hook, not this action, so it cannot literally share the pin).
That second copy must move in lockstep with the action's version, with its
version comment on the same line as `rev:`; this file pins that too (see
the lockstep test's docstring for what it cannot verify).
"""
import re
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parents[2]
WORKFLOWS_DIR = REPO_ROOT / ".github" / "workflows"
ACTIONS_DIR = REPO_ROOT / ".github" / "actions"
SHARED_ACTION_DIR = ACTIONS_DIR / "install-gitleaks"
SHARED_ACTION = SHARED_ACTION_DIR / "action.yml"
SHARED_ACTION_REF = "$/.github/actions/install-gitleaks"
PRE_COMMIT_CONFIG = REPO_ROOT / ".pre-commit-config.yaml"
#: Workflows that need the gitleaks binary installed.
INSTALLER_WORKFLOWS = (
"gitleaks.yml",
"gitleaks-main.yml",
"gitleaks-rule-tests.yml",
"docker-tests.yml",
)
#: Matches the release download URL, e.g.
#: "releases/download/v8.30.0/gitleaks_8.30.0_linux_x64.tar.gz", and
#: captures the version so it never needs to be hard-coded here. The
#: version is derived from the URL, not from the archive filename: the
#: archive filename is also used for the *local* download path
#: (``GITLEAKS_ARCHIVE=...``), which a partial version bump could leave
#: stale while the URL moves on -- and a ``.search()`` against the archive
#: filename alone would silently pick up that stale local copy, since it
#: appears first in the file.
RELEASE_URL_VERSION_RE = re.compile(r"releases/download/v(\d+\.\d+\.\d+)/")
#: Matches every mention of the pinned archive filename, e.g.
#: "gitleaks_8.30.0_linux_x64.tar.gz", wherever it appears -- the local
#: download path as well as the release URL -- so all copies can be
#: checked against the release-URL-derived version.
ARCHIVE_NAME_RE = re.compile(r"gitleaks_(\d+\.\d+\.\d+)_linux")
#: Matches a step `name:` that still copies the version, e.g. "Download
#: and verify pinned Gitleaks 8.30.0". The shared action no longer names
#: one (fewer copies to drift); this guards against one creeping back in
#: with a stale version.
STEP_NAME_VERSION_RE = re.compile(r"name:.*Gitleaks\s+(\d+\.\d+\.\d+)")
#: Marker of the release download URL; inline re-hosting of the archive
#: URL is as much a drift risk as the checksum, even under a fresh var name.
GITLEAKS_URL_MARKER = "gitleaks/releases/download"
#: Alternate, unpinned ways of getting Gitleaks onto a runner: the Docker
#: Hub image (``docker run zricethezav/gitleaks:...``), the third-party
#: "gitleaks-action" marketplace action, and the "gitleaks/v8@..." OSS
#: marketplace action. Any of these bypasses the checksum-verified,
#: single-source install in the shared action just as much as an inline
#: URL would. Confirmed absent from the repo (`git grep` across
#: .github and .pre-commit-config.yaml) before this guard was added.
OTHER_INSTALL_ROUTE_RE = re.compile(
r"zricethezav/gitleaks|gitleaks/gitleaks-action|gitleaks/v8@"
)
SHA256SUM_CHECK_RE = re.compile(r"sha256sum\s+(?:--check\b|-c\b)")
#: The gitleaks pre-commit hook's rev line, e.g.:
#: - repo: https://github.com/gitleaks/gitleaks
#: rev: 2ca41cc... # v8.30.0 (frozen)
#: The comment must be on the SAME line as `rev:` -- deliberately, so this
#: can't match a `# vX.Y.Z` comment that drifted onto an unrelated line.
PRE_COMMIT_GITLEAKS_REV_RE = re.compile(
r"repo:[ \t]*https://github\.com/gitleaks/gitleaks[ \t]*\n"
r"[ \t]*rev:[ \t]*\S+[ \t]*#[ \t]*v(\d+\.\d+\.\d+)"
)
def _action_source() -> str:
assert SHARED_ACTION.is_file(), (
f"missing {SHARED_ACTION} — the pinned Gitleaks install has no "
"single source of truth"
)
return SHARED_ACTION.read_text(encoding="utf-8")
def _action_version() -> str:
"""The pinned version, derived from the release download URL (never
hard-coded here, and never derived from the archive filename -- see
RELEASE_URL_VERSION_RE)."""
src = _action_source()
match = RELEASE_URL_VERSION_RE.search(src)
assert match, (
"could not derive the pinned Gitleaks version from the release "
f"download URL in {SHARED_ACTION} — expected "
"'releases/download/vX.Y.Z/'"
)
return match.group(1)
def _strip_comments(src: str) -> str:
"""Drop the part of every line from the first '#' onward.
Good enough for these YAML/shell files: none of the lines this module
inspects for content use '#' inside a quoted value.
"""
return "\n".join(line.split("#", 1)[0] for line in src.splitlines())
def _scan_targets():
"""Every workflow and composite-action file that could re-inline the
pin, excluding the shared install action itself."""
targets = []
for pattern in ("*.yml", "*.yaml"):
targets.extend(sorted(WORKFLOWS_DIR.glob(pattern)))
for path in sorted(ACTIONS_DIR.rglob("*")):
if not path.is_file():
continue
if path.is_relative_to(SHARED_ACTION_DIR):
continue
targets.append(path)
return targets
def test_the_shared_action_is_the_single_pinned_source():
"""The version + checksum pair exists exactly once: the shared action."""
src = _action_source()
version = _action_version()
assert version in src, "the shared action no longer names a version"
assert "GITLEAKS_SHA256" in src, (
"the shared action no longer verifies a SHA256 checksum"
)
assert GITLEAKS_URL_MARKER in src, (
"the shared action no longer downloads from a gitleaks release"
)
def test_every_archive_name_mention_matches_the_release_url_version():
"""Every "gitleaks_X.Y.Z_linux..." mention in the shared action --
the local download path as well as the release URL -- must agree with
the release-URL-derived version. Catches a partial bump that moves
the URL but leaves the local archive filename (or vice versa) stale;
``test_the_shared_action_is_the_single_pinned_source`` alone would
miss that, since the stale copy still contains *some* version."""
src = _action_source()
version = _action_version()
mentions = set(ARCHIVE_NAME_RE.findall(src))
assert mentions, (
f"no 'gitleaks_X.Y.Z_linux' mention found in {SHARED_ACTION}"
)
assert mentions == {version}, (
f"archive-name mention(s) {sorted(mentions)} disagree with the "
f"release-URL-derived version {version!r} in {SHARED_ACTION} — "
"a partial version bump left one copy stale"
)
def test_no_stale_gitleaks_version_in_a_step_name():
"""If a step `name:` names a Gitleaks version at all, it must agree
with the release-URL-derived version -- a third copy of the pin that
could otherwise drift silently."""
src = _action_source()
version = _action_version()
mentions = set(STEP_NAME_VERSION_RE.findall(src))
assert mentions <= {version}, (
f"step-name version mention(s) {sorted(mentions)} disagree with "
f"the release-URL-derived version {version!r} — drop the version "
"from the step name, or bump it in lockstep (#6686)"
)
def test_the_action_verifies_checksum_before_extracting():
"""A corrupted/substituted archive must never reach `tar -x`."""
src = _action_source()
check_match = SHA256SUM_CHECK_RE.search(src)
assert check_match, (
"the shared action no longer runs `sha256sum --check` (or `-c`) "
"against the pinned checksum"
)
extract_index = src.find("tar -xzf")
assert extract_index != -1, (
"the shared action no longer extracts the downloaded archive"
)
assert check_match.start() < extract_index, (
"the checksum must be verified BEFORE the archive is extracted, "
"not after"
)
def test_every_installer_workflow_uses_the_shared_action():
for name in INSTALLER_WORKFLOWS:
path = WORKFLOWS_DIR / name
assert path.is_file(), f"expected workflow {name} not found"
src = _strip_comments(path.read_text(encoding="utf-8"))
assert SHARED_ACTION_REF in src, (
f"{name} does not use {SHARED_ACTION_REF} in a live (non-comment) "
"line — it either installs gitleaks inline (detection drift "
"risk, #6686) or the `uses:` line is commented out"
)
def test_no_inline_pinned_gitleaks_install_reappears():
"""The version/SHA/URL must not be pasted back into any other file.
Scans every workflow (.yml and .yaml) and every file under
.github/actions, except the shared action itself, for the release URL,
the checksum env var name, or the pinned archive filename -- even
under a different variable name than GITLEAKS_SHA256.
"""
version = _action_version()
archive_marker = f"gitleaks_{version}_linux"
markers = ("GITLEAKS_SHA256", archive_marker, GITLEAKS_URL_MARKER)
offenders = []
for path in _scan_targets():
src = path.read_text(encoding="utf-8")
hit = next((marker for marker in markers if marker in src), None)
if hit is not None:
offenders.append((str(path.relative_to(REPO_ROOT)), hit))
assert offenders == [], (
f"inline pinned Gitleaks install found: {offenders}: the version + "
"SHA256/URL belongs only in "
".github/actions/install-gitleaks/action.yml (#6686)"
)
def test_no_other_gitleaks_install_route_reappears():
"""No workflow or action file adopts a different Gitleaks distribution
channel -- the Docker Hub image, the third-party "gitleaks-action", or
the "gitleaks/v8@" marketplace action -- that would install or run
Gitleaks outside the pinned, checksum-verified path in the shared
action (a drift risk this guard cannot otherwise see, since none of
those routes ever names the pinned version or checksum)."""
offenders = []
for path in _scan_targets():
src = path.read_text(encoding="utf-8")
match = OTHER_INSTALL_ROUTE_RE.search(src)
if match is not None:
offenders.append((str(path.relative_to(REPO_ROOT)), match.group(0)))
assert offenders == [], (
f"alternate Gitleaks install route found: {offenders} — use "
f"{SHARED_ACTION_REF} instead of a separate distribution channel "
"(#6686)"
)
def test_precommit_gitleaks_pin_matches_the_shared_action_version():
""".pre-commit-config.yaml pins gitleaks separately; it must track the
shared action's version, or the two scanning lanes drift again.
Limitation: this only checks the human-authored `# vX.Y.Z` comment
against the action's version, and requires that comment to sit on the
same source line as `rev:` (so it can't drift onto an unrelated line
and still pass). It cannot independently verify that the pinned `rev:`
commit SHA actually corresponds to that tag -- pre-commit pins a
frozen commit SHA precisely so the hook resolves offline, and
resolving a tag to a commit requires network access this test does
not have. A comment edited to a false version without updating the
SHA would defeat this check.
"""
assert PRE_COMMIT_CONFIG.is_file(), f"missing {PRE_COMMIT_CONFIG}"
action_version = _action_version()
src = PRE_COMMIT_CONFIG.read_text(encoding="utf-8")
match = PRE_COMMIT_GITLEAKS_REV_RE.search(src)
assert match, (
"could not find the gitleaks hook's pinned `rev: <sha> # vX.Y.Z` "
f"comment (same line) in {PRE_COMMIT_CONFIG}"
)
precommit_version = match.group(1)
assert precommit_version == action_version, (
f".pre-commit-config.yaml pins gitleaks v{precommit_version} but "
f".github/actions/install-gitleaks/action.yml pins v{action_version} "
"— bump both together (#6686)"
)