Capstone — PR Secret Firewall
Build a secret-blocking bot — pre-merge secret detection on Copilot-suggested diffs.
What You Will Learn
- Build a secret firewall.
- Detect secrets in Copilot-suggested diffs.
- Block PRs with secrets.
- Alert on detection.
- Measure caught leaks.
Why This Matters
Copilot can suggest code containing secrets (from training data or leaked patterns). A PR firewall catches before merge.
Concept Explained
PR firewall: GitHub Action that scans PR diffs for secret patterns. If found, block merge, alert author. Special focus on Copilot-authored commits.
How It Works
GitHub Action triggers on PR. Scans diff for secret patterns (regex, ML-based). If found: block merge, comment on PR, alert author. Track caught leaks.
Step-by-Step Tutorial
1. Create Action
.github/workflows/secret-firewall.yml2. Scan diff
Use gitleaks or custom regex for known secret patterns.3. Detect Copilot-authored commits
Check commit messages for 'Co-authored-with: Copilot'.4. Block merge
Set status check to fail.5. Alert
Comment on PR. Alert author and security team.Real-World Example
A team built this firewall. Caught 3 Copilot-suggested secrets in 6 months — all from training data patterns (example API keys Copilot thought were valid). Blocked before merge. No leaks.
Example Prompts / Commands / Code
"""# .github/workflows/secret-firewall.yml
name: Secret Firewall
on:
pull_request:
types: [opened, synchronize]
jobs:
scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Scan diff for secrets
id: scan
run: |
# Get diff
DIFF=$(git diff origin/main...HEAD)
# Check for Copilot-authored commits
COPILOT_COMMITS=$(git log origin/main..HEAD --grep='Co-authored-with: GitHub Copilot' --oneline)
if [ -n "$COPILOT_COMMITS" ]; then
echo "Copilot-authored commits detected. Extra scrutiny."
fi
# Scan with gitleaks
echo "$DIFF" | gitleaks detect --stdin --report-path=report.json
if [ -s report.json ]; then
echo "Secrets detected!"
cat report.json
exit 1
fi
- name: Alert on detection
if: failure()
uses: actions/github-script@v6
with:
script: |
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: '🚨 **Secret detected in PR!**\n\nPlease remove the secret and rotate if needed.\n\nSee Action logs for details.'
});
"""
Common Mistakes
- Only scanning Copilot commits — human commits can have secrets too.
- No alerting — secrets detected silently.
- Not requiring the status check — PRs can merge despite detection.
- Not tracking caught leaks — can't measure value.
Best Practices
- Scan ALL PR diffs (not just Copilot).
- Block merge on detection (required status check).
- Alert author and security team.
- Track caught leaks (measure value).
- Train team on secret hygiene.
Troubleshooting
| Problem | How to Fix |
|---|---|
| False positives | Tune regex. Or allowlist known-safe patterns. |
| Secrets slipping through | Add ML-based detection (e.g., GitHub's secret scanning). |
Practical Exercise
Your Turn
Build a secret firewall GitHub Action. Test by intentionally committing a fake secret in a PR.
Professional Challenge
Track caught leaks over a quarter. Measure: leaks caught, false positives, time saved. Present to security team.
Key Takeaways
- PR firewall: scan diffs for secrets.
- Block merge on detection.
- Alert author and security.
- Track caught leaks.
- Train team on secret hygiene.
Frequently Asked Questions
Does this replace pre-commit?
Use gitleaks or custom?
Further Reading
Official References
SEO Metadata
SEO title: Capstone — PR Secret Firewall
Meta description: Build a secret-blocking bot — pre-merge secret detection on Copilot-suggested diffs.
Primary keyword: capstone
Secondary keywords: capstone — pr secret firewall
Search intent: Informational
URL slug: /capstone-pr-secret-firewall-copilot-diffs
Categories: AI Tools, GitHub Copilot
Tags: GitHub Copilot, Professional, Capstone, Security, Secrets, CI/CD, Firewall, IMCSEIAN, Tutorial, IMCSEIAN
Featured image concept: IMCSEIAN lesson card for Capstone — PR Secret Firewall
Comments
Comments
Post a Comment