enh(secu): manage invalid-revision range error - #64
Open
sc979 wants to merge 13 commits into
Open
Conversation
sc979
commented
Jul 28, 2026
sc979
commented
Jul 28, 2026
sc979
commented
Jul 28, 2026
sc979
commented
Jul 28, 2026
Co-authored-by: Stéphane Chapron <34628915+sc979@users.noreply.github.com> Signed-off-by: Stéphane Chapron <34628915+sc979@users.noreply.github.com>
sc979
commented
Jul 28, 2026
Signed-off-by: Stéphane Chapron <34628915+sc979@users.noreply.github.com>
sc979
commented
Jul 28, 2026
sc979
marked this pull request as draft
July 28, 2026 12:18
sc979
commented
Jul 29, 2026
sc979
commented
Jul 29, 2026
sc979
commented
Jul 29, 2026
sc979
commented
Jul 29, 2026
sc979
commented
Jul 29, 2026
Co-authored-by: Stéphane Chapron <34628915+sc979@users.noreply.github.com> Signed-off-by: Stéphane Chapron <34628915+sc979@users.noreply.github.com>
sc979
marked this pull request as ready for review
July 29, 2026 09:25
sc979
commented
Jul 29, 2026
Signed-off-by: Stéphane Chapron <34628915+sc979@users.noreply.github.com>
Signed-off-by: Stéphane Chapron <34628915+sc979@users.noreply.github.com>
sc979
commented
Jul 29, 2026
Signed-off-by: Stéphane Chapron <34628915+sc979@users.noreply.github.com>
sc979
commented
Jul 29, 2026
Signed-off-by: Stéphane Chapron <34628915+sc979@users.noreply.github.com>
already managed by the triggering pipeline. causing failing loop Signed-off-by: Stéphane Chapron <34628915+sc979@users.noreply.github.com>
Signed-off-by: Stéphane Chapron <34628915+sc979@users.noreply.github.com>
On a push that creates a new branch (or rewrites history), the gitleaks range fell back to a full-history scan. Because a branch usually forks off the default branch, that re-scanned commits already living in the default branch and re-reported pre-existing secrets that the branch never introduced. Resolve the range against the default branch instead: scan only merge-base(origin/<default>, after)..after, i.e. the commits unique to the branch. The empty-"before" case now follows the same path, so it is consistent with a real new branch. When the default branch cannot be resolved, fall back to a full scan (over-scan is the safe direction). Also correct the range-resolved log to ::notice:: (::info:: is not a valid workflow command). Assisted-by: Claude Code (claude-opus-4-8)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
What are your needs or what are you planning to do in this PR?
Resolves the "Invalid revision range" failures on the gitleaks job by resolving the
scan range defensively (retry + re-fetch), narrows the scan so it only covers commits
that actually belong to the change under test, and makes the build fail only on a
real secret finding so the alert isn't raised on tooling errors.
Scan-range behavior
compute_range()picks thegit logrange gitleaks scans (--log-opts), with anempty value meaning a full-history scan.
merge-base(base, head)..head— only the PR's own commits.before..after— only the commits the push added.before/ rewritten history →merge-base(origin/<default>, after)..after— only the commits unique to this branch since it diverged from the default branch.
The shared base history is already scanned on the default branch's own pushes, so
re-scanning it here would just re-report pre-existing, unrelated findings.
full scan. Over-scan is the safe direction — no path silently scans nothing.
Build outcome & alerting
The alert is wired to the build failure, so the job fails only when it must:
0)2)exit 1)exit 0) +::error::logexit 1)A gitleaks tool/internal error no longer fails the build, so it can't raise a
false alert; it is still surfaced as an
::error::annotation for visibility. Only agenuine secret finding (or an unrecoverable range after every retry) fails the job.
The range-resolved log is displayed in the logs
compute_range()test coverageVerified verbatim against a throwaway repo mimicking the runner layout (default
branch present as
refs/remotes/origin/<default>, detached HEAD). Each case assertsthe resulting
--log-opts(empty = full scan) and the return code.push — existing branch
--log-optsPUSH_BEFORE=A,PUSH_AFTER=C--no-merges A..Cpush — new branch / empty / rewritten → unique commits only
--log-optsmainPUSH_BEFORE=0000…,PUSH_AFTER=E--no-merges B..Ebefore(now consistent)PUSH_BEFORE="",PUSH_AFTER=E--no-merges B..EPUSH_BEFORE=<missing>,PUSH_AFTER=E--no-merges B..EmaincommitPUSH_BEFORE=0000…,PUSH_AFTER=G--no-merges A..Gpush — fail-safe fallbacks (must be full scan, never empty)
--log-optsDEFAULT_BRANCH=does-not-existPUSH_AFTER=YPUSH_AFTER=C--no-merges C..C(empty range, correct)pull_request
--log-optsHEAD_SHA=E,PR_BASE_SHA=C--no-merges --first-parent B..EHEAD_SHA=<missing>other events → full scan
--log-optsworkflow_dispatchschedule(cron)Result: 12 / 12 passed.