Skip to content

Commit cf83351

Browse files
Add comprehensive secret detection and update documentation
- Enhanced .gitignore with all secrets categories from CONTEXT.md - API keys, access tokens, cloud credentials, private keys - Service account credentials, webhook secrets - Organized with CONTEXT.md section references - Created scripts/detect-secrets.sh for pre-commit secret scanning - Detects API keys (Stripe, OpenAI, GitHub, AWS, etc.) - Detects tokens, credentials, private keys, JWT tokens - Uses entropy analysis for high-entropy strings - Filters false positives (variable names, examples, URLs, comments) - Excludes test files and example files from scanning - Provides clear error messages with file location and context - Updated .pre-commit-config.yaml - Added detect-secrets hook as local hook - Runs automatically on commit - Updated bootstrap-template-structure.sh - Added scripts/detect-secrets.sh to file list - Updated docs/ai/CONTEXT.md - Section 7.1.4: Documented detect-secrets.sh implementation - Section 11.3: Added AI agent requirements for secret detection - Instructions for handling false positives - Updated README.md - Added Secret Detection subsection in Configuration - Documented what it detects and false positive filtering - Updated Security Notes section - Added detect-secrets.sh to Key Files Reference table All pre-commit checks passing
1 parent c8fda00 commit cf83351

6 files changed

Lines changed: 378 additions & 13 deletions

File tree

.gitignore

Lines changed: 83 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# ---------------------------------------------------------------------------
99
# Environment variables / secrets
1010
# ---------------------------------------------------------------------------
11+
# Per docs/ai/CONTEXT.md Section 7.1 - Secrets Management
1112

1213
# Standard environment files
1314
.env
@@ -24,21 +25,94 @@ secrets.*
2425
*.secret
2526
*.secrets
2627

27-
# Credential files
28-
*.pem
29-
*.key
30-
*.crt
31-
*.pfx
32-
*.p12
33-
id_rsa
34-
id_ed25519
28+
# ---------------------------------------------------------------------------
29+
# API Keys and Access Tokens (Section 7.1.2.1, 7.1.2.2)
30+
# ---------------------------------------------------------------------------
31+
# API key files
32+
*api*key*
33+
*apikey*
34+
*access*token*
35+
*oauth*token*
36+
*refresh*token*
37+
*pat*
38+
*personal*access*token*
3539

36-
# Cloud / tooling credentials
40+
# ---------------------------------------------------------------------------
41+
# Cloud Provider Credentials (Section 7.1.2.4)
42+
# ---------------------------------------------------------------------------
3743
.aws/
3844
.gcp/
3945
.azure/
46+
.terraform/
4047
terraform.tfvars
4148
terraform.tfvars.json
49+
*.tfvars
50+
*.tfvars.json
51+
52+
# GCP service account keys
53+
*service-account*.json
54+
*gcp*.json
55+
*gcloud*.json
56+
57+
# AWS credentials
58+
.aws/credentials
59+
.aws/config
60+
aws-credentials.json
61+
62+
# Azure credentials
63+
.azure/credentials
64+
azure-credentials.json
65+
66+
# ---------------------------------------------------------------------------
67+
# Cryptographic Private Keys (Section 7.1.2.5)
68+
# ---------------------------------------------------------------------------
69+
# SSH keys
70+
id_rsa
71+
id_ed25519
72+
id_ecdsa
73+
id_dsa
74+
*.pem
75+
*.key
76+
*.p12
77+
*.pfx
78+
*.crt
79+
*.cer
80+
*.der
81+
82+
# TLS/SSL certificates (private keys only - public certs may be OK)
83+
*.key
84+
*.pem
85+
!*.pub
86+
!*.public
87+
88+
# Signing keys
89+
*.signing.key
90+
*.private.key
91+
92+
# ---------------------------------------------------------------------------
93+
# Service Account Credentials (Section 7.1.2.6)
94+
# ---------------------------------------------------------------------------
95+
*service-account*.json
96+
*service-account*.yaml
97+
*service-account*.yml
98+
*credentials*.json
99+
*credentials*.yaml
100+
*credentials*.yml
101+
102+
# ---------------------------------------------------------------------------
103+
# Webhook Secrets (Section 7.1.2.7)
104+
# ---------------------------------------------------------------------------
105+
*webhook*secret*
106+
*webhook*signing*
107+
*hook*secret*
108+
109+
# ---------------------------------------------------------------------------
110+
# Generated logs and caches that may contain secrets
111+
# ---------------------------------------------------------------------------
112+
*.log
113+
!artifacts/pre-commit.log
114+
*.cache
115+
*.tmp
42116

43117
# ---------------------------------------------------------------------------
44118
# Python

.pre-commit-config.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ repos:
1212
args: [--fix=lf]
1313
- id: detect-private-key
1414

15+
# Custom secret detection (comprehensive API keys, tokens, credentials)
16+
- repo: local
17+
hooks:
18+
- id: detect-secrets
19+
name: Detect Secrets (API Keys, Tokens, Credentials)
20+
entry: scripts/detect-secrets.sh
21+
language: system
22+
pass_filenames: false
23+
always_run: false
24+
1525
# Python: Ruff (lint + autofix) and Ruff formatter
1626
- repo: https://github.com/astral-sh/ruff-pre-commit
1727
rev: v0.8.4

README.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,32 @@ Pre-commit hooks are configured in `.pre-commit-config.yaml`. The default config
367367
| 🐍 Python | Ruff linting and formatting | ✅ Active |
368368
| 🐚 Bash | ShellCheck and shfmt formatting | ✅ Active |
369369
| 📄 Markdown | PyMarkdown validation | ✅ Active |
370-
| 🔒 Security | Private key detection | ✅ Active |
370+
| 🔒 Security | Private key detection, API key detection, token scanning | ✅ Active |
371+
372+
#### Secret Detection
373+
374+
The framework includes comprehensive secret detection via `scripts/detect-secrets.sh`:
375+
376+
**What It Detects**:
377+
378+
- ✅ API keys (Stripe, OpenAI, Google, AWS, etc.)
379+
- ✅ GitHub tokens (PATs, OAuth tokens)
380+
- ✅ Cloud provider credentials (AWS, GCP, Azure)
381+
- ✅ Private keys (SSH, TLS, signing keys)
382+
- ✅ OAuth tokens and refresh tokens
383+
- ✅ JWT tokens
384+
- ✅ High-entropy strings (potential secrets)
385+
386+
**False Positive Filtering**:
387+
388+
- ✅ Ignores variable names (e.g., `api_key =`)
389+
- ✅ Ignores example/placeholder values
390+
- ✅ Ignores URLs and API endpoints
391+
- ✅ Ignores comments and documentation
392+
- ✅ Excludes test files and example files
393+
394+
If secrets are detected, the commit will be blocked. Use example placeholders like
395+
`YOUR_API_KEY_HERE` instead of real secrets.
371396

372397
### CI/CD Configuration
373398

@@ -429,7 +454,7 @@ This framework is designed with security as the highest priority:
429454
| Security Feature | Status | Description |
430455
|-----------------|--------|-------------|
431456
| 🔐 Secrets Protection | ✅ Active | Comprehensive `.gitignore` prevents accidental secret commits |
432-
| 🔍 Automated Detection | ✅ Active | Pre-commit hooks detect private keys and other secrets |
457+
| 🔍 Automated Detection | ✅ Active | Pre-commit hooks detect secrets via detect-secrets.sh |
433458
| 🛡️ Least Privilege | ✅ Active | All scripts should use least privilege principles |
434459
| ✅ Input Validation | ✅ Active | All inputs should be treated as untrusted |
435460
| 📋 Audit Trail | ✅ Active | Pre-commit logs provide an audit trail of quality checks |
@@ -475,6 +500,7 @@ Licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) for full
475500
| `.pre-commit-config.yaml` | Quality check configuration | ✅ Required |
476501
| `.github/workflows/ci.yaml` | CI/CD pipeline definition | ✅ Required |
477502
| `scripts/run-precommit.sh` | Pre-commit execution wrapper (use this, not `pre-commit` directly) | ✅ Required |
503+
| `scripts/detect-secrets.sh` | Secret detection script (runs automatically via pre-commit) | ✅ Required |
478504
| `bootstrap-template-structure.sh` | Recreate template structure | ✅ Optional |
479505

480506
---

bootstrap-template-structure.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ FILES=(
2929
".github/ISSUE_TEMPLATE/feature_request.yml"
3030
".github/ISSUE_TEMPLATE/bug_report.yml"
3131
"scripts/run-precommit.sh"
32+
"scripts/detect-secrets.sh"
3233
)
3334

3435
echo "==> Creating directory structure (no overwrite)"

docs/ai/CONTEXT.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,23 @@ Secrets must not appear:
294294

295295
Repositories must enforce:
296296

297-
- Pre-commit secret scanning
298-
- CI-level secret detection
297+
- Pre-commit secret scanning via `scripts/detect-secrets.sh`
298+
- CI-level secret detection (runs same pre-commit hooks)
299299
- AI agent instructions prohibiting secret creation or logging
300300

301+
**Secret Detection Implementation**: This framework includes `scripts/detect-secrets.sh`, a
302+
comprehensive secret detection script that:
303+
304+
- Scans staged files for API keys, tokens, credentials, and private keys
305+
- Uses pattern matching for known secret formats (GitHub tokens, AWS keys, Stripe keys, etc.)
306+
- Applies entropy analysis to detect high-entropy strings
307+
- Filters false positives (variable names, example values, API endpoints, comments)
308+
- Excludes test files, example files, and documentation from scanning
309+
- Provides clear error messages with file location and context
310+
311+
AI agents must understand that this script will block commits containing secrets and must
312+
never attempt to bypass or disable this protection.
313+
301314
High-entropy strings and known token patterns must be treated as potential secrets until proven otherwise.
302315

303316
#### 7.1.5 Security Posture Statement
@@ -509,6 +522,15 @@ AI agents must execute pre-commit using the repository helper script:
509522
./scripts/run-precommit.sh
510523
```
511524

525+
**Secret Detection**: The pre-commit hooks include `scripts/detect-secrets.sh` which
526+
automatically scans all staged files for secrets, API keys, and credentials. If secrets
527+
are detected, the commit will be blocked. AI agents must:
528+
529+
- Never attempt to bypass secret detection
530+
- Use example placeholders (e.g., `YOUR_API_KEY_HERE`) instead of real secrets
531+
- Ensure all secrets are stored in `.env` files (which are excluded from git)
532+
- If a false positive is detected, add appropriate allowlist patterns to the script
533+
512534
---
513535

514536
## 12. Why Security Matters in This Framework

0 commit comments

Comments
 (0)