Skip to content

Semgrep Code Scan with AI Validation #2

Semgrep Code Scan with AI Validation

Semgrep Code Scan with AI Validation #2

name: Semgrep Code Scan with AI Validation
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:
jobs:
semgrep-scan:
name: Run Semgrep & Validate with Claude
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Install Semgrep
run: pip install semgrep
- name: Run Semgrep scan (non-blocking)
run: semgrep ci --config auto || true
- name: Save Semgrep reports
if: always()
run: |
semgrep --config auto --json > semgrep-report.json
semgrep --config auto --text > semgrep-report.txt
- name: Validate Semgrep findings with Claude
if: always()
uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.ANTROPIC_API_KEY }}
prompt: |
I need you to validate the Semgrep security findings in semgrep-report.json.
For EACH finding in the JSON file:
1. Read the actual source code file at the path mentioned in the finding
2. Examine the specific line numbers where the issue was detected
3. Understand the full context of the code (read surrounding code, understand data flow)
4. Determine if this is a TRUE POSITIVE (real security vulnerability) or FALSE POSITIVE (safe code incorrectly flagged)
For each finding, add these fields:
- "is_false_positive": true or false
- "validation_reason": "Detailed explanation of why this is classified as true/false positive"
Consider in your analysis:
- Is user input involved? Is it properly validated/sanitized?
- Can this vulnerability actually be exploited in practice?
- Are there framework-specific protections in place (e.g., Django ORM, parameterized queries)?
- Is the flagged code path actually reachable and executable?
- What is the full data flow context?
After validating ALL findings, save the enhanced JSON with validation fields to: semgrep-report-validated.json
Be thorough and examine the actual code before making your determination. Do not guess.
- name: Upload all reports
if: always()
uses: actions/upload-artifact@v4
with:
name: semgrep-reports
path: |
semgrep-report.json
semgrep-report.txt
semgrep-report-validated.json