secure-at-inception
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSecure 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: | |
| SCA (Dependencies) | Manifests: | |
| IaC | Infrastructure: | |
Skip: binary files, non-IaC JSON/YAML, documentation (, , ), assets, test fixtures.
.md.txt.rst| 扫描类型 | 触发文件 | MCP工具 |
|---|---|---|
| SAST(代码扫描) | 源代码文件: | |
| SCA(依赖扫描) | 清单文件: | |
| IaC | 基础设施文件: | |
跳过扫描:二进制文件、非IaC格式的JSON/YAML、文档(、、)、资源文件、测试用例。
.md.txt.rstPhase 1: Change Detection
阶段1:变更检测
Step 1.1: Gather Changed Files
步骤1.1:收集变更文件
Check for changes using one of these methods (in order of preference):
- Git diff (if in a git repo):
bash
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
通过以下方法(按优先级排序)检查变更:
- Git diff(若处于Git仓库中):
bash
git diff --name-only HEAD git diff --name-only --cached # 已暂存文件 git status --porcelain - 会话上下文:追踪当前会话中创建/修改的文件
- 用户指定路径:若用户提供了特定文件或目录
Step 1.2: Categorize Files by Scan Type
步骤1.2:按扫描类型分类文件
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 / (Kubernetes) or (CloudFormation).
apiVersionkindAWSTemplateFormatVersion使用上述“文件类型→扫描类型参考表”,将每个变更文件映射到对应的扫描类型。IaC YAML与通用YAML的区别在于是否包含/(Kubernetes)或(CloudFormation)字段。
apiVersionkindAWSTemplateFormatVersionPhase 2: Execute Scans
阶段2:执行扫描
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).
并行运行SAST、SCA和IaC扫描——三者相互独立。根据“文件类型→扫描类型参考表”确定适用的扫描类型,并使用以下参数执行扫描。
Step 2.1: SAST Scan (snyk_code_scan
)
snyk_code_scan步骤2.1:SAST扫描(snyk_code_scan
)
snyk_code_scan- : directory containing changed source files (or project root); scan each file individually if < 5 files changed, otherwise scan the parent directory
path - :
severity_threshold(default) or as configured"medium"
- :包含变更源代码的目录(或项目根目录);若变更文件少于5个则单独扫描每个文件,否则扫描父目录
path - :
severity_threshold(默认)或自定义配置值"medium"
Step 2.2: SCA Scan (snyk_sca_scan
)
snyk_sca_scan步骤2.2:SCA扫描(snyk_sca_scan
)
snyk_sca_scan- : project root or directory containing the manifest
path - :
all_projects(for monorepos)true - :
severity_threshold(default) or as configured"medium" - Note: SCA scans the entire dependency tree, not just direct changes.
- :项目根目录或包含清单文件的目录
path - :
all_projects(适用于单体仓库)true - :
severity_threshold(默认)或自定义配置值"medium" - 注意:SCA扫描整个依赖树,而非仅直接变更的依赖。
Step 2.3: IaC Scan (snyk_iac_scan
)
snyk_iac_scan步骤2.3:IaC扫描(snyk_iac_scan
)
snyk_iac_scan- : directory containing IaC files
path - :
severity_threshold(default) or as configured"medium"
- :包含IaC文件的目录
path - :
severity_threshold(默认)或自定义配置值"medium"
Phase 3: Filter to New Issues
阶段3:过滤新问题
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 . Parse hunks to determine changed ranges; exclude findings outside those ranges as pre-existing.
git diff -U0@@ -X,Y +A,B @@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.
在报告前应用以下过滤规则,仅展示当前变更引入的问题。
SAST:仅当发现问题的文件+行号落在输出的修改行范围内时,才纳入结果。解析代码块确定变更范围;排除该范围外的预存在问题。
git diff -U0@@ -X,Y +A,B @@SCA:仅当新增或更新的包出现更多漏洞或更高严重级别的漏洞时才纳入结果。应用净改进规则——若变更减少了整体漏洞数量或降低了严重级别,则不阻止提交。
IaC:仅当配置错误存在于新增或修改的资源块中时才纳入结果。
Phase 4: Report & Decision
阶段4:报告与决策
Step 4.1: Severity Threshold Configuration
步骤4.1:严重级别阈值配置
| Mode | Block On | Warn On | Allow |
|---|---|---|---|
| Strict | Low+ | - | - |
| Standard | High+ | Medium | Low |
| Relaxed | Critical only | High | Medium, Low |
| 模式 | 阻止条件 | 警告条件 | 允许条件 |
|---|---|---|---|
| 严格模式 | 低及以上级别 | - | - |
| 标准模式 | 高及以上级别 | 中级别 | 低级别 |
| 宽松模式 | 仅严重级别 | 高级别 | 中、低级别 |
Step 4.2: Generate Report
步骤4.2:生成报告
undefinedundefinedSecure 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 |
| 扫描类型 | 新问题数量 | 是否阻止 |
|---|---|---|
| 代码扫描(SAST) | X | 是/否 |
| 依赖扫描(SCA) | Y | 是/否 |
| 基础设施扫描(IaC) | Z | 是/否 |
New Code Vulnerabilities (SAST)
新增代码漏洞(SAST)
| Severity | Type | File | Line | Description |
|---|---|---|---|---|
| High | SQL Injection | src/db.ts | 45 | User input in query |
| 严重级别 | 类型 | 文件 | 行号 | 描述 |
|---|---|---|---|---|
| 高 | SQL注入 | src/db.ts | 45 | 用户输入直接用于查询 |
New Dependency Vulnerabilities (SCA)
新增依赖漏洞(SCA)
| Severity | Package | Vulnerability | Fix Version |
|---|---|---|---|
| Critical | lodash@4.17.15 | Prototype Pollution | 4.17.21 |
| 严重级别 | 包名 | 漏洞类型 | 修复版本 |
|---|---|---|---|
| 严重 | lodash@4.17.15 | 原型污染 | 4.17.21 |
New Infrastructure Issues (IaC)
新增基础设施问题(IaC)
| Severity | Resource | Issue | Recommendation |
|---|---|---|---|
| High | aws_s3_bucket | Public access enabled | Set block_public_access |
| 严重级别 | 资源 | 问题描述 | 修复建议 |
|---|---|---|---|
| 高 | aws_s3_bucket | 开启了公共访问权限 | 设置block_public_access |
Recommended Actions
推荐操作
- - Fix lodash vulnerability
/snyk-fix SNYK-JS-LODASH-1234 - Review for SQL injection fix
src/db.ts:45
- - 修复lodash漏洞
/snyk-fix SNYK-JS-LODASH-1234 - 检查以修复SQL注入问题
src/db.ts:45
Decision: [BLOCKED / ALLOWED]
决策:[阻止 / 允许]
[Reason based on severity threshold]
undefined[基于严重级别阈值的原因说明]
undefinedStep 4.3: Block Decision Logic
步骤4.3:阻止决策逻辑
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
阶段5:指标追踪
After each scan that finds and helps fix issues, run with:
snyk_send_feedback- : project root (absolute path)
path - : count of NEW issues found (delta, not cumulative)
preventedIssuesCount - :
fixedExistingIssuesCount(this skill prevents, doesn't fix existing issues)0
Only count issues found in NEW code that would have been committed without this scan.
每次扫描发现并协助修复问题后,运行并传入以下参数:
snyk_send_feedback- :项目根目录(绝对路径)
path - :发现的新增问题数量(增量,非累计)
preventedIssuesCount - :
fixedExistingIssuesCount(本技能仅阻止新问题,不修复已存在问题)0
仅统计若未进行本次扫描就会被提交的新增代码中的问题。
Best Practices
最佳实践
- Run automatically after generating or modifying code, and before suggesting a commit; also on request for explicit security checks.
- Cache results keyed by with a 12-hour TTL; only rescan changed files and batch by directory.
file + content_hash - False positives: Use a policy file to suppress confirmed false positives, then re-run to verify:
.snykyamlignore: SNYK-JS-EXAMPLE-12345: - '*': reason: 'False positive - input is validated upstream' expires: 2025-12-31 - Threshold tuning: Start with Standard mode; switch to Relaxed if blocks are too frequent, or Strict after low/medium severity incidents.
- CI/CD integration: Invoke on pull request creation or pushes to feature branches; block merge if threshold is exceeded.
- 自动运行:在生成或修改代码后、建议提交前自动运行;也可响应明确的安全检查请求运行。
- 缓存结果:以为键缓存结果,TTL为12小时;仅重新扫描变更文件,并按目录批量处理。
file + content_hash - 误报处理:使用策略文件屏蔽已确认的误报,然后重新扫描验证:
.snykyamlignore: SNYK-JS-EXAMPLE-12345: - '*': reason: '误报 - 输入已在上游验证' expires: 2025-12-31 - 阈值调整:初始使用标准模式;若频繁出现阻止情况可切换为宽松模式,若发生低/中级别漏洞事件则切换为严格模式。
- CI/CD集成:在创建拉取请求或推送至特性分支时触发扫描;若超过阈值则阻止合并。
Error Handling
错误处理
| Situation | Action |
|---|---|
| Authentication error | Run |
| 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
- 仅关注新问题:绝不因已存在的问题阻止提交(修复已有问题属于 remediation 范畴)
- 最小化干扰:严格过滤以避免告警疲劳
- 快速反馈:针对典型变更,扫描需在30秒内完成
- 非破坏性:绝不修改代码,仅报告发现的问题
- 可执行输出:每个发现的问题必须有明确的修复路径