Skip to content

Commit b2f0af2

Browse files
fix: fail explicitly when Docker scan fails to prevent fail-open bypass
docker run ... 2>/dev/null || true suppresses all stderr and forces exit 0 in every case. If TruffleHog or Docker fails at runtime (image pull error, OOM, container crash), SCAN_OUTPUT is empty → VERIFIED_COUNT=0 → job passes silently — a fail-open that bypasses the required ruleset check. Fix: capture the exit code without || true. TruffleHog exits 0 (no secrets) or 183 (secrets found) on a successful run. Any other code means the scanner itself failed — fail the job explicitly with ::error rather than silently passing with zero findings. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 107b04c commit b2f0af2

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

.github/workflows/trufflehog-scan.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,22 @@ jobs:
124124
echo "$CHANGED_FILES"
125125
126126
# Scan changed files using TruffleHog filesystem mode — pinned by digest for reproducibility
127+
SCAN_EXIT=0
127128
SCAN_OUTPUT=$(docker run --rm -v "$(pwd)":/tmp -w /tmp \
128129
ghcr.io/trufflesecurity/trufflehog:3.94.2@sha256:dabd9a5f78ed81211792afc39a35100e2b947baa9f43f1e73a97759d7d15ab86 \
129130
filesystem /tmp/ \
130131
--json \
131132
$EXCLUDE_ARGS \
132-
--no-update 2>/dev/null || true)
133+
--no-update 2>/dev/null) || SCAN_EXIT=$?
134+
135+
# TruffleHog exits 0 (no secrets found) or 183 (secrets found) on a successful run.
136+
# Any other exit code means Docker or TruffleHog itself failed to execute.
137+
# We must not silently pass in that case — an empty SCAN_OUTPUT would report 0 findings
138+
# and let the job succeed, bypassing the required ruleset check (fail-open).
139+
if [ "$SCAN_EXIT" -ne 0 ] && [ "$SCAN_EXIT" -ne 183 ]; then
140+
echo "::error::TruffleHog Docker scan failed (exit ${SCAN_EXIT}). Blocking to prevent fail-open bypass of secret scanning."
141+
exit 1
142+
fi
133143
134144
# Parse JSON lines and filter to only changed files
135145
if [ -n "$SCAN_OUTPUT" ]; then

0 commit comments

Comments
 (0)