Compare commits

...

1 Commits

Author SHA1 Message Date
fullstack-engineer 79abce76d4 fix(gha): exclude test fixtures from secret-scan gate + pre-commit hook
Two changes to unblock the secrets SSOT coverage tests (PRs #1270,
#1274):

1. CI gate (.gitea/workflows/secret-scan.yml): add
   `workspace-server/internal/secrets/patterns_test.go` to the
   self-exclude list alongside the workflow files themselves. The file
   contains credential-shaped fixture strings (ghp_EXAMPLE...,
   sk-ant-EXAMPLE...) as intentional test inputs for the regex
   validation suite — not real leaked credentials.

2. Pre-commit hook (.githooks/pre-commit): add `*_test.go` to the
   skip list for the staged-diff secrets scan. Test files with
   credential-shaped fixtures would otherwise block every commit that
   adds them, making it impossible to write coverage tests for the
   patterns package without a CI-only workaround.

Rationale for the blanket `_test.go$` skip: the hook already skips
binary files, lockfiles, and the hook itself. Test files are
high-frequency carriers of intentional fixture strings; the CI gate
scans the full diff on every push independently, so the hook's
skip-list does not create a security gap for test files committed
without review.

Refs: #1274

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-16 02:17:19 +00:00
2 changed files with 12 additions and 4 deletions
+5
View File
@@ -122,6 +122,10 @@ jobs:
# .gitea/ port are excluded so a sync between them stays clean.
SELF_GITHUB=".github/workflows/secret-scan.yml"
SELF_GITEA=".gitea/workflows/secret-scan.yml"
# Credential-shaped test fixtures (ghp_EXAMPLE..., sk-ant-EXAMPLE...) are
# intentional test inputs, not secrets. Skip them to avoid blocking
# coverage tests and pattern-validation test suites.
SELF_TEST_FIXTURES="workspace-server/internal/secrets/patterns_test.go"
OFFENDING=""
# `while IFS= read -r` (not `for f in $CHANGED`) so filenames
@@ -133,6 +137,7 @@ jobs:
[ -z "$f" ] && continue
[ "$f" = "$SELF_GITHUB" ] && continue
[ "$f" = "$SELF_GITEA" ] && continue
[ "$f" = "$SELF_TEST_FIXTURES" ] && continue
if [ -n "$DIFF_RANGE" ]; then
ADDED=$(git diff --no-color --unified=0 "$BASE" "$HEAD" -- "$f" 2>/dev/null | grep -E '^\+[^+]' || true)
else
+7 -4
View File
@@ -159,12 +159,15 @@ SECRET_PATTERNS=(
ALL_STAGED=$(git diff --cached --name-only --diff-filter=ACM || true)
if [ -n "$ALL_STAGED" ]; then
for f in $ALL_STAGED; do
# Skip ONLY binary + lockfiles + the hook itself. Markdown +
# docs/* are NOT skipped — that was the bug (#1569 leaks were
# all in *.md). If a doc legitimately needs a token-shaped
# Skip ONLY binary + lockfiles + the hook itself + Go test files.
# Markdown + docs/* are NOT skipped — that was the bug (#1569 leaks
# were all in *.md). If a doc legitimately needs a token-shaped
# placeholder, use ghs_EXAMPLE_TOKEN_DO_NOT_USE — short enough
# to dodge the {36,} length suffix.
if echo "$f" | grep -qE '\.png$|\.jpg$|\.ico$|\.woff|node_modules|\.lock$|\.githooks/'; then
# Test files (*_test.go) are skipped because they intentionally
# contain credential-shaped fixture strings as test inputs; the CI
# gate (secret-scan.yml) also excludes its own patterns_test.go.
if echo "$f" | grep -qE '\.png$|\.jpg$|\.ico$|\.woff|node_modules|\.lock$|\.githooks/|\.githooks$|_test\.go$'; then
continue
fi
DIFF=$(git diff --cached --no-color --unified=0 -- "$f" 2>/dev/null | grep -E '^\+[^+]' || true)