Skip to content

gitleaks scans every branch, so one false positive on any branch turns hygiene red on every PR #3599

Description

@kyle-sexton

Summary

The hygiene job's secret scan is failing on open PRs for a finding that belongs to a
branch those PRs do not contain. As of this writing that is every PR CI runs, plus main's
next push. The finding itself is a false positive.

Reproduction

.github/workflows/ci.yml:137-144 runs the scan with scan-mode: git. In that mode
gitleaks walks the commits reachable from all refs in the clone, not the checked-out
ref. actions/checkout with fetch-depth: 0 fetches every branch, so each PR's scan
covers unrelated in-flight branches.

Reproduced locally against gitleaks 8.30.1, the version CI installs:

# only origin/main plus the PR branch present
$ gitleaks git --config .gitleaks.toml --redact
INF 1977 commits scanned.
INF no leaks found

# after git fetch origin '+refs/heads/*:refs/remotes/origin/*'
$ gitleaks git --config .gitleaks.toml --redact
INF 2018 commits scanned.
WRN leaks found: 1

Same config, same binary, same checked-out commit. The only variable is which other
branches happen to be in the clone.

The finding

RuleID : generic-api-key
File   : plugins/claude-config/lib/resolve-convention-home.sh
Line   : 248
Commit : f7aec1549dec60407a24a7d8ea720696b7b099af
Branch : chore/retired-conventions-mechanism
Match  : CLAUDE_TOKEN=""

The matched text is an empty shell variable initialisation, next to its sibling on the
line above:

AGENTS_STATE="none"; AGENTS_TOKEN=""
CLAUDE_STATE="none"; CLAUDE_TOKEN=""

These are parser state variables for a file scan. There is no credential here, and the
assigned value is the empty string, so nothing is disclosed. generic-api-key fired on
the identifier alone.

Neither the file nor the line exists on main, which is why main's last push run
(33562372229, f43bd07, 21:40Z) was green and PR runs started failing at 22:12Z: the
commit landed on its branch at 21:47Z, between the two.

Two separate defects

  1. The false positive. CLAUDE_TOKEN="" is a state variable, not a secret.
  2. The blast radius. A finding on any branch fails hygiene on every other branch. A
    contributor sees a red check citing a file their PR never touched, which is the part
    that actually costs time. Defect 1 is a one-line fix on one branch; defect 2 will do
    this again on the next false positive.

Options

For the finding, per .gitleaks.toml's own policy ("Intentional findings use a
repository-owned .gitleaksignore or inline gitleaks:allow comment"), an inline
# gitleaks:allow on that line in the owning branch is the narrower of the two and does
not need a fingerprint that goes stale when the commit is rebased.

For the blast radius, scan-mode: git could be scoped to the range under review
(--log-opts over the PR's own commits) so a PR is judged on its own diff, with
full-history scanning kept on the main-branch push run where it still catches
history rewrites. That is a change to the shared ci-workflows action's contract or its
inputs, so it wants its own decision rather than a drive-by edit.

Not fixed here

Neither fix belongs in an unrelated PR: the false positive is on a branch whose author
should decide the annotation, and the scoping change touches shared CI. Filed so the
red check has an owner instead of being re-diagnosed by whoever hits it next.

Activity

  1. added
    needs-triage
    on Sep 1, 2026
  2. kyle-sexton commented on Sep 1, 2026

    @kyle-sexton
    MemberAuthor

    What the rule actually matched, and why an inline allow is not enough on its own

    Two corrections to the original report, both from reproducing against gitleaks 8.30.1.

    The "secret" is the next line

    Unredacted, the finding spans two lines:

    Rule   : generic-api-key
    Line   : 248 - 249
    Match  : 'CLAUDE_TOKEN=""\nCLAUDE_SHIM=0'
    Secret : 'CLAUDE_SHIM=0'
    

    generic-api-key keys on the TOKEN identifier and then reaches forward for
    something quoted-or-assigned to call the value. What it settled on is
    CLAUDE_SHIM=0, the integer flag on the following line. So the finding is not
    "an empty assignment looks like a credential" as first described; it is the
    keyword on line 248 capturing an unrelated line 249. The assigned value on 248 is
    still the empty string, and nothing is disclosed either way.

    Worth noting for anyone reproducing: the two lines in isolation do not fire.
    A minimal three-line fixture scans clean. The rule only triggers with the real
    file's surrounding content, so a reduced repro will mislead you into thinking it
    is already fixed.

    An inline gitleaks:allow does not clear a finding already in history

    This is the part that changes the fix. Measured on a fixture holding the real
    file, with the annotation added in a later commit:

    Scan mode Result
    git (what CI runs) 1 leak — the earlier commit's patch still carries the unannotated line
    dir (working tree) 0 leaks — the annotation is respected

    scan-mode: git reads commit patches, not the checked-out file, so annotating in
    a follow-up commit leaves every already-pushed commit flagged for as long as it
    stays reachable.

    What this means for the two fixes

    • The annotation is still necessary, and for a reason the first write-up
      missed: without it, the squash-merged commit that lands on main carries the
      bare line, and main goes red permanently rather than transiently. Prepared
      as a 6-line commit (annotation plus a comment recording why), verified dir
      mode clean with it and flagged without, resolver suite 61/61, shellcheck clean.
      Not pushed: it belongs to feat: ship the retired-conventions mechanism (Phase 2b) #3597's branch, and pushing to a branch other than
      the one this session was assigned needs its owner's say-so.
    • The annotation alone does not unblock the currently-red PRs. Only removing
      the unannotated commit from every scanned ref does that, which means either
      rewriting that branch's single commit or waiting for feat: ship the retired-conventions mechanism (Phase 2b) #3597 to squash-merge and
      its branch to be deleted.
    • Which makes the scoping change the load-bearing item rather than the nice-to-have.
      Judging a PR on its own commit range would have made this a non-event: the
      finding would have failed exactly one PR, the one that introduced it, instead
      of every open PR in the repository.

    Generated by Claude Code

  3. kyle-sexton commented on Sep 1, 2026

    @kyle-sexton
    MemberAuthor

    The per-commit fix does not converge, and there is now evidence

    The annotation landed on chore/retired-conventions-mechanism (f7aec154 amended in
    place to f3d0a223, author preserved, delta exactly the six lines). That should have
    been the end of it. It was not, for two reasons that between them make the case for the
    scoping change rather than more annotations.

    The commit stayed reachable

    chore/bespoke-conversion was stacked directly on the pre-amend commit, so the old
    f7aec154 survived on that ref. It was then merged forward rather than rebased
    (38fcb185, "Merge remote 2b (gitleaks annotation) keeping the CI repairs"), which is
    the right call for a branch someone else has checked out and which correctly preserved
    CI repairs made in parallel. It also means a merge keeps the unannotated commit
    reachable by construction. f7aec154 is currently reachable from three refs:

    refs/remotes/origin/chore/bespoke-conversion
    refs/remotes/origin/chore/pilot-plugin-quality
    refs/remotes/origin/chore/retired-conventions-mechanism
    

    Annotating the source does not retract a commit. Only rewriting every ref that carries
    it does, and on a stack with concurrent work that is a fight you keep re-fighting.

    The finding multiplied

    The scan now reports two, not one:

    708739fb2ba1  line 249  plugins/plugin-quality/lib/resolve-convention-home.sh
    f7aec1549dec  line 248  plugins/claude-config/lib/resolve-convention-home.sh
    

    The second is the same file vendored into another plugin on chore/pilot-plugin-quality,
    carrying the same CLAUDE_TOKEN / CLAUDE_SHIM pair. This file is explicitly a
    shared-source candidate ("the first consuming plugin adds both in the same change that
    copies it"), so every future consumer that copies it before the annotation reaches them
    adds another finding, each on its own branch, each failing hygiene for every other branch.

    What this changes

    The scoping change is not the tidier of the two options, it is the only one that
    terminates. Judging a PR on its own commit range would have made both of these findings
    fail exactly the branch that introduced them, where the author can see and fix them,
    instead of failing every open PR in the repository and sending whoever hits it first on
    a cross-branch archaeology run.

    Until that lands, hygiene stays red repo-wide, including on PRs whose diffs touch none
    of this. That is worth knowing before someone reads a red check as their own defect.

    The remaining per-commit cleanup belongs to the branches that own those commits, and is
    being actively worked there.


    Generated by Claude Code

  4. kyle-sexton commented on Sep 2, 2026

    @kyle-sexton
    MemberAuthor

    PR #3618 (commit 220bd3bc) adds a repository-owned .gitleaksignore recording both current fingerprints:

    f7aec1549dec60407a24a7d8ea720696b7b099af:plugins/claude-config/lib/resolve-convention-home.sh:generic-api-key:248
    708739fb2ba1b0196e93f9c07d3293bddfeed2f0:plugins/plugin-quality/lib/resolve-convention-home.sh:generic-api-key:249
    

    This is the third mechanism .gitleaks.toml's own policy names, and unlike the inline annotation it does clear findings already in history: gitleaks reads the ignore file from the checked-out tree, so any branch carrying it scans clean regardless of which refs hold the unannotated commits. Verified with gitleaks 8.30.1 over all 29 remote refs: 2 leaks without the file, 0 with it. Other open PRs pick it up by merging main once #3618 lands.

    This unblocks PRs; it does not close this issue. The scoping change (judging a PR on its own commit range) is still the fix that terminates, since each future false positive needs a new fingerprint here until it lands. The entries can be deleted once their commits stop being reachable.


    Generated by Claude Code

  5. kyle-sexton commented on Sep 6, 2026

    @kyle-sexton
    MemberAuthor

    This was generated by AI during triage.

    Merged from #3610 (duplicate)

    #3610 reported the same defect pair from the other end: the same generic-api-key finding on plugins/claude-config/lib/resolve-convention-home.sh:248 (commit f7aec154), and the same blast radius from scan-mode: git walking every fetched ref. Closing it as a duplicate of this issue, which carries the fuller diagnosis (the two-line match region, and the git vs dir scan-mode table showing why an inline annotation cannot retract a finding already in history). Carrying over what #3610 had and this issue did not:

    Failing run: https://github.com/melodic-software/claude-code-plugins/actions/runs/33567373731/job/100053589384 (commit count on that run: 1,987 scanned against a PR head history of 1,976, which is the all-refs reach stated numerically).

    Acceptance criteria (from #3610):

    • The hygiene job's gitleaks step passes on a pull request whose diff does not touch plugins/claude-config/lib/resolve-convention-home.sh.
    • The fix does not add a repo-specific rule or allowlist to .gitleaks.toml.
    • A decision is recorded on whether the scan should be scoped to the pull request's own commits.

    Follow-ups #3610 was tracking, which this issue now owns:

    1. Remove each .gitleaksignore fingerprint entry once the branch it names squash-merges or is deleted; the commits become unreachable and the entry becomes dead config. The file states that condition inline.
    2. Add the inline gitleaks:allow marker to the plugins/plugin-quality/lib/resolve-convention-home.sh copy on chore/pilot-plugin-quality, which is still unmarked. Without it, each new commit touching that line mints a fresh fingerprint no entry covers.
    3. Record the scan-scoping decision explicitly, including if the decision is "leave as is". Both issues independently reached the conclusion that scoping is the only fix that terminates.

    One empirical result from #3610 worth keeping, since it rules out the cheapest-looking fix: renaming the flag does not work. Tested against gitleaks 8.30.1 with this repo's config, CLAUDE_SHIM_PRESENT=0 still fires, and so does a blank line between the flag and the *_TOKEN initializations. Only removing the *_TOKEN variables or marking the line suppresses it.

    Also on the record from #3610: .gitleaksignore is registered in scripts/affected-tests-no-suite.txt paired with the hygiene lane, so a future change to it fails the affected-tests contract rather than mapping to no suite.


    Generated by Claude Code

  6. added
    needs-human
    and removed
    needs-triage
    on Sep 23, 2026
  7. kyle-sexton commented on Sep 23, 2026

    @kyle-sexton
    MemberAuthor

    This was generated by AI during triage.

    Human-gated. Open decision: whether to scope gitleaks scan-mode: git to the PR's own commit range (keep full-history on main push) vs leave as-is

  8. added theissue type on Sep 23, 2026
  9. kyle-sexton commented on Sep 29, 2026

    @kyle-sexton
    MemberAuthor

    Reopened. This comes from the 2026-09-29 audit of the Cursor agent run. The labels needs-human, work-class: structural and priority: low stay; this issue closes on merge of the fix PR, not before.

    Findings

    • ci: scope gitleaks git scan to the event's commits (#3599) #5131 closed this issue as completed. It replaced the ci-workflows gitleaks composite step with scripts/gitleaks-scoped-scan.sh, nine hours after the owner's own ci-workflows#629 was closed and v0.30.0 shipped the log-opts input that the composite needed for exactly this.
    • Push events lost the full-history scan: the fork scanned only before^..after, and a dispatch scanned -1.
    • The fork lost the composite's asset cache and shared installer.
    • An opposite decision (docs(ci): park gitleaks all-refs scan default (#3599) #5003, closed unmerged) never reached main, so the two positions were never reconciled.

    Decision

    The owner authorized, in a Claude Code session on 2026-09-29: re-pin the composite to v0.30.x with event-scoped log-opts, restore a full-history scan on push to main, and delete the fork. This comment records that as the answer to the third acceptance criterion carried over from #3610 ("a decision is recorded on whether the scan is scoped"). #5003's parked-until-funded text is not a decision and is not restated here.

    Fix

    PR #5316 does exactly that: pin 35880dcb (v0.30.1), scan-mode: git with empty log-opts (pull_request scans <base>..HEAD, push scans HEAD, dispatch scans --all), the fork and its test deleted, and the two 04f4bcd5 fingerprints restored in .gitleaksignore because that commit is in main's history.

    Acceptance mapping

    1. Hygiene passes on a PR that does not touch resolve-convention-home.sh: shown by ci: re-pin gitleaks composite, extend the Windows lane, wire unwired suites #5316's own lint run ('Scan for secrets').
    2. No repo-specific rule in .gitleaks.toml: holds; the file is untouched.
    3. A decision is recorded: this comment.

    #5316 says Closes #3599; the issue closes on merge.

    Follow-ups carried over from #3610

    1. Dead .gitleaksignore entries: removed in ci: re-pin gitleaks composite, extend the Windows lane, wire unwired suites #5316 (five lines for commits no origin ref reaches; the two 04f4bcd5 lines stay).
    2. The unmarked plugin-quality copy already carries # gitleaks:allow on origin/main (plugins/plugin-quality/lib/resolve-convention-home.sh:259).
    3. The scoping decision is recorded in this comment.

    One consequence for the owner

    A manual dispatch of ci scans every ref (the composite's documented --all default). On 2026-09-29 that reports 8 findings on other refs, six of them on other PR heads. Pull requests and pushes are unaffected.

  10. kyle-sexton commented on Sep 29, 2026

    @kyle-sexton
    MemberAuthor

    Correction to the section "One consequence for the owner" in the earlier comment on this issue (#3599 (comment)). That section said a manual dispatch of ci "reports 8 findings on other refs, six of them on other PR heads". That was wrong for a CI run.

    What a dispatch actually does

    • The dispatch that ran on PR ci: re-pin gitleaks composite, extend the Windows lane, wire unwired suites #5316's branch (ci run 36577675603, job lint, step "Scan for secrets", log-opts unset so it scans --all) scanned 3192 commits and reported no leaks found.
    • A scan of only the origin heads and tags (gitleaks git . --log-opts="--remotes=origin --tags", run from the branch worktree so the branch's .gitleaksignore applies) scanned 3185 commits across 59 refs and exited 0, no leaks.

    Where the 8 findings came from

    They came from a local scan with --log-opts=--all in a clone that also holds refs/remotes/pr/*: 3047 local-only refs to closed and open pull request heads fetched into the local clone. A CI clone holds only origin's branches and tags, so it does not have those refs. Repeating the local all-refs scan today reports 11 findings (more PR heads have been fetched since). Every one is in a commit that only a refs/remotes/pr/* ref reaches: PR heads #5131, #5109, #5086, #5080, #4518, #4334 and #66. None is reachable from an origin branch or tag.

    So a manual dispatch of ci is not expected to fail because of other refs, and the comment above the step in ci.yml no longer says it reports findings on other branches. A finding would show up in a dispatch only if an origin branch or tag carried one; none does today.

    Acceptance criterion 1, result

    PR #5316's own lint run (run 36579146249, head 5ca5fe296, pull_request event): "Scan for secrets" concluded success, 8 commits scanned (<base>..HEAD), no leaks found. Criterion 1 is met; criteria 2 and 3 are unchanged from the earlier comment, so Closes #3599 stands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-human

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions