Author: Axel MierczukOnce you’ve found one vulnerability, there are likely more. This plugin helps you hunt them down systematically.
Installation
Overview
Variant analysis is the process of taking a known vulnerability and searching for similar instances across a codebase. The plugin provides:- Five-step systematic process from understanding to reporting
- Tool selection guidance (ripgrep, Semgrep, CodeQL)
- Critical pitfall catalog to avoid missing variants
- Ready-to-use templates for CodeQL and Semgrep in multiple languages
- Detailed methodology for abstraction and generalization
When to Use
Use this plugin 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 plugin 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
Understand the Original Issue
Before searching, deeply understand the known bug:
- What is the root cause? Not the symptom, but WHY it’s vulnerable
- What conditions are required? Control flow, data flow, state
- What makes it exploitable? User control, missing validation, etc.
Create an Exact Match
Start with a pattern that matches ONLY the known instance:Verify: Does it match exactly ONE location (the original)?This establishes your baseline before generalization.
Identify Abstraction Points
Determine what can be generalized:
| 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 |
Iteratively Generalize
Change ONE element at a time:
- Run the pattern
- Review ALL new matches
- Classify: true positive or false positive?
- If FP rate acceptable, generalize next element
- If FP rate too high, revert and try different abstraction
Tool Selection
Choose the right tool for your analysis:| Scenario | Tool | Why |
|---|---|---|
| Quick surface search | ripgrep | Fast, zero setup, good for reconnaissance |
| Simple pattern matching | Semgrep | Easy syntax, no build needed, works on incomplete code |
| Data flow tracking | Semgrep taint / CodeQL | Follows values across functions and files |
| Cross-function analysis | CodeQL | Best interprocedural analysis, deep data flow |
| Non-building code | Semgrep | Works without compilation |
The Abstraction Ladder
Patterns exist at different abstraction levels. Climb the ladder systematically:Level 0: Exact Match
Level 0: Exact Match
Match the literal vulnerable code:
- Matches: 1 (the original)
- False positives: 0
- Value: Confirms bug exists, baseline for generalization
Level 1: Variable Abstraction
Level 1: Variable Abstraction
Replace variable names with wildcards:
- Matches: 3-5 (same query pattern, different variables)
- False positives: Low
- Value: Find copy-paste variants
Level 2: Structural Abstraction
Level 2: Structural Abstraction
Generalize the structure:
- Matches: 10-30 (any string concat used in query)
- False positives: Medium
- Value: Find pattern variants
Level 3: Semantic Abstraction
Level 3: Semantic Abstraction
Abstract to the security property:
- Matches: 50-100+ (any user input to any query)
- False positives: High (many have proper parameterization)
- Value: Comprehensive coverage, requires triage
Choosing Your Level
| Goal | Recommended Level |
|---|---|
| Verify a specific fix | Level 0 |
| Find copy-paste bugs | Level 1 |
| Audit a component | Level 2 |
| Full security assessment | Level 3 |
Critical Pitfalls to Avoid
1. Narrow Search Scope
Problem: Searching only the module where the original bug was found misses variants in other locations. Example: Bug found inapi/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
Problem: Using only the exact attribute/function from the original bug misses variants using related constructs. Example: Bug usesisAuthenticated check → only searching for that exact term → missing bugs using isActive, isAdmin, isVerified
Mitigation: Enumerate ALL semantically related attributes/functions for the bug class.
3. Single Vulnerability Class
Problem: 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 == nullevaluates to true) - Documentation/code mismatches (function does opposite of docs)
- Inverted conditional logic (wrong branch taken)
4. Missing Edge Cases
Problem: Testing patterns only with “normal” scenarios misses vulnerabilities triggered by edge cases. Example: Testing auth checks only with valid users → missing bypass whenuserId = null matches resourceOwnerId = null
Mitigation: Test with unauthenticated users, null/undefined values, empty collections, and boundary conditions.
Expanding Vulnerability Classes
A single root cause can manifest in multiple ways. Before concluding your search, expand to related vulnerability classes:Semantically Related Functions
Semantically Related Functions
Boolean Logic Errors
Boolean Logic Errors
- Inverted conditions (
if not xvsif x) - Wrong default return value (
return truevsreturn false) - Short-circuit evaluation errors
Edge Cases by Data Type
Edge Cases by Data Type
- Null/None/undefined comparisons
- Empty string vs null
- Zero vs null
- Empty array/collection
Documentation Mismatches
Documentation Mismatches
Function does opposite of docstring:Detection: Search for functions with “deny”, “restrict”, “block”, “forbid” and verify return semantics.
Null Equality Bypasses
Null Equality Bypasses
Ready-to-Use Templates
The plugin includes language-specific templates:- CodeQL
- Semgrep
Templates for:
- Python (
resources/codeql/python.ql) - JavaScript (
resources/codeql/javascript.ql) - Java (
resources/codeql/java.ql) - Go (
resources/codeql/go.ql) - C++ (
resources/codeql/cpp.ql)
Commands
The plugin includes a/variants command for quick invocation:
- The original bug/vulnerability that was found
- The codebase to search
Variant Report Template
Use the provided template for documenting findings:Key Principles
Root Cause First
Understand WHY before searching for WHERE
Start Specific
First pattern should match exactly the known bug
One Change at a Time
Generalize incrementally, verify after each change
Know When to Stop
50%+ FP rate means you’ve gone too generic
Search Everywhere
Always search the ENTIRE codebase
Expand Classes
One root cause has multiple manifestations
Related Skills
CodeQL
Primary tool for deep interprocedural variant analysis
Semgrep
Fast pattern matching for simpler variants
SARIF Parsing
Process variant analysis results
Example Workflow
The Expert Mindset
- Understand before searching - Root cause analysis is non-negotiable
- Start specific - First pattern should match exactly one thing
- Climb the ladder - Generalize one step at a time
- Measure as you go - Track matches and FP rates at each step
- Know when to stop - High FP rate means you’ve gone too far
- Iterate ruthlessly - Refine patterns based on what you learn
- Document everything - Your tracking doc is as valuable as your patterns
- Expand vulnerability classes - One root cause has many manifestations
- Check semantics - Verify code matches documentation intent
- Test edge cases - Null values and boundary conditions reveal hidden bugs