ci(security): stop the secrets gate failing PRs on other branches' commits - #2300
Conversation
--since-commit only prunes commits the base can reach. With fetch-depth 0 the checkout carries every branch, so commits on unmerged branches were scanned as well, and a secret on one of them failed pull requests that do not touch it. Refs #2025 Signed-off-by: Gregory Gogin <grigoriy.gogin@constructor.tech>
A Lob key is `test_` followed by 35 characters, which is also the shape of this repository's long test function names -- 33 of them across 27 files match the pattern today, and each one fails the gate on the pull request that adds it. Lob is a direct-mail API and is not a dependency here, so the detector can only produce false positives. Refs #2025 Signed-off-by: Gregory Gogin <grigoriy.gogin@constructor.tech>
📝 WalkthroughWalkthroughThe TruffleHog workflow now scopes pull-request scans to the merge ref and excludes the Lob detector from pull-request, full-history, and GitHub API scans. The workflow documents the detector exclusion. ChangesTruffleHog scan scope
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.github/workflows/trufflehog.yml:
- Line 160: Update the full-history TruffleHog baseline associated with the scan
configuration containing the lob detector exclusion: rerun the post-change
full-history scan, replace BASELINE with the resulting non-Lob finding count,
and refresh the documented true-positive/false-positive breakdown and triage
date.
- Around line 48-56: Update the TruffleHog invocation in the workflow run block
to scan an explicit Git revision range from SINCE to HEAD_SHA, including the
corresponding invocation around lines 66-67. Preserve the existing merge-commit
and base fallback setup, and ensure the range prevents traversal beyond the
intended PR revisions.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 861482ed-27ff-4939-9ab3-f35b4f57ab75
📒 Files selected for processing (1)
.github/workflows/trufflehog.yml
| # `--since-commit` alone only prunes what the base can reach: with fetch-depth 0 the | ||
| # checkout carries every branch, and commits on unmerged ones are scanned too, so an | ||
| # unrelated branch fails this PR. `--branch` confines the walk to the merge ref. | ||
| env: | ||
| BASE_SHA: ${{ github.event.pull_request.base.sha }} | ||
| run: | | ||
| set -euo pipefail | ||
| SINCE="$(git rev-parse 'HEAD^1' 2>/dev/null || echo "$BASE_SHA")" | ||
| HEAD_SHA="$(git rev-parse HEAD)" |
There was a problem hiding this comment.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
repo="$(mktemp -d)"
trap 'rm -rf "$repo"' EXIT
git -C "$repo" init -q
git -C "$repo" config user.name review
git -C "$repo" config user.email review@example.invalid
commit() {
git -C "$repo" add -A
GIT_AUTHOR_DATE="$1" GIT_COMMITTER_DATE="$1" \
git -C "$repo" commit -q -m "$2"
}
echo root > "$repo/root"
commit "2026-01-01T00:00:00Z" root
git -C "$repo" branch -M main
git -C "$repo" checkout -q -b pr
echo pr > "$repo/pr.txt"
commit "2026-01-02T00:00:00Z" pr
git -C "$repo" checkout -q main
echo base > "$repo/base.txt"
commit "2026-08-06T00:00:00Z" base
GIT_AUTHOR_DATE="2026-08-06T00:00:01Z" \
GIT_COMMITTER_DATE="2026-08-06T00:00:01Z" \
git -C "$repo" merge --no-ff --no-edit pr >/dev/null
merge="$(git -C "$repo" rev-parse HEAD)"
base="$(git -C "$repo" rev-parse HEAD^1)"
pr="$(git -C "$repo" rev-parse HEAD^2)"
mapfile -t order < <(git -C "$repo" log --full-history --format=%H "$merge")
pos() {
for i in "${!order[@]}"; do
[[ "${order[$i]}" == "$1" ]] && { echo "$i"; return; }
done
echo -1
}
base_pos="$(pos "$base")"
pr_pos="$(pos "$pr")"
if (( base_pos >= 0 && pr_pos >= 0 && base_pos < pr_pos )); then
echo "Reproduced: the base commit appears before the PR commit."
exit 1
fi
echo "The ordering case was not reproduced; verify with the pinned TruffleHog image."Repository: constructorfabric/insight
Length of output: 285
Use an explicit Git revision range for the PR scan.
HEAD_SHA is the synthetic merge commit. TruffleHog passes the branch value to git log --full-history and stops when it reaches the base hash. If the base tip is newer than an older PR commit, the base commit can appear before that PR commit and the scan can miss it. Pass an explicit range such as ${SINCE}..${HEAD_SHA}, or verify an equivalent pinned-version configuration. Also applies to lines 66-67.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.github/workflows/trufflehog.yml around lines 48 - 56, Update the TruffleHog
invocation in the workflow run block to scan an explicit Git revision range from
SINCE to HEAD_SHA, including the corresponding invocation around lines 66-67.
Preserve the existing merge-commit and base fallback setup, and ensure the range
prevents traversal beyond the intended PR revisions.
Closes #2025.
secrets (diff)fails pull requests on findings they do not introduce. Two independent causes, one commit each.The scan reaches unmerged branches.
--since-commitprunes only what the base commit can reach, andfetch-depth: 0puts every branch in the checkout, so TruffleHog walks their commits too. A pull request touching five markdown files (#2289) was scanned over 203 chunks / 258 339 bytes and failed on a commit from an unrelated branch,feat/bamboohr-cdk-fetch-all.--branch "$HEAD_SHA"confines the walk to the merge ref; the same scan then reads 9 chunks / 1 898 bytes.The Lob detector matches test function names. A Lob key is
test_followed by 35 characters.test_a_deprecated_field_is_not_requestedis exactly that shape, and Lob's sandbox accepts anytest_-prefixed key, so the finding arrives asverified: truewithenvironment: test. 33 names across 27 files match the pattern today, and each one fails the gate on the pull request that adds it. Lob is a direct-mail API and is not a dependency here, so the detector can only produce false positives. Dropped in all three jobs.Reviewer note: the two halves are separable. Drop the second commit if you would rather keep the detector and annotate individual lines with
trufflehog:ignore— that costs 33 annotations today and one per future long test name.Test plan
203 chunks / 258 339 bytes / 2 verified— identical to attempt 3 in CI--branchalone, detached HEAD as in CI:9 chunks / 1 898 bytes, 0 findings--exclude-detectors lobalone: 0 findings, scan volume unchanged--branchand without the Lob exclusion, still reports both findings — confining the range does not blind the gateactionlint .github/workflows/trufflehog.yml— exit 0secrets (diff)passes on this pull requestsecrets (full history)reports without the Lob rowsThe last two need CI runs and are unchecked until they exist.
Summary by CodeRabbit