diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index 459be998..dd460acd 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -105,8 +105,8 @@ jobs: EVENT: ${{ github.event_name }} PR_BASE: ${{ github.event.pull_request.base.sha }} PR_HEAD: ${{ github.event.pull_request.head.sha }} - PUSH_BEFORE: ${{ github.before }} - PUSH_AFTER: ${{ github.after }} + PUSH_BEFORE: ${{ github.event.before }} + PUSH_AFTER: ${{ github.event.after }} run: | set -euo pipefail gitleaks version @@ -116,7 +116,15 @@ jobs: range="${PR_BASE}..${PR_HEAD}" ;; push) - if [ -z "${PUSH_BEFORE:-}" ] || [ "$PUSH_BEFORE" = "0000000000000000000000000000000000000000" ]; then + # Both ends have to be real commits in this checkout. A branch + # deletion sends an all-zero "after", and a force-push can send a + # "before" that no ref reaches any more, so git log would exit 128 + # and the job would scan nothing. Either case scans full history. + zero="0000000000000000000000000000000000000000" + if [ -z "${PUSH_BEFORE:-}" ] || [ -z "${PUSH_AFTER:-}" ] \ + || [ "$PUSH_BEFORE" = "$zero" ] || [ "$PUSH_AFTER" = "$zero" ] \ + || ! git cat-file -e "${PUSH_BEFORE}^{commit}" 2>/dev/null \ + || ! git cat-file -e "${PUSH_AFTER}^{commit}" 2>/dev/null; then range="" else range="${PUSH_BEFORE}..${PUSH_AFTER}" @@ -128,6 +136,10 @@ jobs: ;; esac + if [ "$EVENT" = "push" ] && [ -z "$range" ]; then + echo "::warning::gitleaks is scanning FULL HISTORY on a push instead of the changed commit range. The before/after SHAs were empty, all-zero or unreachable (a branch deletion or a force-push) - check that PUSH_BEFORE/PUSH_AFTER use github.event.before / github.event.after, not github.before / github.after (those are not github-context properties, so they expand to empty and silently blind the scanner to new leaks)." + fi + report="${RUNNER_TEMP:-/tmp}/gitleaks-report.json" rm -f "$report"