Sc diff report

From ersinkoc/security-check · View interactive version

Sc diff report is an AI agent skill from the GitHub repository ersinkoc/security-check. Incremental security scan for changed files only — optimized for PR and commit-level reviews

How to use this skill

Skill file

SC: Diff Report — Incremental Security Scan

Purpose

Performs a targeted security scan on only the files changed in a git diff, pull request, or recent commit. This enables fast, focused security feedback during code review without the overhead of a full codebase scan. Classifies findings as "new" (introduced by changes) vs "existing" (pre-existing in touched files).

Diff mode is always partial coverage. Apply the evidence contract in sc-orchestrator: verify causality against the base revision, independently challenge candidates, and never present unresolved or pre-existing leads as newly introduced vulnerabilities.

Activation

Activates when the user issues any of:

Output

File: security-report/diff-report.md

Phase 1: Change Detection

Git Diff Extraction

Determine the diff scope based on user context:

PR Mode (most common):

git diff main...HEAD --name-only
git diff main...HEAD

Staged changes:

git diff --cached --name-only
git diff --cached

Last commit:

git diff HEAD~1 --name-only
git diff HEAD~1

Custom range:

git diff {base}...{head} --name-only
git diff {base}...{head}

Changed File Inventory

From the diff output, build an inventory:

  1. Added files — entirely new files (highest priority)
  2. Modified files — existing files with changes
  3. Deleted files — removed files (check for orphaned references)
  4. Renamed files — detect renames with content changes

For each changed file, record:

Change Filtering

Filter out changes unlikely to have security impact:

Dependency Change Detection

If lock files or manifests changed:

Phase 2: Targeted Vulnerability Scanning

Skill Selection

Based on changed files, activate only relevant skills:

| Changed File Pattern | Skills to Activate |

|---------------------|-------------------|

| *.go | sc-lang-go, sc-sqli, sc-cmdi, sc-ssrf, sc-auth, sc-race-condition |

| *.ts, *.tsx, *.js, *.jsx | sc-lang-typescript, sc-xss, sc-sqli, sc-secrets, sc-auth |

| *.py | sc-lang-python, sc-sqli, sc-cmdi, sc-ssti, sc-deserialization |

| *.php | sc-lang-php, sc-sqli, sc-xss, sc-cmdi, sc-deserialization, sc-path-traversal |

| *.rs | sc-lang-rust, sc-cmdi, sc-race-condition |

| *.java, *.kt | sc-lang-java, sc-sqli, sc-deserialization, sc-xxe, sc-rce |

| *.cs | sc-lang-csharp, sc-sqli, sc-deserialization, sc-xxe |

| Dockerfile*, docker-compose* | sc-docker |

| *.tf, *.tfvars | sc-iac |

| .github/workflows/*, .gitlab-ci.yml | sc-ci-cd |

| *.graphql, *resolver*, *schema* | sc-graphql |

| *.proto | sc-api-security |

| .env*, *config*, *secret* | sc-secrets, sc-data-exposure |

| *auth*, *login*, *session* | sc-auth, sc-session, sc-jwt |

| *upload* | sc-file-upload |

| *redirect*, *callback* | sc-open-redirect |

Focused Scanning

For each activated skill:

  1. Provide the skill with ONLY the changed files and their full content
  2. Also provide the diff hunks showing exactly what changed
  3. Instruct the skill to focus on the changed lines but consider surrounding context
  4. The skill runs its standard Phase 1 (Discovery) and Phase 2 (Verification) but scoped to changed files

New vs Existing Classification

For each finding:

New finding (introduced by this change):

Confirm "new" by comparing the complete source-to-sink path and effective controls in both base and head. A changed line near an old root cause is not sufficient.

Existing finding (pre-existing, found while scanning touched file):

Regression (re-introduced):

Phase 3: Quick Verification

Apply a lightweight version of sc-verifier logic:

  1. Reachability: Is the changed code reachable from an entry point?
  2. Sanitization: Is there sanitization in the data flow?
  3. Framework protection: Does the framework auto-protect against this?
  4. Context: Is this test code or production code?
  5. Confidence scoring (same 0-100 scale)
  6. Trust boundary: name attacker, affected principal/resource, and meaningful result
  7. Causality: prove which changed behavior introduces or restores the boundary failure
  8. Verdict: confirmed, needs_validation, or rejected; only confirmed records receive severity

Output Format

# Security Diff Report

**Branch:** {branch name}
**Base:** {base branch/commit}
**Date:** {scan date}
**Files Changed:** {N}
**Files Scanned:** {N} (after filtering)

## Summary

| Category | New | Existing | Total |
|----------|-----|----------|-------|
| Critical | {N} | {N} | {N} |
| High | {N} | {N} | {N} |
| Medium | {N} | {N} | {N} |
| Low | {N} | {N} | {N} |

## Verdict

{PASS | WARN | FAIL}

- **PASS**: No new Critical or High findings
- **WARN**: New Medium findings or existing High findings in touched files
- **FAIL**: New Critical or High findings introduced by this change

## New Findings (Introduced by This Change)

### DIFF-001: {Title}
- **Severity:** {severity}
- **Confidence:** {score}/100
- **Classification:** NEW
- **File:** {path}:{line}
- **Diff Context:**

{relevant diff hunk}

- **Description:** {what's wrong}
- **Remediation:** {how to fix before merging}

## Existing Findings (Pre-existing in Touched Files)

### DIFF-NNN: {Title}
- **Classification:** EXISTING
- **Note:** This finding predates this change but was discovered while scanning modified files.
{abbreviated finding details}

## Dependency Changes

| Package | Change | Risk |
|---------|--------|------|
| {name} | Added v{X} | {assessment} |
| {name} | Updated {old} → {new} | {assessment} |
| {name} | Removed | No risk |

## Changed Files Not Scanned
{List of filtered files with reason (docs, generated, assets)}

## Needs Validation
{Unresolved source-grounded leads with exact blockers and no severity}

## Coverage Limits
{Untouched dependencies, call paths, deployment facts, filtered files, and verification limits}

PR Comment Format

For integration with PR workflows, also produce a concise summary suitable for a PR comment:

## Security Scan Results

{PASS ✓ | WARN ⚠ | FAIL ✗}

**New findings:** {N} ({breakdown})
**Existing findings in touched files:** {N}

{If FAIL: list top 3 new critical/high findings with file:line}
{If WARN: brief note on what to review}
{If PASS: "No new security issues detected in this change."}

Performance Considerations

Common False Positives in Diff Mode

  1. Refactored code flagged as new vulnerability — code was moved, not introduced
  2. Test additions flagged — new tests often contain intentionally vulnerable patterns
  3. Configuration for development — dev-only settings in changed config files
  4. Renamed variables — security-sensitive variable renamed but same protection in place
  5. Import reordering — framework imports moved but middleware still applied
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.