Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,22 +138,18 @@ jobs:
base="${{ github.event.before }}"
fi

pattern='(ghp_|sk-[A-Za-z0-9]{20,}|xox[baprs]-[A-Za-z0-9-]{10,}|BEGIN (RSA|OPENSSH|EC|DSA|PRIVATE) KEY|api[_-]?key[[:space:]]*[:=]|private[_-]?key[[:space:]]*[:=]|access[_-]?token[[:space:]]*[:=]|bearer[_-]?token[[:space:]]*[:=]|password[[:space:]]*[:=]|secret[_-]?key[[:space:]]*[:=]|auth[_-]?token[[:space:]]*[:=])'
sensitive_exts=(
'*.js' '*.jsx' '*.ts' '*.tsx' '*.mjs' '*.cjs'
'*.py' '*.sh' '*.bash'
'*.yml' '*.yaml' '*.json' '*.toml' '*.ini' '*.cfg'
'.env*'
)
pattern='(ghp_|sk-[A-Za-z0-9]{20,}|xox[baprs]-[A-Za-z0-9-]{10,}|BEGIN (RSA|OPENSSH|EC|DSA|PRIVATE) KEY|([A-Za-z0-9]+[_-])?(secret|token|bearer)([_-][A-Za-z0-9]+)*[[:space:]]*[:=]|api[_-]?key[[:space:]]*[:=]|private[_-]?key[[:space:]]*[:=]|password[[:space:]]*[:=])'

if [[ -z "$base" || "$base" =~ ^0+$ ]] || ! git cat-file -e "$base^{commit}" 2>/dev/null; then
if git grep -nI -E "$pattern" -- "${sensitive_exts[@]}" ':!.github/workflows/ci.yml' \
if git grep -nIi -E "$pattern" -- . \
| bash scripts/filter-secret-scan-candidates.sh; then
echo "Potential secret pattern detected in repository history scan."
exit 1
fi
else
if git diff -U0 "$base"...HEAD -- "${sensitive_exts[@]}" ':!.github/workflows/ci.yml' \
if git diff -U0 "$base"...HEAD -- \
| grep -E '^\+' \
| grep -Ev '^\+\+\+' \
| grep -E -i "$pattern" \
| bash scripts/filter-secret-scan-candidates.sh; then
echo "Potential secret pattern detected in changed content."
Expand Down
5 changes: 3 additions & 2 deletions scripts/filter-secret-scan-candidates.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env bash
set -euo pipefail

safe_github_secret_reference='^([^:]+:[0-9]+:|\+)[[:space:]]*[A-Za-z0-9_-]+[[:space:]]*:[[:space:]]*\$\{\{[[:space:]]*secrets\.[A-Za-z_][A-Za-z0-9_]*[[:space:]]*\}\}[[:space:]]*$'
safe_reference='^([^:]+:[0-9]+:|[-+])[[:space:]]*[A-Za-z0-9_-]+[[:space:]]*:[[:space:]]*\$\{\{[[:space:]]*secrets\.[A-Za-z_][A-Za-z0-9_]*[[:space:]]*\}\}[[:space:]]*$'
scan_definition='^([^:]+:[0-9]+:|[-+])[[:space:]]*(pattern|safe_github_secret_reference)='

grep -Eiv "$safe_github_secret_reference"
grep -Eiv "$safe_reference|$scan_definition"
Loading