Threat Patch
Reads security findings and produces minimal, surgical code patches with structured documentation. Fixes are code-grounded — each patch targets specific files and functions identified in the finding. Output includes a summary, validation steps, and the code changes.
When to Apply
- User provides a
findings.json (from threat-model) and wants fixes
- User provides a Codex security findings CSV and wants fixes
- User has a THREAT-MODEL.md and wants to remediate identified risks
- User describes a specific vulnerability and wants a patch
- Reviewing security scanner output and needs actionable fixes
- After a security audit, turning findings into code changes
Input Sources (priority order)
| Source |
What It Provides |
How to Use |
| findings.json (from threat-model) |
Structured findings with data flow traces, systemic groupings, exploit chains, and severity ratings |
Read directly — richest input, already triaged and grouped |
| Codex CSV |
Title, description, severity, relevant_paths per finding |
Run scripts/parse-findings.sh <csv-path> to extract structured output |
| THREAT-MODEL.md |
Human-readable threat model |
Extract findings from Criticality Calibration section |
| Inline description |
User describes a specific vulnerability |
Parse from conversation context |
When findings.json is available, it's the preferred input — it includes data flow traces (entry → chain → sink) that directly inform where to apply fixes, and systemic groupings that suggest centralized fixes over individual patches.
Workflow Overview
1. Ingest Findings → Read findings.json / CSV / descriptions
2. Triage & Group → Sort by severity, use systemic groupings if available
3. For each finding:
a. Read Code → Open relevant_paths, understand the pattern
b. Confirm → Verify issue is still present in HEAD
c. Design Fix → Determine minimal fix approach
d. Implement → Write the code changes
e. Document → Summary + Validation + Attack-path (if needed)
f. Test → Run relevant tests
4. Output → Per-patch deliverable with summary and diff
5. Update State → Mark patched findings in findings.json (if present)
How to Use
- Read workflow for the detailed patching methodology at each step
- Read fix patterns when designing fixes — common patterns by vulnerability class
- Read output format for the documentation template per patch
- If input is findings.json: read it directly — it's already structured
- If input is Codex CSV: run
scripts/parse-findings.sh <csv-path> to extract structured output
Key Principles
- Minimal diff: Fix the vulnerability, don't refactor surrounding code. The smallest correct patch is the best patch
- Centralize over duplicate: When multiple code paths share the same vulnerability pattern, extract a shared helper rather than patching each site independently
- Explicit error paths: Add specific error types for rejected inputs with clear operator feedback, not silent failures or generic errors
- Confirm before fixing: Always verify the finding is still present in HEAD — code may have moved or been refactored since the finding was detected
- User approval before edits: Present the fix design (files to change, approach) and wait for approval before modifying source code. Hooks gate Edit/Write tool calls for additional safety
- Document even failures: When a fix can't be tested due to environment limitations, document the test command and the limitation
Guardrails
This skill modifies source code. Safety measures:
- PreToolUse hooks on Edit and Write tools prompt for confirmation before each file change
- Confirmation gate in the workflow between fix design and implementation
- Revert path: Without commits (default), use
git checkout -- <files> to undo. With commits, use git revert
Output Modes
Code patch — when a fix is implemented:
- Summary of what was confirmed and what the fix does
- Testing section with build/test commands
- The actual code changes
Analysis only — when the fix needs user decision or architectural changes:
- Summary of what was confirmed
- Validation checklist
- Attack-path analysis (path, likelihood, impact, assumptions, controls, blindspots)
References
| File |
When to Read |
| references/workflow.md |
Before starting — detailed approach for each patching phase |
| references/fix-patterns.md |
When designing fixes — patterns by vulnerability class |
| references/output-format.md |
When documenting — templates for both output modes |
1---2name: threat-patch3description: Remediate security findings by producing minimal, surgical code patches. Triggers on 'patch security findings', 'fix vulnerabilities', 'remediate findings', 'threat patch', or when the user provides a findings.json (from threat-model), a Codex security findings CSV, a THREAT-MODEL.md, or individual vulnerability descriptions and wants them fixed. Also trigger when reviewing code flagged by a security scanner and the user wants actionable fixes rather than just reports.4---5# Threat Patch
6
7Reads security findings and produces minimal, surgical code patches with structured documentation. Fixes are code-grounded — each patch targets specific files and functions identified in the finding. Output includes a summary, validation steps, and the code changes.
8
9## When to Apply
10
11- User provides a `findings.json` (from threat-model) and wants fixes
12- User provides a Codex security findings CSV and wants fixes
13- User has a THREAT-MODEL.md and wants to remediate identified risks
14- User describes a specific vulnerability and wants a patch
15- Reviewing security scanner output and needs actionable fixes
16- After a security audit, turning findings into code changes
17
18## Input Sources (priority order)
19
20| Source | What It Provides | How to Use |
21|--------|-----------------|-----------|
22| **findings.json** (from threat-model) | Structured findings with data flow traces, systemic groupings, exploit chains, and severity ratings | Read directly — richest input, already triaged and grouped |
23| **Codex CSV** | Title, description, severity, relevant_paths per finding | Run `scripts/parse-findings.sh <csv-path>` to extract structured output |
24| **THREAT-MODEL.md** | Human-readable threat model | Extract findings from Criticality Calibration section |
25| **Inline description** | User describes a specific vulnerability | Parse from conversation context |
26
27When `findings.json` is available, it's the preferred input — it includes data flow traces (entry → chain → sink) that directly inform where to apply fixes, and systemic groupings that suggest centralized fixes over individual patches.
28
29## Workflow Overview
30
31```
321. Ingest Findings → Read findings.json / CSV / descriptions
332. Triage & Group → Sort by severity, use systemic groupings if available
343. For each finding:
35 a. Read Code → Open relevant_paths, understand the pattern
36 b. Confirm → Verify issue is still present in HEAD
37 c. Design Fix → Determine minimal fix approach
38 d. Implement → Write the code changes
39 e. Document → Summary + Validation + Attack-path (if needed)
40 f. Test → Run relevant tests
414. Output → Per-patch deliverable with summary and diff
425. Update State → Mark patched findings in findings.json (if present)
43```
44
45## How to Use
46
471. Read [workflow](references/workflow.md) for the detailed patching methodology at each step
482. Read [fix patterns](references/fix-patterns.md) when designing fixes — common patterns by vulnerability class
493. Read [output format](references/output-format.md) for the documentation template per patch
504. If input is findings.json: read it directly — it's already structured
515. If input is Codex CSV: run `scripts/parse-findings.sh <csv-path>` to extract structured output
52
53## Key Principles
54
55- **Minimal diff**: Fix the vulnerability, don't refactor surrounding code. The smallest correct patch is the best patch
56- **Centralize over duplicate**: When multiple code paths share the same vulnerability pattern, extract a shared helper rather than patching each site independently
57- **Explicit error paths**: Add specific error types for rejected inputs with clear operator feedback, not silent failures or generic errors
58- **Confirm before fixing**: Always verify the finding is still present in HEAD — code may have moved or been refactored since the finding was detected
59- **User approval before edits**: Present the fix design (files to change, approach) and wait for approval before modifying source code. Hooks gate Edit/Write tool calls for additional safety
60- **Document even failures**: When a fix can't be tested due to environment limitations, document the test command and the limitation
61
62## Guardrails
63
64This skill modifies source code. Safety measures:
65- **PreToolUse hooks** on Edit and Write tools prompt for confirmation before each file change
66- **Confirmation gate** in the workflow between fix design and implementation
67- **Revert path**: Without commits (default), use `git checkout -- <files>` to undo. With commits, use `git revert`
68
69## Output Modes
70
71**Code patch** — when a fix is implemented:
72- Summary of what was confirmed and what the fix does
73- Testing section with build/test commands
74- The actual code changes
75
76**Analysis only** — when the fix needs user decision or architectural changes:
77- Summary of what was confirmed
78- Validation checklist
79- Attack-path analysis (path, likelihood, impact, assumptions, controls, blindspots)
80
81## References
82
83| File | When to Read |
84|------|-------------|
85| [references/workflow.md](references/workflow.md) | Before starting — detailed approach for each patching phase |
86| [references/fix-patterns.md](references/fix-patterns.md) | When designing fixes — patterns by vulnerability class |
87| [references/output-format.md](references/output-format.md) | When documenting — templates for both output modes |