Skip to content

Commit 0f1689e

Browse files
committed
added secrurity scan workflow
1 parent 367b76f commit 0f1689e

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: Security Scan
2+
3+
on:
4+
pull_request:
5+
merge_group:
6+
branches:
7+
- main
8+
9+
jobs:
10+
security-scan:
11+
runs-on: ubuntu-latest
12+
name: Security Scanning
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: TruffleHog OSS Secret Scanning
21+
uses: trufflesecurity/trufflehog@main
22+
with:
23+
# Scan the entire repository
24+
path: ./
25+
# Only show verified secrets and unknown (high confidence)
26+
extra_args: --results=verified,unknown
27+
28+
- name: Setup Python for detect-secrets
29+
uses: actions/setup-python@v5
30+
with:
31+
python-version: '3.x'
32+
33+
- name: Install detect-secrets
34+
run: |
35+
pip install detect-secrets
36+
37+
- name: Run detect-secrets scan
38+
run: |
39+
# Check if baseline exists
40+
if [ -f .secrets.baseline ]; then
41+
echo "Running detect-secrets against baseline..."
42+
detect-secrets scan --baseline .secrets.baseline
43+
else
44+
echo "No baseline found, creating one..."
45+
detect-secrets scan --baseline .secrets.baseline --force-use-all-plugins || echo "Baseline created"
46+
# Fail if new secrets found (baseline should be committed)
47+
if [ -s .secrets.baseline ]; then
48+
echo "❌ New secrets detected! Please review and commit updated baseline."
49+
exit 1
50+
fi
51+
fi
52+
53+
- name: Custom Secret Patterns Check
54+
run: |
55+
echo "🔍 Checking for additional secret patterns..."
56+
57+
# Check for AWS keys
58+
if grep -r -E "AKIA[0-9A-Z]{16}" . --exclude-dir=.git --exclude-dir=node_modules || \
59+
grep -r -E "[0-9a-zA-Z/+]{40}" . --exclude-dir=.git --exclude-dir=node_modules --include="*.env*"; then
60+
echo "❌ AWS credentials found!"
61+
exit 1
62+
fi
63+
64+
# Check for JWT tokens in code (not test files)
65+
if find . -name "*.js" -o -name "*.ts" -o -name "*.py" -o -name "*.go" -o -name "*.rs" \
66+
| grep -v test | grep -v spec | xargs grep -l "eyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]*\.[A-Za-z0-9_-]*" 2>/dev/null; then
67+
echo "❌ JWT tokens found in source code!"
68+
exit 1
69+
fi
70+
71+
# Check .env files that might be accidentally committed
72+
if find . -name "*.env" -not -name "*.env.example" -not -name "*.env.sample" -not -name "*.env.template" \
73+
| grep -v node_modules | head -1 | grep -q .; then
74+
echo "❌ .env files found in repository!"
75+
echo "These files should be in .gitignore:"
76+
find . -name "*.env" -not -name "*.env.example" -not -name "*.env.sample" -not -name "*.env.template" | grep -v node_modules
77+
exit 1
78+
fi
79+
80+
echo "✅ Custom secret checks passed!"
81+
82+
# Optional: Add Semgrep for additional security analysis
83+
semgrep:
84+
runs-on: ubuntu-latest
85+
name: Semgrep Security Analysis
86+
if: github.actor != 'dependabot[bot]'
87+
88+
steps:
89+
- name: Checkout code
90+
uses: actions/checkout@v4
91+
92+
- name: Run Semgrep
93+
uses: returntocorp/semgrep-action@v1
94+
with:
95+
# Run security-focused rules
96+
config: >-
97+
p/security-audit
98+
p/secrets
99+
p/owasp-top-ten
100+
env:
101+
SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }}
102+
# If you don't have Semgrep token, it will run in offline mode

0 commit comments

Comments
 (0)