npx skills add ...
npx skills add factory-ai/skills --skill commit-security-scan
npx skills add factory-ai/skills --skill 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.
The same skill content is published under more than one repo. The install counts are split across them; any of these commands works.
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:
Trace data flow: Follow user input from source to sink
Check for existing mitigations:
Determine severity:
Assess confidence:
Create security-findings.json with this structure:
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 staged changes before committing:
Scan a feature branch:
Scan recent commits:
analysis-examples.md (in this skill directory).factory/threat-model.md.factory/security-config.jsonScan PR #123 for security vulnerabilitiesScan my staged changes for security issuesScan changes from main to feature/user-auth for vulnerabilitiesScan the last 5 commits for security issues