npx skills add https://github.com/trailofbits/skills --skill variant-analysis你是一名变体分析专家。你的职责是在识别出初始模式后,帮助在整个代码库中查找相似的漏洞和错误。
在以下情况下使用此技能:
不要在以下情况下使用此技能:
在开始搜索之前,深入理解已知的错误:
从一个仅匹配已知实例的模式开始:
rg -n "exact_vulnerable_code_here"
验证:它是否精确地匹配一个位置(原始位置)?
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 元素 | 保持具体 | 可以抽象 |
|---|---|---|
| 函数名 | 如果该名称是此错误独有的 | 如果模式适用于一个函数族 |
| 变量名 | 从不 | 始终使用元变量 |
| 字面值 | 如果该值很重要 | 如果任何值都会触发错误 |
| 参数 | 如果参数位置很重要 | 使用 ... 通配符 |
每次只更改一个元素:
当假阳性率超过约 50% 时停止
对于每个匹配项,记录:
有关更深入的战略指导,请参阅 METHODOLOGY.md。
| 场景 | 工具 | 原因 |
|---|---|---|
| 快速表面搜索 | ripgrep | 快速,零设置 |
| 简单模式匹配 | Semgrep | 语法简单,无需构建 |
| 数据流追踪 | Semgrep taint / CodeQL | 跨函数跟踪值 |
| 跨函数分析 | CodeQL | 最佳的过程间分析 |
| 非构建代码 | Semgrep | 适用于不完整的代码 |
这些常见错误会导致分析人员遗漏真正的漏洞:
仅在发现原始错误的模块中搜索,会遗漏其他位置的变体。
示例: 在 api/handlers/ 中发现错误 → 仅搜索该目录 → 遗漏了 utils/auth.py 中的变体
缓解措施: 始终针对整个代码库根目录运行搜索。
仅使用原始错误中的确切属性/函数,会遗漏使用相关结构的变体。
示例: 错误使用了 isAuthenticated 检查 → 仅搜索该确切术语 → 遗漏了使用相关属性(如 isActive、isAdmin、isVerified)的错误
缓解措施: 枚举该错误类别的所有语义相关的属性/函数。
只关注根本原因的一种表现形式,会遗漏同一逻辑错误出现的其他方式。
示例: 原始错误是“当条件为 false 时返回 allow” → 仅搜索该模式 → 遗漏了:
null == null 结果为 true)缓解措施: 在开始搜索之前,列出根本原因所有可能的表现形式。
仅用“正常”场景测试模式,会遗漏由边缘情况触发的漏洞。
示例: 仅用有效用户测试身份验证检查 → 遗漏了当 userId = null 匹配 resourceOwnerId = null 时的绕过
缓解措施: 使用以下情况进行测试:未认证用户、null/undefined 值、空集合以及边界条件。
resources/ 目录中提供了现成的模板:
CodeQL (resources/codeql/):
python.ql, javascript.ql, java.ql, go.ql, cpp.qlSemgrep (resources/semgrep/):
python.yaml, javascript.yaml, java.yaml, go.yaml, cpp.yaml报告 : resources/variant-report-template.md
每周安装量
1.3K
代码仓库
GitHub 星标数
3.9K
首次出现
Jan 19, 2026
安全审计
安装于
claude-code1.1K
codex1.0K
opencode1.0K
gemini-cli959
cursor925
github-copilot893
You are a variant analysis expert. Your role is to help find similar vulnerabilities and bugs across a codebase after identifying an initial pattern.
Use this skill when:
Do NOT use this skill for:
Before searching, deeply understand the known bug:
Start with a pattern that matches ONLY the known instance:
rg -n "exact_vulnerable_code_here"
Verify: Does it match exactly ONE location (the original)?
| Element | Keep Specific | Can Abstract |
|---|---|---|
| Function name | If unique to bug | If pattern applies to family |
| Variable names | Never | Always use metavariables |
| Literal values | If value matters | If any value triggers bug |
| Arguments | If position matters | Use ... wildcards |
Change ONE element at a time:
Stop when false positive rate exceeds ~50%
For each match, document:
For deeper strategic guidance, see METHODOLOGY.md.
| Scenario | Tool | Why |
|---|---|---|
| Quick surface search | ripgrep | Fast, zero setup |
| Simple pattern matching | Semgrep | Easy syntax, no build needed |
| Data flow tracking | Semgrep taint / CodeQL | Follows values across functions |
| Cross-function analysis | CodeQL | Best interprocedural analysis |
| Non-building code | Semgrep | Works on incomplete code |
These common mistakes cause analysts to miss real vulnerabilities:
Searching only the module where the original bug was found misses variants in other locations.
Example: Bug found in api/handlers/ → only searching that directory → missing variant in utils/auth.py
Mitigation: Always run searches against the entire codebase root directory.
Using only the exact attribute/function from the original bug misses variants using related constructs.
Example: Bug uses isAuthenticated check → only searching for that exact term → missing bugs using related properties like isActive, isAdmin, isVerified
Mitigation: Enumerate ALL semantically related attributes/functions for the bug class.
Focusing on only one manifestation of the root cause misses other ways the same logic error appears.
Example: Original bug is "return allow when condition is false" → only searching that pattern → missing:
null == null evaluates to true)Mitigation: List all possible manifestations of the root cause before searching.
Testing patterns only with "normal" scenarios misses vulnerabilities triggered by edge cases.
Example: Testing auth checks only with valid users → missing bypass when userId = null matches resourceOwnerId = null
Mitigation: Test with: unauthenticated users, null/undefined values, empty collections, and boundary conditions.
Ready-to-use templates in resources/:
CodeQL (resources/codeql/):
python.ql, javascript.ql, java.ql, go.ql, cpp.qlSemgrep (resources/semgrep/):
python.yaml, javascript.yaml, java.yaml, go.yaml, cpp.yamlReport : resources/variant-report-template.md
Weekly Installs
1.3K
Repository
GitHub Stars
3.9K
First Seen
Jan 19, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
claude-code1.1K
codex1.0K
opencode1.0K
gemini-cli959
cursor925
github-copilot893
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
102,200 周安装