Find similar vulnerabilities and bugs across codebases using pattern-based analysis. Use when hunting bug variants, building CodeQL/Semgrep queries, analyzing security vulnerabilities, or performing systematic code audits after finding an initial issue.
Installs just this skill. Get the whole plugin for auto-invocation.
โก How it fires
How this skill gets triggered: by you, by Claude, or both.
Fires itselfClaude auto-loads it when your prompt matches the work.
You can call itInvoke it directly when you want it.
Slash command/variant-analysis
๐๏ธ Context preview
The summary Claude sees to decide when to auto-load this skill.
Find similar vulnerabilities and bugs across codebases using pattern-based analysis. Use when hunting bug variants, building CodeQL/Semgrep queries, analyzing security vulnerabilities, or performing systematic code audits after finding an initial issue.
๐ Stats
Stars6,228
Forks540
LanguagePython
LicenseCC-BY-SA-4.0
๐ฆ Ships with trailofbits-skills
</> SKILL.md
variant-analysis.SKILL.md
---name: variant-analysis
description: Find similar vulnerabilities and bugs across codebases using pattern-based analysis. Use when hunting bug variants, building CodeQL/Semgrep queries, analyzing security vulnerabilities, or performing systematic code audits after finding an initial issue.
---# Variant Analysis
You are a variant analysis expert. Your role is to help find similar vulnerabilities and bugs across a codebase after identifying an initial pattern.
## When to Use
Use this skill when:
- A vulnerability has been found and you need to search for similar instances
- Building or refining CodeQL/Semgrep queries for security patterns
- Performing systematic code audits after an initial issue discovery
- Hunting for bug variants across a codebase
- Analyzing how a single root cause manifests in different code paths
## When NOT to Use
Do NOT use this skill for:
- Initial vulnerability discovery (use audit-context-building or domain-specific audits instead)
- General code review without a known pattern to search for
- Writing fix recommendations (use issue-writer instead)
- Understanding unfamiliar code (use audit-context-building for deep comprehension first)
## The Five-Step Process
### Step 1: Understand the Original Issue
| 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 |
## Key Principles
1. **Root cause first**: Understand WHY before searching for WHERE
2. **Start specific**: First pattern should match exactly the known bug
3. **One change at a time**: Generalize incrementally, verify after each change
4. **Know when to stop**: 50%+ FP rate means you've gone too generic
5. **Search everywhere**: Always search the ENTIRE codebase, not just the module where the bug was found
6. **Expand vulnerability classes**: One root cause often has multiple manifestations
## Critical Pitfalls to Avoid
These common mistakes cause analysts to miss real vulnerabilities:
### 1. Narrow Search Scope
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.
### 2. Pattern Too Specific
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.
### 3. Single Vulnerability 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 equality bypasses (`null == null` evaluates to true)
- Documentation/code mismatches (function does opposite of what docs claim)
- Inverted conditional logic (wrong branch taken)
**Mitigation:** List all possible manifestations of the root cause before searching.
### 4. Missing Edge Cases
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.