Secure At Inception
Proactively scan all newly generated or modified code to prevent security vulnerabilities before they enter the codebase. Provides intelligent scanning decisions, caching, and filtering to focus only on NEW issues.
File Type → Scan Type Reference
| Scan Type |
Trigger Files |
MCP Tool |
| SAST (Code) |
Source files: .js, .ts, .py, .java, .go, .rb, .php, .cs, .swift, .kt, .scala, .rs, .c, .cpp, .dart, and more |
snyk_code_scan |
| SCA (Dependencies) |
Manifests: package.json, requirements.txt, pom.xml, build.gradle, Gemfile, go.mod, Cargo.toml, *.csproj, composer.json, and more |
snyk_sca_scan |
| IaC |
Infrastructure: .tf, .tfvars, K8s YAML (with apiVersion/kind), template.json/.yaml, ARM JSON, serverless.yml |
snyk_iac_scan |
Skip: binary files, non-IaC JSON/YAML, documentation (.md, .txt, .rst), assets, test fixtures.
Phase 1: Change Detection
Step 1.1: Gather Changed Files
Check for changes using one of these methods (in order of preference):
- Git diff (if in a git repo):
git diff --name-only HEAD
git diff --name-only --cached # staged files
git status --porcelain
- Session context: Track files created/modified during the current session
- User-specified path: If user provides a specific file or directory
Step 1.2: Categorize Files by Scan Type
Use the File Type → Scan Type Reference table above to map each changed file to the appropriate scan. IaC YAML is distinguished from generic YAML by the presence of apiVersion/kind (Kubernetes) or AWSTemplateFormatVersion (CloudFormation).
Phase 2: Execute Scans
Run SAST, SCA, and IaC scans in parallel — they are independent of each other. Use the parameters below for each applicable scan type (determined by the File Type → Scan Type Reference table).
Step 2.1: SAST Scan (snyk_code_scan)
path: directory containing changed source files (or project root); scan each file individually if < 5 files changed, otherwise scan the parent directory
severity_threshold: "medium" (default) or as configured
Step 2.2: SCA Scan (snyk_sca_scan)
path: project root or directory containing the manifest
all_projects: true (for monorepos)
severity_threshold: "medium" (default) or as configured
- Note: SCA scans the entire dependency tree, not just direct changes.
Step 2.3: IaC Scan (snyk_iac_scan)
path: directory containing IaC files
severity_threshold: "medium" (default) or as configured
Phase 3: Filter to New Issues
Apply these filters before reporting to surface only issues introduced by the current changes.
SAST: Include a finding only if its file+line falls within a modified line range from git diff -U0. Parse @@ -X,Y +A,B @@ hunks to determine changed ranges; exclude findings outside those ranges as pre-existing.
SCA: Include only if a new or updated package now has MORE vulnerabilities or higher severity than before. Apply the Net Improvement Rule — if the change reduces overall vulnerability count or severity, do NOT block.
IaC: Include only if the misconfiguration is in a newly added or modified resource block.
Phase 4: Report & Decision
Step 4.1: Severity Threshold Configuration
| Mode |
Block On |
Warn On |
Allow |
| Strict |
Low+ |
- |
- |
| Standard |
High+ |
Medium |
Low |
| Relaxed |
Critical only |
High |
Medium, Low |
Step 4.2: Generate Report
## Secure At Inception Scan Results
### Summary
| Scan Type | New Issues | Blocked |
|----------------------|------------|---------|
| Code (SAST) | X | Yes/No |
| Dependencies (SCA) | Y | Yes/No |
| Infrastructure (IaC) | Z | Yes/No |
### New Code Vulnerabilities (SAST)
| Severity | Type | File | Line | Description |
|----------|---------------|------------|------|-----------------------|
| High | SQL Injection | src/db.ts | 45 | User input in query |
### New Dependency Vulnerabilities (SCA)
| Severity | Package | Vulnerability | Fix Version |
|----------|------------------|----------------------|-------------|
| Critical | lodash@4.17.15 | Prototype Pollution | 4.17.21 |
### New Infrastructure Issues (IaC)
| Severity | Resource | Issue | Recommendation |
|----------|----------------|-----------------------|--------------------------|
| High | aws_s3_bucket | Public access enabled | Set block_public_access |
### Recommended Actions
1. `/snyk-fix SNYK-JS-LODASH-1234` - Fix lodash vulnerability
2. Review `src/db.ts:45` for SQL injection fix
### Decision: [BLOCKED / ALLOWED]
[Reason based on severity threshold]
Step 4.3: Block Decision Logic
If any NEW issue severity >= threshold:
BLOCKED - do not proceed until fixed
Provide specific fix commands
Else:
ALLOWED - safe to proceed
Note any warnings for future attention
Phase 5: Track Metrics
After each scan that finds and helps fix issues, run snyk_send_feedback with:
path: project root (absolute path)
preventedIssuesCount: count of NEW issues found (delta, not cumulative)
fixedExistingIssuesCount: 0 (this skill prevents, doesn't fix existing issues)
Only count issues found in NEW code that would have been committed without this scan.
Best Practices
Error Handling
| Situation |
Action |
| Authentication error |
Run snyk_auth and retry; prompt user for manual authentication if still failing |
| Scan timeout |
Retry once with smaller scope; report partial results if still failing |
| No changes detected |
Report "No code changes detected - nothing to scan"; offer full project scan on request |
| Unsupported files only |
Report "No scannable files in changes" with a list of skipped file types and reasons |
Constraints
- New Issues Only: Never block on pre-existing issues (that's remediation's job)
- Minimal Noise: Filter aggressively to avoid alert fatigue
- Fast Feedback: Complete scan within 30 seconds for typical changes
- Non-Destructive: Never modify code, only report findings
- Actionable Output: Every finding must have a clear fix path
1---2name: secure-at-inception3description: Proactive security scanning for newly generated or modified code. Intelligently detects changes, runs appropriate scans (SAST, SCA, IaC), filters to only NEW issues, and prevents vulnerabilities at the source. Use this skill when: - Agent generates new code files - Agent modifies existing code - User asks to "scan for security issues" or "check my changes" - Before committing changes - User mentions "secure at inception", "proactive scan", or "security check"4license: Apache-2.05---6
7# Secure At Inception
8
9Proactively scan all newly generated or modified code to prevent security vulnerabilities before they enter the codebase. Provides intelligent scanning decisions, caching, and filtering to focus only on NEW issues.
10
11---
12
13## File Type → Scan Type Reference
14
15| Scan Type | Trigger Files | MCP Tool |
16|-----------|--------------|----------|
17| SAST (Code) | Source files: `.js`, `.ts`, `.py`, `.java`, `.go`, `.rb`, `.php`, `.cs`, `.swift`, `.kt`, `.scala`, `.rs`, `.c`, `.cpp`, `.dart`, and more | `snyk_code_scan` |
18| SCA (Dependencies) | Manifests: `package.json`, `requirements.txt`, `pom.xml`, `build.gradle`, `Gemfile`, `go.mod`, `Cargo.toml`, `*.csproj`, `composer.json`, and more | `snyk_sca_scan` |
19| IaC | Infrastructure: `.tf`, `.tfvars`, K8s YAML (with `apiVersion`/`kind`), `template.json`/`.yaml`, ARM JSON, `serverless.yml` | `snyk_iac_scan` |
20
21**Skip**: binary files, non-IaC JSON/YAML, documentation (`.md`, `.txt`, `.rst`), assets, test fixtures.
22
23---
24
25## Phase 1: Change Detection
26
27### Step 1.1: Gather Changed Files
28
29Check for changes using one of these methods (in order of preference):
30
311. **Git diff** (if in a git repo):
32 ```bash
33 git diff --name-only HEAD
34 git diff --name-only --cached # staged files
35 git status --porcelain
36 ```
372. **Session context**: Track files created/modified during the current session
383. **User-specified path**: If user provides a specific file or directory
39
40### Step 1.2: Categorize Files by Scan Type
41
42Use the File Type → Scan Type Reference table above to map each changed file to the appropriate scan. IaC YAML is distinguished from generic YAML by the presence of `apiVersion`/`kind` (Kubernetes) or `AWSTemplateFormatVersion` (CloudFormation).
43
44---
45
46## Phase 2: Execute Scans
47
48Run SAST, SCA, and IaC scans in **parallel** — they are independent of each other. Use the parameters below for each applicable scan type (determined by the File Type → Scan Type Reference table).
49
50### Step 2.1: SAST Scan (`snyk_code_scan`)
51- `path`: directory containing changed source files (or project root); scan each file individually if < 5 files changed, otherwise scan the parent directory
52- `severity_threshold`: `"medium"` (default) or as configured
53
54### Step 2.2: SCA Scan (`snyk_sca_scan`)
55- `path`: project root or directory containing the manifest
56- `all_projects`: `true` (for monorepos)
57- `severity_threshold`: `"medium"` (default) or as configured
58- Note: SCA scans the entire dependency tree, not just direct changes.
59
60### Step 2.3: IaC Scan (`snyk_iac_scan`)
61- `path`: directory containing IaC files
62- `severity_threshold`: `"medium"` (default) or as configured
63
64---
65
66## Phase 3: Filter to New Issues
67
68Apply these filters before reporting to surface only issues introduced by the current changes.
69
70**SAST**: Include a finding only if its file+line falls within a modified line range from `git diff -U0`. Parse `@@ -X,Y +A,B @@` hunks to determine changed ranges; exclude findings outside those ranges as pre-existing.
71
72**SCA**: Include only if a new or updated package now has MORE vulnerabilities or higher severity than before. Apply the **Net Improvement Rule** — if the change reduces overall vulnerability count or severity, do NOT block.
73
74**IaC**: Include only if the misconfiguration is in a newly added or modified resource block.
75
76---
77
78## Phase 4: Report & Decision
79
80### Step 4.1: Severity Threshold Configuration
81
82| Mode | Block On | Warn On | Allow |
83|------|----------|---------|-------|
84| Strict | Low+ | - | - |
85| Standard | High+ | Medium | Low |
86| Relaxed | Critical only | High | Medium, Low |
87
88### Step 4.2: Generate Report
89
90```
91## Secure At Inception Scan Results
92
93### Summary
94| Scan Type | New Issues | Blocked |
95|----------------------|------------|---------|
96| Code (SAST) | X | Yes/No |
97| Dependencies (SCA) | Y | Yes/No |
98| Infrastructure (IaC) | Z | Yes/No |
99
100### New Code Vulnerabilities (SAST)
101| Severity | Type | File | Line | Description |
102|----------|---------------|------------|------|-----------------------|
103| High | SQL Injection | src/db.ts | 45 | User input in query |
104
105### New Dependency Vulnerabilities (SCA)
106| Severity | Package | Vulnerability | Fix Version |
107|----------|------------------|----------------------|-------------|
108| Critical | lodash@4.17.15 | Prototype Pollution | 4.17.21 |
109
110### New Infrastructure Issues (IaC)
111| Severity | Resource | Issue | Recommendation |
112|----------|----------------|-----------------------|--------------------------|
113| High | aws_s3_bucket | Public access enabled | Set block_public_access |
114
115### Recommended Actions
1161. `/snyk-fix SNYK-JS-LODASH-1234` - Fix lodash vulnerability
1172. Review `src/db.ts:45` for SQL injection fix
118
119### Decision: [BLOCKED / ALLOWED]
120[Reason based on severity threshold]
121```
122
123### Step 4.3: Block Decision Logic
124
125```
126If any NEW issue severity >= threshold:
127 BLOCKED - do not proceed until fixed
128 Provide specific fix commands
129Else:
130 ALLOWED - safe to proceed
131 Note any warnings for future attention
132```
133
134---
135
136## Phase 5: Track Metrics
137
138After each scan that finds and helps fix issues, run `snyk_send_feedback` with:
139- `path`: project root (absolute path)
140- `preventedIssuesCount`: count of NEW issues found (delta, not cumulative)
141- `fixedExistingIssuesCount`: `0` (this skill prevents, doesn't fix existing issues)
142
143Only count issues found in NEW code that would have been committed without this scan.
144
145---
146
147## Best Practices
148
149- **Run automatically** after generating or modifying code, and before suggesting a commit; also on request for explicit security checks.
150- **Cache results** keyed by `file + content_hash` with a 12-hour TTL; only rescan changed files and batch by directory.
151- **False positives**: Use a `.snyk` policy file to suppress confirmed false positives, then re-run to verify:
152 ```yaml
153 ignore:
154 SNYK-JS-EXAMPLE-12345:
155 - '*':
156 reason: 'False positive - input is validated upstream'
157 expires: 2025-12-31
158 ```
159- **Threshold tuning**: Start with Standard mode; switch to Relaxed if blocks are too frequent, or Strict after low/medium severity incidents.
160- **CI/CD integration**: Invoke on pull request creation or pushes to feature branches; block merge if threshold is exceeded.
161
162---
163
164## Error Handling
165
166| Situation | Action |
167|-----------|--------|
168| Authentication error | Run `snyk_auth` and retry; prompt user for manual authentication if still failing |
169| Scan timeout | Retry once with smaller scope; report partial results if still failing |
170| No changes detected | Report "No code changes detected - nothing to scan"; offer full project scan on request |
171| Unsupported files only | Report "No scannable files in changes" with a list of skipped file types and reasons |
172
173---
174
175## Constraints
176
1771. **New Issues Only**: Never block on pre-existing issues (that's remediation's job)
1782. **Minimal Noise**: Filter aggressively to avoid alert fatigue
1793. **Fast Feedback**: Complete scan within 30 seconds for typical changes
1804. **Non-Destructive**: Never modify code, only report findings
1815. **Actionable Output**: Every finding must have a clear fix path