Skip to content

Commit 03c24de

Browse files
committed
.github precommit hook preventing leak of secrets
1 parent 77f88ab commit 03c24de

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Secret Detection
2+
3+
on:
4+
push:
5+
branches: [ develop, main ]
6+
pull_request:
7+
branches: [ develop, main ]
8+
9+
jobs:
10+
secret-detection:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Run Gitleaks
18+
uses: gitleaks/gitleaks-action@v2
19+
env:
20+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21+
22+
- name: Check for common secret patterns
23+
run: |
24+
# Check for common secret file patterns
25+
if find . -name "*.key" -o -name "*.pem" -o -name "*.p12" -o -name "*.pfx" -o -name "*.jks" -o -name "secret*" -o -name "*secret*" | grep -v ".github" | head -1; then
26+
echo "Error: Secret files detected!"
27+
find . -name "*.key" -o -name "*.pem" -o -name "*.p12" -o -name "*.pfx" -o -name "*.jks" -o -name "secret*" -o -name "*secret*" | grep -v ".github"
28+
exit 1
29+
fi
30+
31+
# Check for hardcoded secrets in files
32+
if grep -r -E "(password|pwd|secret|key|token|api_key|apikey|access_key)" --include="*.py" --include="*.js" --include="*.ts" --include="*.yaml" --include="*.yml" --include="*.json" --exclude-dir=".github" --exclude-dir=".git" . | grep -v -E "(#|//|\*)" | head -1; then
33+
echo "Warning: Potential hardcoded secrets found. Please review:"
34+
grep -r -E "(password|pwd|secret|key|token|api_key|apikey|access_key)" --include="*.py" --include="*.js" --include="*.ts" --include="*.yaml" --include="*.yml" --include="*.json" --exclude-dir=".github" --exclude-dir=".git" . | grep -v -E "(#|//|\*)" || true
35+
fi

.pre-commit-config.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.6.0
4+
hooks:
5+
- id: check-added-large-files
6+
- id: detect-private-key
7+
- id: check-yaml
8+
- id: check-json
9+
- id: check-merge-conflict
10+
- id: trailing-whitespace
11+
- id: end-of-file-fixer
12+
- repo: https://github.com/Yelp/detect-secrets
13+
rev: v1.5.0
14+
hooks:
15+
- id: detect-secrets
16+
args: ['--baseline', '.secrets.baseline']
17+
exclude: package.lock.json
18+
- repo: https://github.com/zricethezav/gitleaks
19+
rev: v8.18.4
20+
hooks:
21+
- id: gitleaks

0 commit comments

Comments
 (0)