@soleur/opencode 3.357.5 → 3.357.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/skills/review/SKILL.md
CHANGED
|
@@ -108,7 +108,7 @@ First, I need to determine the review target type and set up the code for analys
|
|
|
108
108
|
- [ ] Set up language-specific analysis tools
|
|
109
109
|
- [ ] Prepare security scanning environment
|
|
110
110
|
- [ ] Make sure we are on the branch we are reviewing. Use gh pr checkout to switch to the branch or manually checkout the branch.
|
|
111
|
-
- [ ] Push the branch
|
|
111
|
+
- [ ] Push the branch before spawning the panel (`git push -u origin $(git branch --show-current)`; agents read remote state [rf-before-spawning-review-agents-push-the]) after running ship's `prepush-secret-scan.sh` (Bash `timeout: 400000`; 0/43 continue, else STOP); `incr ci_cycles` after the push.
|
|
112
112
|
|
|
113
113
|
Ensure that the code is ready for analysis (either in worktree or on current branch). ONLY then proceed to the next step.
|
|
114
114
|
|
|
@@ -1067,6 +1067,7 @@ After emitting the marker, the calling skill's continuation gate takes over —
|
|
|
1067
1067
|
```bash
|
|
1068
1068
|
git add <changed files>
|
|
1069
1069
|
git commit -m "docs: review artifacts for feat-<name>"
|
|
1070
|
+
# ship's prepush-secret-scan.sh first
|
|
1070
1071
|
git push && bash "${CLAUDE_PLUGIN_ROOT}/scripts/pipeline-tally.sh" incr ci_cycles
|
|
1071
1072
|
```
|
|
1072
1073
|
|
package/skills/ship/SKILL.md
CHANGED
|
@@ -1621,9 +1621,9 @@ Run `echo 'SOLEUR_RULE_APPLIED rule=hr-technical-fork-is-not-an-operator-questio
|
|
|
1621
1621
|
|
|
1622
1622
|
[skill-enforced: ship Phase 6.4 + hook ship-unpushed-commits-gate.sh]
|
|
1623
1623
|
|
|
1624
|
-
Before queueing `gh pr merge --squash --auto` (Phase 6.5's CI Status Check below), verify every local commit is on `origin/<branch>`. GitHub's auto-merge consumes the PR head ref on origin — local-only commits are silently dropped from the squash.
|
|
1624
|
+
Before queueing `gh pr merge --squash --auto` (Phase 6.5's CI Status Check below), verify every local commit is on `origin/<branch>`. GitHub's auto-merge consumes the PR head ref on origin — local-only commits are silently dropped from the squash. (PR #3624 → #3627 → #3630: 2 of 5 commits never landed.)
|
|
1625
1625
|
|
|
1626
|
-
The PreToolUse hook [`.claude/hooks/ship-unpushed-commits-gate.sh`](../../../../.claude/hooks/ship-unpushed-commits-gate.sh) enforces this gate mechanically — it intercepts every `gh pr merge` (
|
|
1626
|
+
The PreToolUse hook [`.claude/hooks/ship-unpushed-commits-gate.sh`](../../../../.claude/hooks/ship-unpushed-commits-gate.sh) enforces this gate mechanically — it intercepts every `gh pr merge` (chained forms too) and denies the tool call when `git rev-list origin/<branch>..HEAD --count` returns > 0. The deny message lists the unpushed SHAs so the operator can `git push` and re-issue. Run the Phase 6 secret scan before the `git push` it asks for.
|
|
1627
1627
|
|
|
1628
1628
|
For headless or non-hooked contexts (CI workflows, direct shell invocations), run the equivalent check before `gh pr merge`:
|
|
1629
1629
|
|
|
@@ -1632,17 +1632,17 @@ BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
|
|
1632
1632
|
git fetch origin "$BRANCH" 2>/dev/null || true
|
|
1633
1633
|
UNPUSHED=$(git rev-list "origin/${BRANCH}..HEAD" --count 2>/dev/null || echo 0)
|
|
1634
1634
|
if [[ "$UNPUSHED" -gt 0 ]]; then
|
|
1635
|
-
echo "FAIL: ${UNPUSHED} unpushed commit(s) on origin/${BRANCH}. Run 'git push'." >&2
|
|
1635
|
+
echo "FAIL: ${UNPUSHED} unpushed commit(s) on origin/${BRANCH}. Run the Phase 6 secret scan, then 'git push'." >&2
|
|
1636
1636
|
git log "origin/${BRANCH}..HEAD" --oneline >&2
|
|
1637
1637
|
exit 1
|
|
1638
1638
|
fi
|
|
1639
1639
|
```
|
|
1640
1640
|
|
|
1641
|
-
**Fail-open conditions** (the hook exits silently): branch is `main`/`master`, detached HEAD, no upstream tracking ref, bare-repo context, branch name fails refname validation. **Fail-closed on fetch failure**
|
|
1641
|
+
**Fail-open conditions** (the hook exits silently): branch is `main`/`master`, detached HEAD, no upstream tracking ref, bare-repo context, branch name fails refname validation. **Fail-closed on fetch failure** (a stale ref hides the miss). See rule `wg-ship-push-before-merge` in `AGENTS.rules.md` for the canonical contract.
|
|
1642
1642
|
|
|
1643
|
-
**PUSHED IS NOT THE SAME AS FINISHED — BATCH EVERY FORESEEABLE COMMIT BEFORE QUEUEING `--auto`.** The gate above asks whether what you have is pushed; it cannot ask whether what you have is all you will need. Any commit you can foresee wanting — a late ADR, a review fix you already know is coming, a measurement you have not yet written down — belongs in the tree BEFORE `gh pr merge --squash --auto` is queued, and the place to do that work is the review-agent wait
|
|
1643
|
+
**PUSHED IS NOT THE SAME AS FINISHED — BATCH EVERY FORESEEABLE COMMIT BEFORE QUEUEING `--auto`.** The gate above asks whether what you have is pushed; it cannot ask whether what you have is all you will need. Any commit you can foresee wanting — a late ADR, a review fix you already know is coming, a measurement you have not yet written down — belongs in the tree BEFORE `gh pr merge --squash --auto` is queued, and the place to do that work is the review-agent wait. **Anything you land during that wait is outside the snapshot the reviewers read** (`rf-before-spawning-review-agents-push-the`: subagents analyse remote state at spawn time), so push it and re-cover it before you accept their findings. Pushing after `--auto` is queued resets the head ref and restarts the entire required-check set when the PR is one check from merging; the restarted cycle is gated by a single job that runs roughly 5-9x longer than any other (see [settle-then-admin-merge.md](${CLAUDE_PLUGIN_ROOT}/skills/ship/references/settle-then-admin-merge.md) for the measured figure and its derivation). **Why:** #7896 burned ~6 CI cycles (a late ADR commit at 65 of 67 checks).
|
|
1644
1644
|
|
|
1645
|
-
**Hook ordering
|
|
1645
|
+
**Hook ordering:** the gate is wired AFTER [`pre-merge-rebase.sh`](../../../../.claude/hooks/pre-merge-rebase.sh) in [`.claude/settings.json`](../../../../.claude/settings.json), so an auto-sync push has updated the tracking ref before this gate counts; `T11` in [`ship-unpushed-commits-gate.test.sh`](../../../../.claude/hooks/ship-unpushed-commits-gate.test.sh) enforces it.
|
|
1646
1646
|
|
|
1647
1647
|
## Phase 6: Push and Create PR
|
|
1648
1648
|
|
|
@@ -1734,6 +1734,8 @@ Abort Phase 6 if rc != 0. The gate mirrors reproducible CI: fast required jobs,
|
|
|
1734
1734
|
|
|
1735
1735
|
**Pipeline tally gate — BEFORE pushing (#9403):** `bash "${CLAUDE_PLUGIN_ROOT}/scripts/pipeline-tally.sh" init` (standalone ship writes no ledger otherwise), `gate ci_cycles` — `STOP` → `budget-capped` session-state write per the [render spec](${CLAUDE_PLUGIN_ROOT}/skills/ship/references/pipeline-tally-render.md) and exit; `WARN`/`UNKNOWN` → continue; `incr ci_cycles` after a successful push.
|
|
1736
1736
|
|
|
1737
|
+
**Secret scan — BEFORE every `git push` (also 6.45, 6.5, 7):** `bash "${CLAUDE_PLUGIN_ROOT}/skills/ship/scripts/prepush-secret-scan.sh"; echo "SCAN_RC=$?"`, Bash `timeout: 400000` ([contract](./scripts/prepush-secret-scan.sh)); 43 is not an error. 0 continue; 43 append the printed `secret-scan:` line to the PR body (re-add after any body rewrite), continue; else STOP (44: show the operator the reason; 127: plugin root unset, see Cloud Mode). Headless FINDINGS/44: abort, never rewrite history or edit the gitleaks config.
|
|
1738
|
+
|
|
1737
1739
|
Push the branch to remote. Get the branch name first:
|
|
1738
1740
|
|
|
1739
1741
|
```bash
|
|
@@ -2011,6 +2013,7 @@ bash "${CLAUDE_PLUGIN_ROOT}/skills/archive-kb/scripts/archive-kb.sh"
|
|
|
2011
2013
|
If it archives anything (`Archived N artifact(s)`), commit and push the move so it rides this PR — never a follow-up:
|
|
2012
2014
|
|
|
2013
2015
|
```bash
|
|
2016
|
+
# Phase 6 secret scan first
|
|
2014
2017
|
git add -A knowledge-base && git commit -m "chore(kb): archive <branch> artifacts at ship" && git push && bash "${CLAUDE_PLUGIN_ROOT}/scripts/pipeline-tally.sh" incr ci_cycles
|
|
2015
2018
|
```
|
|
2016
2019
|
|
|
@@ -2124,6 +2127,7 @@ retired both the driver and AC17.)
|
|
|
2124
2127
|
|
|
2125
2128
|
```bash
|
|
2126
2129
|
git merge --abort
|
|
2130
|
+
# Phase 6 secret scan first
|
|
2127
2131
|
bash "${CLAUDE_PLUGIN_ROOT}/scripts/resolve-regenerable-conflicts.sh" origin/main && git push \
|
|
2128
2132
|
&& bash "${CLAUDE_PLUGIN_ROOT}/scripts/pipeline-tally.sh" incr ci_cycles
|
|
2129
2133
|
```
|
|
@@ -2151,6 +2155,7 @@ retired both the driver and AC17.)
|
|
|
2151
2155
|
5. Push and re-verify:
|
|
2152
2156
|
|
|
2153
2157
|
```bash
|
|
2158
|
+
# Phase 6 secret scan first
|
|
2154
2159
|
git push && bash "${CLAUDE_PLUGIN_ROOT}/scripts/pipeline-tally.sh" incr ci_cycles
|
|
2155
2160
|
gh pr view --json mergeable | jq '.mergeable'
|
|
2156
2161
|
```
|
|
@@ -2565,6 +2570,7 @@ The agent maintains a `fix_attempt_count` counter (agent-level state, not a bash
|
|
|
2565
2570
|
a. If the failure is in tests or lint: invoke `skill: soleur:test-fix-loop` to diagnose, fix, and commit. After test-fix-loop completes, push and re-queue auto-merge:
|
|
2566
2571
|
|
|
2567
2572
|
```bash
|
|
2573
|
+
# Phase 6 secret scan first
|
|
2568
2574
|
git push && bash "${CLAUDE_PLUGIN_ROOT}/scripts/pipeline-tally.sh" incr ci_cycles
|
|
2569
2575
|
gh pr merge <number> --squash --auto
|
|
2570
2576
|
```
|
|
@@ -0,0 +1,520 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# prepush-secret-scan.sh — local per-commit secret scan over the commits a push would publish.
|
|
3
|
+
#
|
|
4
|
+
# WHAT. Runs `gitleaks git` over `origin/main..HEAD` (non-merge commits, the range shape of the CI
|
|
5
|
+
# range arm in .github/workflows/secret-scan.yml, plus `--text`) BEFORE `git push`, so a secret-bearing
|
|
6
|
+
# commit is caught while its history is still local and fixable by rewriting an unpublished commit.
|
|
7
|
+
# CI cannot do that job: its scan starts at the PR, after the push, and a pushed SHA stays reachable
|
|
8
|
+
# (refs/pull/N/head) even after a force-push. A published secret cannot be cleared by a later "fix"
|
|
9
|
+
# commit either: the range scan reads every commit in the range, not the tip. Called by prose from
|
|
10
|
+
# `soleur:ship` before each of its pushes and from the review skill's pushes; the hook-level
|
|
11
|
+
# chokepoint (a git `pre-push`) is tracked in #11126.
|
|
12
|
+
#
|
|
13
|
+
# USAGE. prepush-secret-scan.sh [--base REF] [--no-fetch]
|
|
14
|
+
# --base REF range base (default refs/remotes/origin/main). A SELECTOR, not a skip switch:
|
|
15
|
+
# `--base HEAD` yields range=0. Must match ^[A-Za-z0-9._/-]+$ and not start with `-`;
|
|
16
|
+
# it is resolved to a full commit SHA and ONLY that SHA reaches --log-opts.
|
|
17
|
+
# --no-fetch skip the best-effort `git fetch origin main` (offline probes, tests).
|
|
18
|
+
# No environment variable or file skips the scan. The only env knob is
|
|
19
|
+
# SOLEUR_PREPUSH_SCAN_TIMEOUT (integer seconds, 1..600, default 240; anything else falls back), and
|
|
20
|
+
# an expired bound is a STOP (44), never a skip. Worst case ~340s: run it with a Bash timeout of 400s.
|
|
21
|
+
#
|
|
22
|
+
# EXIT CONTRACT (the caller branches on this; ONLY 0 and 43 continue):
|
|
23
|
+
# 0 CLEAN — rc 0 from gitleaks, a report of exactly `[]`, and no scan-error output.
|
|
24
|
+
# 1 FINDINGS — STOP. Also what a `set -u` abort produces, which is the safe direction.
|
|
25
|
+
# 43 NOT_RUN — the scan could not be attempted because the ENVIRONMENT lacks something (no
|
|
26
|
+
# gitleaks, no work tree, no tmpdir, unresolvable base, a shallow clone, no
|
|
27
|
+
# committed .gitleaks.toml). Record `secret-scan: not run (<reason>)` in the PR
|
|
28
|
+
# body and continue; CI's secret-scan.yml still gates the merge (not the publication).
|
|
29
|
+
# 44 INCOMPLETE — STOP, the operator decides (headless: abort like FINDINGS). The scan ran or was
|
|
30
|
+
# attempted and the range was NOT verified clean: timeout/OOM, rc >= 2, an empty
|
|
31
|
+
# report, a scanned-count mismatch, `ERR`/`fatal:` in an rc-0 scan (an unreadable
|
|
32
|
+
# object), an unreadable range, or no merge base in a non-shallow repo. Each of
|
|
33
|
+
# these can be induced by the PR's own content, so none may read as "continue".
|
|
34
|
+
# Any unexpected verdict also lands here.
|
|
35
|
+
# any other value is a STOP too, including 127 (script not found: CLAUDE_PLUGIN_ROOT unset) and 64
|
|
36
|
+
# (bad arguments). 43/44 are outside every status bash produces by accident (1 generic/`set -u`,
|
|
37
|
+
# 2 syntax, 126/127, 128+N), the reasoning of battery-owed.sh's 42.
|
|
38
|
+
#
|
|
39
|
+
# RECEIPT (stdout; the last line bar the NOT_RUN line below):
|
|
40
|
+
# PREPUSH_SECRET_SCAN verdict=<CLEAN|FINDINGS|NOT_RUN|INCOMPLETE> base=<sha|none> head=<sha|none>
|
|
41
|
+
# fetch=<ok|stale|skipped> range=<N> scanned=<M|?> cfg_changed=<0|1> cfg=<base|none>
|
|
42
|
+
# published=<0|1|?> attr=<pinned|unpinned> gitleaks=<ver|none> reason=<token>
|
|
43
|
+
# On NOT_RUN a final `secret-scan: not run (<reason>)` line follows: that is the PR-body line.
|
|
44
|
+
# `scanned` is read best-effort from gitleaks' `N commits scanned.` line and cross-checked only
|
|
45
|
+
# when it parses (a parse miss leaves `scanned=?` and does not block CLEAN, so output-format
|
|
46
|
+
# drift cannot turn every run into INCOMPLETE). Findings print commit/file/line/rule id on stderr,
|
|
47
|
+
# never the secret, the `Match` text or raw gitleaks output (which carries author emails).
|
|
48
|
+
#
|
|
49
|
+
# WHAT THE SCAN READS. The BASE's committed .gitleaks.toml and .gitleaksignore (cfg=base), never the
|
|
50
|
+
# working tree's and never the PR's, and never HEAD's when the base has none (that is NOT_RUN): a PR
|
|
51
|
+
# that widens, breaks or deletes its own config cannot scan itself clean. gitleaks is pointed at the
|
|
52
|
+
# repository's git dir, not the work tree, so a checked-out .gitleaksignore is not read either. A
|
|
53
|
+
# legitimate allowlist-adding PR therefore gets FINDINGS here; CI's `allowlist-diff` job (label or
|
|
54
|
+
# `Allowlist-Widened-By:` trailer) is the arbiter. `cfg_changed=1` says the range touches the config,
|
|
55
|
+
# .gitleaksignore or a root .gitattributes. An inline `gitleaks:allow` comment added by the PR is
|
|
56
|
+
# still honoured, exactly as in CI. gitleaks runs with GIT_ATTR_SOURCE=<empty tree>, `--text`, and the
|
|
57
|
+
# global/system git config replaced, so committed `-diff`/`binary` attributes, NUL-byte files and a
|
|
58
|
+
# user's diff.* settings cannot blind it (`--text` alone already defeats `.git/info/attributes`).
|
|
59
|
+
#
|
|
60
|
+
# LIMITATIONS (measured, documented rather than claimed away; CI's `gitleaks dir .` is the net):
|
|
61
|
+
# - Merge commits: `--no-merges` mirrors CI's range arm and misses content that exists ONLY in a
|
|
62
|
+
# conflict-resolution merge commit (rc 0; `-m` and `gitleaks dir` find it). A tip-tree scan
|
|
63
|
+
# belongs to #11126.
|
|
64
|
+
# - UTF-16 files are invisible here and to CI. git < 2.40 prints attr=unpinned (GIT_ATTR_SOURCE is
|
|
65
|
+
# ignored there; `--text` still holds).
|
|
66
|
+
# - An empty or unparseable base config, or a symlinked one, is NOT_RUN/INCOMPLETE, never a fallback.
|
|
67
|
+
# - Version skew: CI pins gitleaks 8.24.2. A newer local rule pack can flag what CI accepts; that
|
|
68
|
+
# is still a STOP (conservative) and the receipt prints the local version.
|
|
69
|
+
# - Shallow clones with no merge base are NOT_RUN `no-merge-base`: scanning a truncated history
|
|
70
|
+
# would attribute other commits to this PR.
|
|
71
|
+
# - A push made by another script (pre-merge-rebase.sh, sync-pr-behind.sh) never reaches this
|
|
72
|
+
# scan: only a git `pre-push` hook can see it (#11126).
|
|
73
|
+
#
|
|
74
|
+
# REMEDY: printed with FINDINGS, branched on whether a finding commit is already on origin; headless
|
|
75
|
+
# ship aborts and never rewrites history unasked, never edits .gitleaks.toml/.gitleaksignore, never
|
|
76
|
+
# adds an inline allow.
|
|
77
|
+
|
|
78
|
+
set -uo pipefail
|
|
79
|
+
|
|
80
|
+
# Drop empty and relative PATH entries first: `:/bin` or `./bin` would run a repo-local git, timeout,
|
|
81
|
+
# jq or env as the operator.
|
|
82
|
+
IFS=: read -ra _pe <<<"${PATH:-}"
|
|
83
|
+
_np=""
|
|
84
|
+
for _e in ${_pe[@]+"${_pe[@]}"}; do
|
|
85
|
+
case "$_e" in /*) _np="${_np:+$_np:}$_e" ;; esac
|
|
86
|
+
done
|
|
87
|
+
[ -n "$_np" ] || _np=/usr/bin:/bin # an empty PATH would make bash search the current directory
|
|
88
|
+
PATH=$_np
|
|
89
|
+
export PATH
|
|
90
|
+
|
|
91
|
+
# drop_repo_paths <physical root> — remove every absolute PATH entry that lives inside the repository
|
|
92
|
+
# (direnv PATH_add, node_modules/.bin): a PR could put a git, timeout, jq, env or gitleaks there, and the
|
|
93
|
+
# first match wins, so the entry is filtered, not skipped. Builtins only (`cd -P`, `pwd -P`).
|
|
94
|
+
drop_repo_paths() {
|
|
95
|
+
local root=$1 e ed np=""
|
|
96
|
+
local -a pe
|
|
97
|
+
[ "$root" != / ] || return 0
|
|
98
|
+
IFS=: read -ra pe <<<"$PATH"
|
|
99
|
+
for e in ${pe[@]+"${pe[@]}"}; do
|
|
100
|
+
ed=$(cd -P "$e" 2>/dev/null && pwd -P) || ed=""
|
|
101
|
+
case "$ed/" in "$root"/*) continue ;; esac
|
|
102
|
+
np="${np:+$np:}$e"
|
|
103
|
+
done
|
|
104
|
+
[ -n "$np" ] || np=/usr/bin:/bin
|
|
105
|
+
PATH=$np
|
|
106
|
+
export PATH
|
|
107
|
+
hash -r
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
BASE_REF="refs/remotes/origin/main"
|
|
111
|
+
DO_FETCH=1
|
|
112
|
+
|
|
113
|
+
R_BASE=none
|
|
114
|
+
R_HEAD=none
|
|
115
|
+
R_FETCH=skipped
|
|
116
|
+
R_RANGE=0
|
|
117
|
+
R_SCANNED='?'
|
|
118
|
+
R_CFG=0
|
|
119
|
+
R_CFGSRC=none
|
|
120
|
+
R_PUB='?'
|
|
121
|
+
R_ATTR=unpinned
|
|
122
|
+
R_GL=none
|
|
123
|
+
|
|
124
|
+
TMP=""
|
|
125
|
+
# shellcheck disable=SC2329 # invoked through the EXIT trap
|
|
126
|
+
cleanup() {
|
|
127
|
+
[[ -n "${TMP:-}" ]] || return 0
|
|
128
|
+
rm -rf "${TMP:?}"
|
|
129
|
+
}
|
|
130
|
+
trap cleanup EXIT
|
|
131
|
+
|
|
132
|
+
usage_die() {
|
|
133
|
+
printf 'usage: prepush-secret-scan.sh [--base REF] [--no-fetch]\n' >&2
|
|
134
|
+
exit 64
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
# finish <CLEAN|FINDINGS|NOT_RUN|INCOMPLETE> <reason-token> — prints the receipt and exits. The only
|
|
138
|
+
# exit path for a verdict; the explicit `exit "$final_rc"` is the contract (never an implicit status).
|
|
139
|
+
# The default arm is a STOP: a mistyped or new verdict must never read as "continue".
|
|
140
|
+
finish() {
|
|
141
|
+
local verdict=$1 reason=$2 final_rc
|
|
142
|
+
case "$verdict" in
|
|
143
|
+
CLEAN) final_rc=0 ;;
|
|
144
|
+
FINDINGS) final_rc=1 ;;
|
|
145
|
+
NOT_RUN) final_rc=43 ;;
|
|
146
|
+
*) final_rc=44 ;;
|
|
147
|
+
esac
|
|
148
|
+
printf 'PREPUSH_SECRET_SCAN verdict=%s base=%s head=%s fetch=%s range=%s scanned=%s cfg_changed=%s cfg=%s published=%s attr=%s gitleaks=%s reason=%s\n' \
|
|
149
|
+
"$verdict" "$R_BASE" "$R_HEAD" "$R_FETCH" "$R_RANGE" "$R_SCANNED" "$R_CFG" "$R_CFGSRC" "$R_PUB" "$R_ATTR" "$R_GL" "$reason"
|
|
150
|
+
# The verdict covers the HEAD it printed, not whatever HEAD is when the push runs (a version-bump or
|
|
151
|
+
# review-fix commit in between would go unscanned); a git pre-push hook that sees the pushed SHAs is #11126.
|
|
152
|
+
if [ "$final_rc" -eq 0 ] || [ "$final_rc" -eq 43 ]; then
|
|
153
|
+
printf 'NOTE: this verdict covers head=%s; run the scan again if HEAD moves before you push.\n' "$R_HEAD" >&2
|
|
154
|
+
fi
|
|
155
|
+
if [ "$verdict" = NOT_RUN ]; then
|
|
156
|
+
printf 'WARN: secret-scan NOT RUN (%s): the commits were not scanned locally; CI secret-scan.yml gates the merge, not the publication. This is the sanctioned continue path: put the secret-scan: line below in the PR body; do not retry or install anything.\n' "$reason" >&2
|
|
157
|
+
printf 'secret-scan: not run (%s)\n' "$reason"
|
|
158
|
+
elif [ "$final_rc" -eq 44 ]; then
|
|
159
|
+
printf 'STOP: secret-scan INCOMPLETE (%s): the range was NOT verified clean. Do not push; show the operator this reason (headless: abort like FINDINGS). The operator may push explicitly, never silently.\n' "$reason" >&2
|
|
160
|
+
fi
|
|
161
|
+
exit "$final_rc"
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
# san <string> <max-len> — ASCII allowlist for every printed field that comes from PR content or a
|
|
165
|
+
# possibly hostile toml: ANSI escapes, newlines and prompt-injection text must not reach the transcript.
|
|
166
|
+
san() {
|
|
167
|
+
printf '%s' "$1" | LC_ALL=C tr -cd '[:alnum:]._/@+=-' | LC_ALL=C cut -c1-"$2"
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
while [ "$#" -gt 0 ]; do
|
|
171
|
+
case "$1" in
|
|
172
|
+
--base)
|
|
173
|
+
[ "$#" -ge 2 ] || usage_die
|
|
174
|
+
BASE_REF=$2
|
|
175
|
+
shift 2
|
|
176
|
+
;;
|
|
177
|
+
--no-fetch)
|
|
178
|
+
DO_FETCH=0
|
|
179
|
+
shift
|
|
180
|
+
;;
|
|
181
|
+
*) usage_die ;;
|
|
182
|
+
esac
|
|
183
|
+
done
|
|
184
|
+
|
|
185
|
+
# ── 1. hardening: nothing ambient may redirect git or gitleaks ────────────────────────────────
|
|
186
|
+
unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE GIT_COMMON_DIR GIT_OBJECT_DIRECTORY \
|
|
187
|
+
GIT_ALTERNATE_OBJECT_DIRECTORIES GIT_NAMESPACE GIT_TEMPLATE_DIR GIT_EXEC_PATH \
|
|
188
|
+
GIT_EXTERNAL_DIFF GIT_REPLACE_REF_BASE GIT_DIFF_OPTS GIT_PAGER
|
|
189
|
+
for _v in $(compgen -e GITLEAKS_); do
|
|
190
|
+
unset "$_v"
|
|
191
|
+
done
|
|
192
|
+
export GIT_NO_REPLACE_OBJECTS=1 GIT_TERMINAL_PROMPT=0 GIT_CONFIG_NOSYSTEM=1 GIT_ATTR_NOSYSTEM=1
|
|
193
|
+
|
|
194
|
+
# Nothing external may run before the PATH is clean, so the repository root is found with builtins only:
|
|
195
|
+
# the nearest ancestor holding a `.git` (a file for worktrees and submodules, a directory otherwise).
|
|
196
|
+
_root=$(pwd -P)
|
|
197
|
+
_d=$_root
|
|
198
|
+
while :; do
|
|
199
|
+
if [ -e "$_d/.git" ]; then
|
|
200
|
+
_root=$_d
|
|
201
|
+
break
|
|
202
|
+
fi
|
|
203
|
+
[ "$_d" != / ] || break
|
|
204
|
+
_d=${_d%/*}
|
|
205
|
+
[ -n "$_d" ] || _d=/
|
|
206
|
+
done
|
|
207
|
+
drop_repo_paths "$_root" # mut:earlyfilter
|
|
208
|
+
_cwd=$(pwd -P)
|
|
209
|
+
[ "$_cwd" = "$_root" ] || drop_repo_paths "$_cwd"
|
|
210
|
+
|
|
211
|
+
[ -n "$(type -P git 2>/dev/null)" ] || finish NOT_RUN not-a-work-tree
|
|
212
|
+
TOP=$(git rev-parse --show-toplevel 2>/dev/null) || TOP=""
|
|
213
|
+
[ -n "$TOP" ] || finish NOT_RUN not-a-work-tree
|
|
214
|
+
TOPREAL=$(cd -P "$TOP" 2>/dev/null && pwd -P) || TOPREAL=$TOP
|
|
215
|
+
drop_repo_paths "$TOPREAL"
|
|
216
|
+
|
|
217
|
+
umask 077
|
|
218
|
+
TMP=$(mktemp -d 2>/dev/null) || finish NOT_RUN tmpdir-unavailable
|
|
219
|
+
|
|
220
|
+
TO_CMD=()
|
|
221
|
+
if command -v timeout >/dev/null 2>&1; then
|
|
222
|
+
TO_CMD=(timeout)
|
|
223
|
+
elif command -v gtimeout >/dev/null 2>&1; then
|
|
224
|
+
TO_CMD=(gtimeout)
|
|
225
|
+
fi
|
|
226
|
+
|
|
227
|
+
# bounded <seconds> cmd... — exec-boundary deadline. A host with neither timeout nor gtimeout (stock
|
|
228
|
+
# macOS) runs unbounded rather than misreporting a runnable gitleaks as broken.
|
|
229
|
+
bounded() {
|
|
230
|
+
local n=$1
|
|
231
|
+
shift
|
|
232
|
+
if [ "${#TO_CMD[@]}" -gt 0 ]; then
|
|
233
|
+
"${TO_CMD[0]}" -k 5 "$n" "$@"
|
|
234
|
+
else
|
|
235
|
+
"$@"
|
|
236
|
+
fi
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
SCAN_T=240
|
|
240
|
+
case "${SOLEUR_PREPUSH_SCAN_TIMEOUT:-}" in
|
|
241
|
+
'' | *[!0-9]*) ;;
|
|
242
|
+
*)
|
|
243
|
+
if [ "${#SOLEUR_PREPUSH_SCAN_TIMEOUT}" -le 3 ] && [ "$SOLEUR_PREPUSH_SCAN_TIMEOUT" -ge 1 ] && [ "$SOLEUR_PREPUSH_SCAN_TIMEOUT" -le 600 ]; then
|
|
244
|
+
SCAN_T=$SOLEUR_PREPUSH_SCAN_TIMEOUT
|
|
245
|
+
fi
|
|
246
|
+
;;
|
|
247
|
+
esac
|
|
248
|
+
|
|
249
|
+
# ── 2. preconditions, each a NOT_RUN with a named reason ──────────────────────────────────────
|
|
250
|
+
GL=$(type -P gitleaks 2>/dev/null) || GL=""
|
|
251
|
+
[ -n "$GL" ] || finish NOT_RUN gitleaks-absent
|
|
252
|
+
|
|
253
|
+
# Resolve symlinks to the real file ONLY to refuse one that lives inside the repo (a PR-controlled
|
|
254
|
+
# shim would run attacker code under this script's identity). The program that RUNS is $GL as found:
|
|
255
|
+
# a version-manager shim is a symlink to a multi-call binary that picks the tool from argv[0], so
|
|
256
|
+
# executing the resolved target runs a different program.
|
|
257
|
+
_p=$GL
|
|
258
|
+
_hops=0
|
|
259
|
+
while [ -L "$_p" ]; do
|
|
260
|
+
_hops=$((_hops + 1))
|
|
261
|
+
[ "$_hops" -le 40 ] || finish NOT_RUN gitleaks-unrunnable
|
|
262
|
+
_t=$(readlink "$_p")
|
|
263
|
+
case "$_t" in
|
|
264
|
+
/*) _p=$_t ;;
|
|
265
|
+
*) _p="$(dirname "$_p")/$_t" ;;
|
|
266
|
+
esac
|
|
267
|
+
done
|
|
268
|
+
_d=$(cd -P "$(dirname "$_p")" 2>/dev/null && pwd -P) || _d=""
|
|
269
|
+
[ -n "$_d" ] || finish NOT_RUN gitleaks-unrunnable
|
|
270
|
+
GLREAL="$_d/$(basename "$_p")"
|
|
271
|
+
case "$GLREAL" in
|
|
272
|
+
"$TOPREAL"/* | "$TOP"/*) finish NOT_RUN gitleaks-in-repo ;;
|
|
273
|
+
esac
|
|
274
|
+
|
|
275
|
+
# Probe by RUNNING it, from a neutral cwd: `command -v` alone certifies an unpinned version-manager
|
|
276
|
+
# shim that resolves and exits non-zero. A bound expiry (124/137) is a load condition, not a broken
|
|
277
|
+
# install, so it gets one wider retry before it is called a timeout.
|
|
278
|
+
GLVER=$(cd / && bounded 10 "$GL" version 2>/dev/null </dev/null)
|
|
279
|
+
prc=$?
|
|
280
|
+
if [ "$prc" -eq 124 ] || [ "$prc" -eq 137 ]; then
|
|
281
|
+
GLVER=$(cd / && bounded 60 "$GL" version 2>/dev/null </dev/null)
|
|
282
|
+
prc=$?
|
|
283
|
+
if [ "$prc" -eq 124 ] || [ "$prc" -eq 137 ]; then
|
|
284
|
+
finish INCOMPLETE timeout
|
|
285
|
+
fi
|
|
286
|
+
fi
|
|
287
|
+
[ "$prc" -eq 0 ] || finish NOT_RUN gitleaks-unrunnable
|
|
288
|
+
R_GL=$(printf '%s' "$GLVER" | sed -n '1p' | tr -cd '[:alnum:].-' | cut -c1-24)
|
|
289
|
+
[ -n "$R_GL" ] || R_GL=unknown
|
|
290
|
+
|
|
291
|
+
# GIT_ATTR_SOURCE needs git >= 2.40; an older git ignores it and the receipt says so.
|
|
292
|
+
read -r _gmaj _gmin <<<"$(git --version 2>/dev/null | sed -En 's/^git version ([0-9]+)\.([0-9]+).*/\1 \2/p')"
|
|
293
|
+
if [[ "${_gmaj:-}" =~ ^[0-9]+$ ]] && [[ "${_gmin:-}" =~ ^[0-9]+$ ]]; then
|
|
294
|
+
if [ "$_gmaj" -gt 2 ] || { [ "$_gmaj" -eq 2 ] && [ "$_gmin" -ge 40 ]; }; then R_ATTR=pinned; fi
|
|
295
|
+
fi
|
|
296
|
+
|
|
297
|
+
# ── 3. refresh (best effort) ──────────────────────────────────────────────────────────────────
|
|
298
|
+
# A stale base can only WIDEN the range (over-scan), so a failed fetch is a state, not a failure.
|
|
299
|
+
# A locally advanced refs/remotes/origin/main (update-ref, branch -f) narrows it, which is why the
|
|
300
|
+
# receipt prints both SHAs unabbreviated. The explicit refspec also works in a single-branch clone,
|
|
301
|
+
# where a bare `git fetch origin main` leaves refs/remotes/origin/main untouched.
|
|
302
|
+
if [ "$DO_FETCH" -eq 1 ]; then
|
|
303
|
+
if (cd "$TOP" && bounded 10 git fetch --no-tags -q origin '+refs/heads/main:refs/remotes/origin/main') </dev/null >/dev/null 2>&1; then
|
|
304
|
+
R_FETCH=ok
|
|
305
|
+
else
|
|
306
|
+
R_FETCH=stale
|
|
307
|
+
fi
|
|
308
|
+
fi
|
|
309
|
+
|
|
310
|
+
# ── 4. range ──────────────────────────────────────────────────────────────────────────────────
|
|
311
|
+
case "$BASE_REF" in
|
|
312
|
+
-* | '') finish NOT_RUN base-unresolvable ;;
|
|
313
|
+
esac
|
|
314
|
+
[[ "$BASE_REF" =~ ^[A-Za-z0-9._/-]+$ ]] || finish NOT_RUN base-unresolvable # mut:baseregex
|
|
315
|
+
BASE_SHA=$(cd "$TOP" && git rev-parse --verify --quiet --end-of-options "${BASE_REF}^{commit}" 2>/dev/null) || BASE_SHA=""
|
|
316
|
+
HEAD_SHA=$(cd "$TOP" && git rev-parse --verify --quiet --end-of-options "HEAD^{commit}" 2>/dev/null) || HEAD_SHA=""
|
|
317
|
+
[[ "$BASE_SHA" =~ ^[0-9a-f]{40,64}$ ]] || finish NOT_RUN base-unresolvable
|
|
318
|
+
[[ "$HEAD_SHA" =~ ^[0-9a-f]{40,64}$ ]] || finish NOT_RUN head-unresolvable
|
|
319
|
+
R_BASE=$BASE_SHA
|
|
320
|
+
R_HEAD=$HEAD_SHA
|
|
321
|
+
|
|
322
|
+
# An unresolvable ref makes `gitleaks git` exit 0 with an empty report (measured), so the checks
|
|
323
|
+
# above are load-bearing. No merge base means an over-scan of main's history would be attributed to
|
|
324
|
+
# this PR: environmental in a shallow clone, but in a full clone it is an orphan or unrelated
|
|
325
|
+
# branch, which a PR can create on purpose, so that is a STOP.
|
|
326
|
+
if ! (cd "$TOP" && git merge-base "$BASE_SHA" "$HEAD_SHA") >/dev/null 2>&1; then
|
|
327
|
+
if [ "$(cd "$TOP" && git rev-parse --is-shallow-repository 2>/dev/null)" = true ]; then
|
|
328
|
+
finish NOT_RUN no-merge-base
|
|
329
|
+
fi
|
|
330
|
+
finish INCOMPLETE no-merge-base
|
|
331
|
+
fi
|
|
332
|
+
|
|
333
|
+
N=$(cd "$TOP" && git rev-list --count --no-merges "$BASE_SHA..$HEAD_SHA" 2>/dev/null) || N=""
|
|
334
|
+
[[ "$N" =~ ^[0-9]+$ ]] || finish INCOMPLETE range-unreadable
|
|
335
|
+
R_RANGE=$N
|
|
336
|
+
# E=1 means at least one commit in range ADDS lines: gitleaks reads added lines only, so a range of
|
|
337
|
+
# pure renames, deletions, mode changes or empty files legitimately scans 0 commits.
|
|
338
|
+
E=""
|
|
339
|
+
if (cd "$TOP" && git log --no-merges --format= --numstat --text "$BASE_SHA..$HEAD_SHA" 2>/dev/null) | awk '$1 ~ /^[0-9]+$/ && $1 > 0 { f = 1 } END { exit !f }'; then
|
|
340
|
+
E=1
|
|
341
|
+
fi
|
|
342
|
+
CFG=$(cd "$TOP" && git diff --name-only "$BASE_SHA...$HEAD_SHA" -- .gitleaks.toml .gitleaksignore .gitattributes 2>/dev/null)
|
|
343
|
+
[ -z "$CFG" ] || R_CFG=1
|
|
344
|
+
|
|
345
|
+
# published=1 when part of the range is already on origin/<branch>: the remedy then starts with
|
|
346
|
+
# rotation, because a rewrite does not unpublish anything.
|
|
347
|
+
BR=$(cd "$TOP" && git symbolic-ref --quiet --short HEAD 2>/dev/null) || BR=""
|
|
348
|
+
RB=""
|
|
349
|
+
if [ -n "$BR" ] && [[ "$BR" =~ ^[A-Za-z0-9._/+@-]+$ ]]; then
|
|
350
|
+
if RB=$(cd "$TOP" && git rev-parse --verify --quiet --end-of-options "refs/remotes/origin/${BR}^{commit}" 2>/dev/null); then
|
|
351
|
+
U=$(cd "$TOP" && git rev-list --count --no-merges "$BASE_SHA..$HEAD_SHA" "^$RB" 2>/dev/null) || U=""
|
|
352
|
+
if [[ "$U" =~ ^[0-9]+$ ]]; then
|
|
353
|
+
if [ "$U" -lt "$N" ]; then R_PUB=1; else R_PUB=0; fi
|
|
354
|
+
fi
|
|
355
|
+
else
|
|
356
|
+
R_PUB=0
|
|
357
|
+
fi
|
|
358
|
+
fi
|
|
359
|
+
|
|
360
|
+
# The config the scan reads is the BASE's committed one and nothing else: a base without a usable
|
|
361
|
+
# config is NOT_RUN, never a fallback to HEAD's (the PR could ship its own allowlist).
|
|
362
|
+
if ! (cd "$TOP" && git show "$BASE_SHA:.gitleaks.toml") >"$TMP/gitleaks.toml" 2>/dev/null || [ ! -s "$TMP/gitleaks.toml" ]; then
|
|
363
|
+
finish NOT_RUN gitleaks-toml-absent
|
|
364
|
+
fi
|
|
365
|
+
R_CFGSRC="base"
|
|
366
|
+
(cd "$TOP" && git show "$BASE_SHA:.gitleaksignore") >"$TMP/gitleaksignore" 2>/dev/null || : >"$TMP/gitleaksignore"
|
|
367
|
+
|
|
368
|
+
if [ "$N" -eq 0 ]; then
|
|
369
|
+
R_SCANNED=0
|
|
370
|
+
finish CLEAN empty-range
|
|
371
|
+
fi
|
|
372
|
+
|
|
373
|
+
# ── 5. scan ───────────────────────────────────────────────────────────────────────────────────
|
|
374
|
+
# Every git setting that changes what the patch stream shows is pinned on BOTH surfaces:
|
|
375
|
+
# GIT_CONFIG_PARAMETERS is read AFTER the GIT_CONFIG_COUNT list and beats it, so a count-only pin
|
|
376
|
+
# loses to `git -c color.diff=always` in the caller's environment, and a coloured patch hides `+`
|
|
377
|
+
# lines from gitleaks. We APPEND to whatever the caller exported. Prefix and attribute settings
|
|
378
|
+
# matter as much as colour: diff.noprefix drops the first path component and defeats the toml's
|
|
379
|
+
# path allowlists.
|
|
380
|
+
# The empty tree of THIS repository's object format (SHA-1 or SHA-256).
|
|
381
|
+
EMPTY_TREE=$(cd "$TOP" && git hash-object -t tree /dev/null 2>/dev/null)
|
|
382
|
+
[[ "$EMPTY_TREE" =~ ^[0-9a-f]{40,64}$ ]] || EMPTY_TREE=4b825dc642cb6eb9a060e54bf8d69288fbee4904
|
|
383
|
+
# gitleaks scans the git DIR, not the work tree: it reads a checked-out .gitleaksignore from the
|
|
384
|
+
# source it is pointed at, and the PR controls the work tree.
|
|
385
|
+
GITCOMMON=$(cd "$TOP" && gd=$(git rev-parse --git-common-dir 2>/dev/null) && cd "$gd" 2>/dev/null && pwd -P) || GITCOMMON=""
|
|
386
|
+
[ -n "$GITCOMMON" ] || finish INCOMPLETE range-unreadable
|
|
387
|
+
GL_PINS=(color.ui=never color.diff=never diff.noprefix=false diff.mnemonicPrefix=false diff.srcPrefix=a/ diff.dstPrefix=b/ core.attributesFile=/dev/null)
|
|
388
|
+
gl_cfg_n="${GIT_CONFIG_COUNT:-0}"
|
|
389
|
+
case "$gl_cfg_n" in '' | *[!0-9]*) gl_cfg_n=0 ;; esac
|
|
390
|
+
gl_cfg_n=$((10#$gl_cfg_n))
|
|
391
|
+
gl_params="${GIT_CONFIG_PARAMETERS:-}"
|
|
392
|
+
GLENV=(env)
|
|
393
|
+
for _i in "${!GL_PINS[@]}"; do
|
|
394
|
+
_k=${GL_PINS[$_i]%%=*}
|
|
395
|
+
_val=${GL_PINS[$_i]#*=}
|
|
396
|
+
GLENV+=("GIT_CONFIG_KEY_$((gl_cfg_n + _i))=$_k" "GIT_CONFIG_VALUE_$((gl_cfg_n + _i))=$_val")
|
|
397
|
+
gl_params="${gl_params:+$gl_params }'$_k'='$_val'"
|
|
398
|
+
done
|
|
399
|
+
GLENV+=(
|
|
400
|
+
"GIT_CONFIG_COUNT=$((gl_cfg_n + ${#GL_PINS[@]}))" # mut:colorcount
|
|
401
|
+
"GIT_CONFIG_PARAMETERS=$gl_params" # mut:colorparams
|
|
402
|
+
"GIT_ATTR_SOURCE=$EMPTY_TREE"
|
|
403
|
+
GIT_CONFIG_GLOBAL=/dev/null
|
|
404
|
+
GIT_CONFIG_SYSTEM=/dev/null
|
|
405
|
+
)
|
|
406
|
+
|
|
407
|
+
# stdout and stderr are captured to $TMP and never echoed: raw gitleaks output carries author emails.
|
|
408
|
+
(
|
|
409
|
+
cd "$TOP" &&
|
|
410
|
+
bounded "$SCAN_T" "${GLENV[@]}" \
|
|
411
|
+
"$GL" git \
|
|
412
|
+
--redact \
|
|
413
|
+
--no-banner \
|
|
414
|
+
--exit-code 1 \
|
|
415
|
+
--config "$TMP/gitleaks.toml" \
|
|
416
|
+
--gitleaks-ignore-path "$TMP/gitleaksignore" \
|
|
417
|
+
--report-format json \
|
|
418
|
+
--report-path "$TMP/report.json" \
|
|
419
|
+
"$GITCOMMON" \
|
|
420
|
+
--log-opts="--no-merges --text ${BASE_SHA}..${HEAD_SHA}" # mut:range
|
|
421
|
+
) </dev/null >"$TMP/out" 2>"$TMP/err"
|
|
422
|
+
scan_rc=$?
|
|
423
|
+
|
|
424
|
+
# ── 6. verdict. The ORDER is part of the contract. ─────────────────────────────────────────────
|
|
425
|
+
if [ "$scan_rc" -eq 124 ] || [ "$scan_rc" -eq 137 ]; then
|
|
426
|
+
finish INCOMPLETE timeout
|
|
427
|
+
fi
|
|
428
|
+
# A missing or zero-byte report is evaluated BEFORE any content branch, so rc 0 with no report can
|
|
429
|
+
# never reach CLEAN.
|
|
430
|
+
if [ ! -s "$TMP/report.json" ]; then
|
|
431
|
+
finish INCOMPLETE empty-report # mut:emptyreport
|
|
432
|
+
fi
|
|
433
|
+
REPORT=$(tr -d ' \t\r\n' <"$TMP/report.json")
|
|
434
|
+
|
|
435
|
+
# Best-effort count of commits gitleaks says it read (anchored; the last match wins).
|
|
436
|
+
SCANNED=$(cat "$TMP/out" "$TMP/err" 2>/dev/null | sed -En -e 's/^([0-9]+) commits? scanned.*$/\1/p' -e 's/^.*[^0-9]([0-9]+) commits? scanned.*$/\1/p' | tail -n 1)
|
|
437
|
+
if [[ "$SCANNED" =~ ^[0-9]+$ ]]; then
|
|
438
|
+
R_SCANNED=$SCANNED
|
|
439
|
+
fi
|
|
440
|
+
|
|
441
|
+
if [ "$scan_rc" -eq 0 ] && [ "$REPORT" = '[]' ]; then
|
|
442
|
+
# gitleaks exits 0 with `[]` and a partial count when git could not read an object (measured):
|
|
443
|
+
# its ERR / fatal lines are the only signal. Written to a file first so grep -q never SIGPIPEs sed.
|
|
444
|
+
cat "$TMP/out" "$TMP/err" 2>/dev/null | sed -e "s/$(printf '\033')\[[0-9;]*m//g" >"$TMP/plain.log"
|
|
445
|
+
if grep -qE '(^|[^A-Za-z])ERR([^A-Za-z]|$)|fatal:' "$TMP/plain.log"; then
|
|
446
|
+
finish INCOMPLETE scan-errors
|
|
447
|
+
fi
|
|
448
|
+
if [[ "$SCANNED" =~ ^[0-9]+$ ]] && [ -n "$E" ]; then
|
|
449
|
+
if [ "$SCANNED" -eq 0 ] || [ "$SCANNED" -gt "$N" ]; then
|
|
450
|
+
finish INCOMPLETE scanned-mismatch
|
|
451
|
+
fi
|
|
452
|
+
fi
|
|
453
|
+
finish CLEAN no-findings
|
|
454
|
+
fi
|
|
455
|
+
|
|
456
|
+
if [ "$scan_rc" -ne 0 ] && [ "$scan_rc" -ne 1 ]; then
|
|
457
|
+
finish INCOMPLETE "gitleaks-rc-${scan_rc}"
|
|
458
|
+
fi
|
|
459
|
+
|
|
460
|
+
# rc 1 with a non-empty report is FINDINGS even when the report does not parse; rc 0 with a
|
|
461
|
+
# non-`[]` report is FINDINGS defensively.
|
|
462
|
+
printf 'secret-scan: FINDINGS in the commits this push would publish (%s..%s):\n' "${BASE_SHA:0:12}" "${HEAD_SHA:0:12}" >&2
|
|
463
|
+
total=""
|
|
464
|
+
if command -v jq >/dev/null 2>&1; then
|
|
465
|
+
total=$(jq -r 'length' "$TMP/report.json" 2>/dev/null) || total=""
|
|
466
|
+
jq -r '.[0:5][] | [(.Commit // "?"), (.File // "?"), ((.StartLine // 0) | tostring), (.RuleID // "?")] | @tsv' "$TMP/report.json" >"$TMP/sum.tsv" 2>/dev/null # mut:summary
|
|
467
|
+
fi
|
|
468
|
+
if [ -s "$TMP/sum.tsv" ]; then
|
|
469
|
+
while IFS=$'\t' read -r c f l r; do
|
|
470
|
+
c12=$(san "$c" 12)
|
|
471
|
+
[[ "$c12" =~ ^[0-9a-f]{7,12}$ ]] || c12='?'
|
|
472
|
+
l=$(san "$l" 7)
|
|
473
|
+
printf ' finding: %s %s:%s (%s)\n' "$c12" "$(san "$f" 120)" "${l:-?}" "$(san "$r" 60)" >&2
|
|
474
|
+
done <"$TMP/sum.tsv"
|
|
475
|
+
if [[ "$total" =~ ^[0-9]+$ ]] && [ "$total" -gt 5 ]; then
|
|
476
|
+
printf ' ... and %s more\n' "$((total - 5))" >&2
|
|
477
|
+
fi
|
|
478
|
+
else
|
|
479
|
+
printf ' finding: the report could not be summarised (jq absent or unparseable); %s finding(s)\n' \
|
|
480
|
+
"$(grep -c '"RuleID"' "$TMP/report.json" 2>/dev/null)" >&2
|
|
481
|
+
fi
|
|
482
|
+
# Is a finding commit already on origin? Then the secret is PUBLISHED. SHA-based, so a branch that was
|
|
483
|
+
# rebased or amended after a push reads as "not published": the local remedy says to rotate anyway.
|
|
484
|
+
PUBF=$R_PUB
|
|
485
|
+
if command -v jq >/dev/null 2>&1 && jq -r '.[].Commit // empty' "$TMP/report.json" >"$TMP/commits.txt" 2>/dev/null; then
|
|
486
|
+
PUBF=0
|
|
487
|
+
while IFS= read -r c; do
|
|
488
|
+
[[ "$c" =~ ^[0-9a-f]{40,64}$ ]] || continue
|
|
489
|
+
if [ -n "$(cd "$TOP" && git for-each-ref --count=1 --format=x --contains "$c" refs/remotes/origin 2>/dev/null)" ]; then
|
|
490
|
+
PUBF=1
|
|
491
|
+
break
|
|
492
|
+
fi
|
|
493
|
+
done <"$TMP/commits.txt"
|
|
494
|
+
fi
|
|
495
|
+
BR_T=${BR:-<branch>}
|
|
496
|
+
SHA_T=${RB:-<sha-you-reviewed>}
|
|
497
|
+
printf 'If you are an automated agent: STOP. Run none of the commands below; show this output to the operator.\n' >&2
|
|
498
|
+
printf 'Remedy (the secret is never printed here):\n' >&2
|
|
499
|
+
if [ "$PUBF" = 1 ]; then
|
|
500
|
+
printf ' 1. A finding commit is ALREADY on origin: the secret is PUBLISHED. Rotate it FIRST; a rewrite does\n' >&2
|
|
501
|
+
printf ' not unpublish it (the SHA stays reachable via refs/pull/N/head).\n' >&2
|
|
502
|
+
printf ' 2. Then: `git reset --soft "$(git merge-base origin/main HEAD)"`, remove the secret, recommit. Before\n' >&2
|
|
503
|
+
printf ' any force-push run `git fetch origin %s` and `git log --oneline HEAD..origin/%s`: if that prints\n' "$BR_T" "$BR_T" >&2
|
|
504
|
+
printf ' anything, STOP (someone else pushed). Only then `git push --force-with-lease=%s:%s origin %s`,\n' "$BR_T" "$SHA_T" "$BR_T" >&2
|
|
505
|
+
printf ' and follow the secret-scanning runbook (engineering/operations/secret-scanning.md).\n' >&2
|
|
506
|
+
else
|
|
507
|
+
printf ' 1. No finding commit is on origin: `git reset --soft "$(git merge-base origin/main HEAD)"`, remove the\n' >&2
|
|
508
|
+
printf ' secret from the files, recommit (this squashes the range and re-runs the commit hook); tip commit\n' >&2
|
|
509
|
+
printf ' only: `git commit --amend`. Do NOT use `git reset --soft origin/main`: when main has advanced it\n' >&2
|
|
510
|
+
printf ' reverts main'"'"'s newer commits.\n' >&2
|
|
511
|
+
printf ' 2. If this branch was EVER pushed, even before a rebase or an amend, treat the secret as published:\n' >&2
|
|
512
|
+
printf ' rotate it first.\n' >&2
|
|
513
|
+
fi
|
|
514
|
+
cat >&2 <<'EOF'
|
|
515
|
+
False positive: interactive ship asks the operator. This scan reads the BASE's committed config,
|
|
516
|
+
so a same-PR allowlist edit does not apply here; CI's allowlist-diff job arbitrates it.
|
|
517
|
+
Headless ship aborts here: it never rewrites history, never edits .gitleaks.toml or .gitleaksignore
|
|
518
|
+
and never adds an inline `gitleaks:allow`.
|
|
519
|
+
EOF
|
|
520
|
+
finish FINDINGS secret-found
|