Complete security remediation workflow. Scans code for vulnerabilities using Snyk, fixes them, validates the fix, and optionally creates a PR. Supports both single-issue and batch mode for multiple vulnerabilities. Use this skill when: - User asks to fix security vulnerabilities - User mentions "snyk fix", "security fix", or "remediate vulnerabilities" - User wants to fix a specific CVE, Snyk ID, or vulnerability type (XSS, SQL injection, path traversal, etc.) - User wants to upgrade a vulnerable dependency - User asks to "fix all" vulnerabilities or "fix all high/critical" issues (batch mode)
Complete security remediation workflow in a single command. Scans for vulnerabilities, fixes them, validates the fix, and optionally creates a PR.
Workflow: Parse → Scan → Analyze → Fix → Validate → Summary → (Optional) PR
Modes:
| User Request | Behavior |
|---|---|
| "fix security issues" | Auto-detect scan type, fix highest priority issue (all instances) |
| "fix code vulnerabilities" | SAST scan only, fix highest priority code issue (all instances in file) |
| "fix dependency vulnerabilities" | SCA scan only, fix highest priority dependency issue |
| "fix SNYK-JS-LODASH-1018905" | Fix specific Snyk issue by ID |
| "fix CVE-2021-44228" | Find and fix specific CVE |
| "fix vulnerabilities in lodash" | Fix highest priority issue in lodash package |
| "fix security issues in server.ts" | Code scan on file, fix highest priority issue (all instances) |
| "fix XSS vulnerabilities" | Fix all XSS vulnerabilities in highest priority file |
| "fix path traversal" | Fix all path traversal vulnerabilities |
| User Request | Behavior |
|---|---|
| "fix all security issues" | Fix ALL vulnerabilities by priority (Critical → Low) |
| "fix all critical vulnerabilities" | Fix only Critical severity issues |
| "fix all high and critical" | Fix Critical and High severity issues |
| "fix all code vulnerabilities" | Fix all SAST issues in the project |
| "fix all dependency issues" | Fix all SCA issues in the project |
| "fix top 5 vulnerabilities" | Fix the 5 highest priority issues |
| "fix all issues in src/" | Fix all vulnerabilities in specified directory |
Batch mode fixes multiple vulnerabilities in a single session. Use when the user says "all", "batch", or specifies a severity filter.
1. Scan entire project (SAST + SCA)
2. Filter by severity/type if specified
3. Group vulnerabilities by type and priority
4. For each group (in priority order):
a. Fix all instances of that vulnerability type
b. Validate the fix
c. Track results
5. Generate comprehensive summary
6. Prompt for single PR with all fixes| Setting | Value | Notes |
|---|---|---|
| Max vulnerabilities | 20 | To avoid overwhelming changes |
| Max files modified | 15 | To keep PRs reviewable |
| Timeout per fix | 3 attempts | Same as single mode |
| Stop on failure | Configurable | Can continue or stop |
Within same priority: Code (SAST) issues before SCA issues (code fixes are typically more urgent).
Parse user input to extract:
code, sca, both) or infer from contextBatch Mode Indicators:
Single Mode (default):
SNYK- → run both scans to locate itCVE- → run both scans to find it.ts, .js, .py, etc. file → Code scan on that fileOnly execute this phase if Batch Mode was detected in Phase 1.
Run comprehensive scans to discover all vulnerabilities:
Run both scans:
- mcp_snyk_snyk_code_scan with path = project root
- mcp_snyk_snyk_sca_scan with path = project rootApply user-specified filters:
| Filter | Example | Result |
|---|---|---|
| Severity | "critical only" | Only Critical vulns |
| Severity | "high and critical" | Critical + High |
| Type | "code vulnerabilities" | Only SAST results |
| Type | "dependency issues" | Only SCA results |
| Path | "in src/" | Only vulns in src/ |
| Count | "top 5" | First 5 by priority |
Group vulnerabilities for efficient fixing:
Display the batch fix plan to user:
## Batch Fix Plan
**Mode**: Batch Remediation
**Filter**: [severity/type/path filter if any]
**Total Vulnerabilities**: [count]
### Fix Order
| # | Type | Severity | Target | Instances |
|---|------|----------|--------|-----------|
| 1 | Code | High | SQL Injection in db.ts | 3 |
| 2 | SCA | Critical | log4j-core@2.14.1 | 1 |
| 3 | Code | High | XSS in api/render.ts | 2 |
| 4 | SCA | High | lodash@4.17.15 | 1 |
| 5 | Code | High | Path Traversal in files.ts | 4 |
**Estimated Changes**: [X files, Y packages]
### Proceed with batch fix? (yes/no/adjust)Wait for user confirmation before proceeding.
If user says "adjust", allow them to modify the plan (exclude items, change order, etc.).
For each vulnerability group in the plan:
stop_on_failure=true: Stop and reportstop_on_failure=false: Continue to next itemAfter all fixes attempted, proceed to Phase 6B (Batch Summary).
Goal: Run scan(s) and identify the vulnerability type to fix, including ALL instances of that type in the same file (for code vulnerabilities)
Based on scan type detection:
mcp_snyk_snyk_code_scan with path set to project root or specific filemcp_snyk_snyk_sca_scan with path set to project rootIf user specified a vulnerability:
If user did NOT specify a vulnerability:
IMPORTANT for Code vulnerabilities: After selecting the vulnerability type, find ALL instances of that same vulnerability type in the same file:
javascript/PT, javascript/XSS, python/SQLi)Example: If scan finds:
High Path Traversal src/api/files.ts:45 javascript/PT
High Path Traversal src/api/files.ts:112 javascript/PT
High XSS src/api/files.ts:78 javascript/XSSAnd Path Traversal is selected as highest priority, target BOTH lines 45 and 112.
For Code vulnerabilities:
## Target Vulnerability
- **Type**: Code (SAST)
- **ID**: [Snyk ID] (e.g., javascript/PT)
- **Severity**: [Critical | High | Medium | Low]
- **Title**: [vulnerability title]
- **CWE**: [CWE-XXX if available]
- **Instances to Fix**: [count]
| # | File | Line | Description |
|---|------|------|-------------|
| 1 | [file] | [line] | [brief context] |
| 2 | [file] | [line] | [brief context] |For SCA vulnerabilities:
## Target Vulnerability
- **Type**: SCA (Dependency)
- **ID**: [Snyk Issue ID]
- **Severity**: [Critical | High | Medium | Low]
- **Package**: [package@current_version]
- **Title**: [vulnerability title]
- **Fix Version**: [minimum version that fixes]
- **Dependency Path**: [direct | transitive via X → Y → Z]Skip to Phase 4 if this is an SCA vulnerability.
Before implementing, document the approach:
## Fix Plan
- **Vulnerability Type**: [type]
- **Root Cause**: [why the code is vulnerable]
- **Fix Approach**: [what will be changed]
- **Security Mechanism**: [what protection is being added]
- **Instances Affected**: [count] locations in [file]Common fix patterns:
| Vulnerability | Fix Pattern |
|---|---|
| SQL Injection | Parameterized queries / prepared statements |
| Command Injection | Input validation + shell escaping or avoid shell |
| Path Traversal | Canonicalize path + validate against allowed base |
| XSS | Output encoding / sanitization appropriate to context |
| Sensitive Data Exposure | Remove/mask data, use secure headers |
| Hardcoded Secrets | Move to environment variables / secrets manager |
Order of fixes: Fix from bottom of file to top (highest line number first) to avoid line number shifts affecting subsequent fixes.
Continue to Phase 5 (Validation).
Skip to Phase 5 if this is a Code vulnerability (already handled in Phase 3).
package.json, requirements.txt, etc.)For transitive dependencies:
Search codebase for potential impact:
# Search for imports of the package
grep -r "from 'package'" --include="*.ts" --include="*.js"
grep -r "require('package')" --include="*.ts" --include="*.js"If complex breaking changes detected:
Example (package.json):
// Before
"lodash": "^4.17.15"
// After - minimal fix
"lodash": "^4.17.21"Run the appropriate install command:
| Package Manager | Command |
|---|---|
| npm (major upgrade) | npm install <pkg>@<version> |
| npm (minor/patch) | npm install |
| yarn | yarn install or yarn upgrade <pkg>@<version> |
| pip | pip install -r requirements.txt |
| maven | mvn dependency:resolve |
If installation fails:
mcp_snyk_snyk_code_scan or mcp_snyk_snyk_sca_scan on the same targetFor Code vulnerabilities - If any instances still present:
For SCA vulnerabilities - If vulnerability still present:
npm install <pkg>@<exact_version>If NEW vulnerabilities introduced:
For Code:
For SCA:
A single upgrade often fixes multiple vulnerabilities:
npm test, pytest, etc.)For Code vulnerabilities (single or multiple instances):
## Remediation Summary
| Remediated Vulnerability | [Title] ([CWE-XXX]) |
|--------------------------|---------------------|
| **Snyk ID** | [javascript/PT, python/XSS, etc.] |
| **Severity** | [Critical/High/Medium/Low] |
| **Instances Fixed** | [count] |
| # | File | Line | Status |
|---|------|------|--------|
| 1 | [file] | [line] | ✅ Fixed |
| 2 | [file] | [line] | ✅ Fixed |
### What Was Fixed
[2-3 sentence plain-English explanation of the vulnerability and how it was fixed. No code snippets.]
### Validation
| Check | Result |
|-------|--------|
| Snyk Re-scan | ✅ Resolved ([count] instances) / ❌ Still present |
| TypeScript/Build | ✅ Pass / ❌ Fail |
| Linting | ✅ Pass / ❌ Fail |
| Tests | ✅ Pass / ⚠️ Skipped (reason) / ❌ Fail |
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
## Should I create a PR for this fix? (yes / no)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━For SCA vulnerabilities:
## Remediation Summary
| Remediated Vulnerability | [Title] |
|--------------------------|---------|
| **Snyk ID** | [SNYK-JS-XXX / CVE-XXX] |
| **Severity** | [Critical/High/Medium/Low] |
| **Package** | [package@old] → [package@new] |
### Additional Issues Fixed by This Upgrade
| ID | Severity | Title |
|----|----------|-------|
| [Snyk ID] | [severity] | [title] |
**Total issues fixed**: [count]
### What Was Fixed
[2-3 sentence plain-English explanation of the vulnerability and how it was fixed.]
### Validation
| Check | Result |
|-------|--------|
| Snyk Re-scan | ✅ Resolved / ❌ Still present |
| TypeScript/Build | ✅ Pass / ❌ Fail |
| Linting | ✅ Pass / ❌ Fail |
| Tests | ✅ Pass / ⚠️ Skipped (reason) / ❌ Fail |
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
## Should I create a PR for this fix? (yes / no)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━Rules for this summary:
After successful fix, report the remediation using mcp_snyk_snyk_send_feedback:
IMPORTANT: Do NOT proceed until the user explicitly confirms.
Only execute this phase after completing all batch fixes.
## Batch Remediation Summary
### Overall Results
| Metric | Count |
|--------|-------|
| Vulnerabilities Attempted | [total] |
| Successfully Fixed | [count] |
| Partially Fixed | [count] |
| Failed | [count] |
| Skipped | [count] |
### Issues Fixed by Severity
| Severity | Fixed | Remaining |
|----------|-------|-----------|
| Critical | X/Y | Z |
| High | X/Y | Z |
| Medium | X/Y | Z |
| Low | X/Y | Z |
### Detailed Results
#### Code Vulnerabilities Fixed
| # | Vulnerability | File | Instances | Status |
|---|---------------|------|-----------|--------|
| 1 | SQL Injection | db.ts | 3/3 | ✅ Fixed |
| 2 | XSS | api/render.ts | 2/2 | ✅ Fixed |
| 3 | Path Traversal | files.ts | 3/4 | ⚠️ Partial |
#### Dependency Vulnerabilities Fixed
| # | Package | Old → New | CVEs Fixed | Status |
|---|---------|-----------|------------|--------|
| 1 | log4j-core | 2.14.1 → 2.17.1 | 3 | ✅ Fixed |
| 2 | lodash | 4.17.15 → 4.17.21 | 2 | ✅ Fixed |
### Files Modified
- src/db.ts
- src/api/render.ts
- src/files.ts
- package.json
- package-lock.json
### Validation Results
| Check | Result |
|-------|--------|
| Snyk Code Re-scan | ✅ [X] issues resolved |
| Snyk SCA Re-scan | ✅ [Y] issues resolved |
| Build | ✅ Pass |
| Tests | ✅ Pass |
| Lint | ✅ Pass |
### Issues NOT Fixed
| Vulnerability | Reason |
|---------------|--------|
| SSRF in external.ts | Complex refactoring required |
| minimist@1.2.5 | No fix version available |
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
## Should I create a single PR for all these fixes? (yes / no)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━Report all fixes to Snyk:
Run mcp_snyk_snyk_send_feedback with:
- path: [project root]
- fixedExistingIssuesCount: [total issues fixed across all vulns]
- preventedIssuesCount: 0If user confirms PR for batch fixes:
Branch naming for batch:
fix/security-batch-YYYYMMDDfix/security-critical-high-batchCommit strategy:
Default to Option 1 unless user prefers separate commits.
PR Body for Batch:
## Security Fixes (Batch)
This PR addresses multiple security vulnerabilities identified by Snyk.
### Summary
- **Code vulnerabilities fixed**: [count]
- **Dependency vulnerabilities fixed**: [count]
- **Total CVEs resolved**: [count]
### Code Fixes
| Vulnerability | File | CWE | Severity |
|---------------|------|-----|----------|
| SQL Injection | db.ts | CWE-89 | Critical |
| XSS | render.ts | CWE-79 | High |
| Path Traversal | files.ts | CWE-22 | High |
### Dependency Upgrades
| Package | Old | New | CVEs Fixed |
|---------|-----|-----|------------|
| log4j-core | 2.14.1 | 2.17.1 | 3 |
| lodash | 4.17.15 | 4.17.21 | 2 |
### Validation
- [x] Snyk scans pass
- [x] Tests pass
- [x] No new vulnerabilities introduced
### Review Notes
Each fix was validated independently before inclusion in this batch.Only execute if user says "yes" to PR prompt.
git statusVerify:
If no changes found: Report "No uncommitted changes to commit" and STOP
Format: fix/security-<identifier>
Examples:
fix/security-SNYK-JS-LODASH-1018905fix/security-cwe-79-xssfix/security-path-traversal-serverfix/security-lodash-upgradegit checkout -b fix/security-<identifier>Stage only files related to the security fix:
git add <files>Do NOT stage:
Create commit:
git commit -m "fix(security): <description>
Resolves: [Snyk ID or CVE]
Severity: [Critical/High/Medium/Low]"git push -u origin fix/security-<identifier>gh pr create \
--title "Security: <title>" \
--body "<body>" \
--base mainPR Body Template:
## Security Fix
### Vulnerability Details
- **ID**: [Snyk ID or CVE]
- **Severity**: [Critical | High | Medium | Low]
- **Type**: [SCA | Code]
### Changes Made
[Description of the fix]
### Files Changed
- [list files]
### Validation
- [x] Snyk scan passes
- [x] Tests pass
- [x] No new vulnerabilities introducedIMPORTANT:
--label flags (labels may not exist in repo)## PR Created Successfully
- **PR URL**: [URL]
- **Branch**: fix/security-<identifier>
- **Title**: [PR title]
- **Status**: Ready for review
### Next Steps
1. Review the PR at the URL above
2. Request reviews from team members
3. Merge when approvedmcp_snyk_snyk_auth and retry onceIf the vulnerability cannot be fixed automatically:
If no upgrade path exists:
If some instances are fixed but others fail:
Revert ALL changes if:
| Error | Resolution |
|---|---|
| Not a git repository | STOP - cannot create PR |
| Branch already exists | Generate unique branch name with timestamp |
| SSH key error | Retry command |
| Not authenticated (gh) | Suggest gh auth login |
Before ending the conversation, verify ALL are complete:
Before ending the conversation, verify ALL are complete:
9293725
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.