factory-ai/commit-security-scan
Analyze code changes for security vulnerabilities using LLM reasoning and threat model patterns. Use for PR reviews, pre-commit checks, or branch comparisons.
npx skills add https://github.com/Factory-AI/factory-plugins --skill commit-security-scan
Analyze code changes (commits, PRs, diffs) using LLM-powered reasoning to detect security vulnerabilities. This skill reads code directly and applies patterns from the repository's threat model to identify issues across all STRIDE categories.
This skill requires:
.factory/threat-model.md must exist.factory/security-config.json for severity thresholdsIMPORTANT: If these files don't exist, you MUST generate them first before proceeding with the security scan.
To generate the prerequisites:
threat-model-generation skill to create both filesDo NOT ask the user to run the skill manually - just do it automatically as part of this workflow.
The skill determines what to scan from the user's request:
| Scan Type | How to Specify | Example |
| ----------------- | -------------------------- | -------------------------------------------- |
| PR | "Scan PR #123" | Scan PR #456 for security vulnerabilities |
| Commit range | "Scan commits X..Y" | Scan commits abc123..def456 |
| Single commit | "Scan commit X" | Scan commit abc123 |
| Staged changes | "Scan staged changes" | Scan my staged changes for security issues |
| Uncommitted | "Scan uncommitted changes" | Scan working directory changes |
| Branch comparison | "Scan from X to Y" | Scan changes from main to feature-branch |
| Last N commits | "Scan last N commits" | Scan the last 3 commits |
If no scope is specified, prompt the user for clarification.
Follow these steps in order:
Try to read these files:
.factory/threat-model.md.factory/security-config.jsonIf either file is missing or cannot be read:
threat-model-generation skill to analyze the repository and create both filesThis ensures the security scan always has the threat model context it needs for accurate analysis.
Based on the user's request, get the list of changed files and their diffs using git:
gh pr diffgit diff or git showgit diff --cachedRead the full content of each changed file for context.
Read .factory/threat-model.md and .factory/security-config.json to understand:
For each changed file, systematically check for STRIDE threats:
eval(), exec()For each potential vulnerability:
Create security-findings.json with this structure:
{
"scan_id": "scan-YYYY-MM-DD-XXX",
"scan_date": "<ISO 8601 timestamp>",
"scan_type": "pr|commit|range|staged|working",
"commit_range": "<base>..<head>",
"pr_number": null,
"threat_model_version": "<from security-config.json>",
"findings": [
{
"id": "VULN-001",
"severity": "HIGH",
"stride_category": "Tampering",
"vulnerability_type": "SQL Injection",
"cwe": "CWE-89",
"file": "src/api/users.py",
"line_range": "45-49",
"code_context": "<vulnerable code snippet>",
"analysis": "<explanation of why this is vulnerable>",
"exploit_scenario": "<how an attacker could exploit this>",
"threat_model_reference": "Section 5.2 - SQL Injection",
"existing_mitigations": [],
"recommended_fix": "<how to fix the vulnerability>",
"confidence": "HIGH",
"reasoning": "<why this confidence level>"
}
],
"summary": {
"total_findings": 0,
"by_severity": { "CRITICAL": 0, "HIGH": 0, "MEDIUM": 0, "LOW": 0 },
"by_stride": {
"Spoofing": 0,
"Tampering": 0,
"Repudiation": 0,
"InfoDisclosure": 0,
"DoS": 0,
"ElevationOfPrivilege": 0
},
"files_analyzed": 0
}
}
security-findings.jsonsecurity-config.json and note if any are triggeredCommon CWE mappings for findings:
| Vulnerability Type | CWE |
| ------------------------ | ------- |
| SQL Injection | CWE-89 |
| Command Injection | CWE-78 |
| XSS (Reflected) | CWE-79 |
| XSS (Stored) | CWE-79 |
| Path Traversal | CWE-22 |
| IDOR | CWE-639 |
| Missing Authentication | CWE-306 |
| Missing Authorization | CWE-862 |
| Hardcoded Credentials | CWE-798 |
| Sensitive Data Exposure | CWE-200 |
| Mass Assignment | CWE-915 |
| Open Redirect | CWE-601 |
| SSRF | CWE-918 |
| XXE | CWE-611 |
| Insecure Deserialization | CWE-502 |
Scan a PR:
Scan PR #123 for security vulnerabilities
Scan staged changes before committing:
Scan my staged changes for security issues
Scan a feature branch:
Scan changes from main to feature/user-auth for vulnerabilities
Scan recent commits:
Scan the last 5 commits for security issues
analysis-examples.md (in this skill directory).factory/threat-model.md.factory/security-config.jsonTake factory-ai/commit-security-scan from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.