feat(ci): add AI security audit for pull requests#923
feat(ci): add AI security audit for pull requests#923davidapp wants to merge 2 commits intotronprotocol:developfrom
Conversation
Add a GitHub Actions workflow that automatically runs AI-powered security audits on every pull request using Claude. The workflow analyzes PR diffs for vulnerabilities and posts structured audit reports as PR comments. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Code Review1. [HIGH] Prompt Injection via PR Diff ContentThe PR diff (attacker-controlled) is directly embedded into the Claude prompt. A malicious PR could include code comments or strings like: This could trick the AI into producing a false "clean" report, defeating the purpose of the audit. Recommendations (combine for defense in depth):
2. [MEDIUM] stderr Leaks into Audit Comment (line 108)AUDIT_RESULT=$(echo "$FULL_PROMPT" | claude -p --output-format text 2>&1) || true
Fix: Separate stderr and handle failure explicitly: AUDIT_RESULT=$(printf '%s\n' "$FULL_PROMPT" | claude -p --output-format text 2>/tmp/claude_err.txt) || true
if [ ! -s audit_result.md ]; then
echo "AI audit failed to produce results. Check workflow logs for details." > audit_result.md
fi3. [MEDIUM] Unnecessary
|
| Severity | Count | Items |
|---|---|---|
| High | 1 | Prompt injection |
| Medium | 2 | stderr leak, unnecessary fetch-depth |
| Low | 3 | echo fragility, duplicate code, no version pin |
| Info | 1 | expression best practice |
The workflow structure is well thought out — the diff size guard, comment replacement mechanism, and API key validation are solid. The main concern is the prompt injection surface: since this workflow's value proposition is security gating, it's worth hardening against crafted diffs that could manipulate audit output. The most impactful fix is switching from claude -p to the API with proper system/user message separation.
The AI security audit now exits with failure if any CRITICAL severity issues are detected, preventing PRs with critical vulnerabilities from showing a green check. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
claude -pTest plan
🤖 Generated with Claude Code