agentleFS
adhuniklabsadhuniklabs/kavach/skills/variant-analysis/SKILL.md

variant-analysis

Skill2 starsChanged 3 months agoMITView on GitHub

KAVACH companion skill finding every sibling of a vulnerability already found - the same root cause manifesting elsewhere in the codebase - via an abstraction-ladder pattern methodology (exact match to semantic taint pattern) and per-language CodeQL/Semgrep taint skeletons. Post-finding expansion usable by every domain agent (kavach-sast, kavach-api, kavach-llm, kavach-billing, kavach-crypto, kavach-supply, kavach-config, kavach-logic). Use after any domain agent confirms or suspects a finding, before writing it up, to check whether the same mistake repeats elsewhere in the surface. Not for initial vulnerability discovery.

8 other projects use a version of this, 2 of them edited.

Adopted by

Most recently taken up by

Used with

Projects with it also use insecure-defaults.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • the-huginSkill

    insecure-defaults

    Detects fail-open vulnerabilities where applications run insecurely with missing configuration. Finds hardcoded credentials, weak env var fallbacks, and insecure-by-default settings. Adapted from Trail of Bits methodology.

    Also in 3 projects that use this

The file

Show its rules and text

We split this skill into the rules it gives an agent

13 rules. 0 are common, 11 are distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 8 edited versions we read keep these.

  • 11

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill when:

    line 20
  2. Distinctive:

    Do NOT use this skill for:

    line 28
  3. Distinctive:

    Before searching, deeply understand the known bug:

    line 38
  4. Distinctive:

    What is the root cause?: Not the symptom, but WHY it's vulnerable

    line 39
  5. Distinctive:

    Start with a pattern that matches ONLY the known instance:

    line 45
  6. Distinctive:

    Verify: Does it match exactly ONE location (the original)?

    line 49
  7. Distinctive:

    If FP rate acceptable, generalize next element

    line 66
  8. Distinctive:

    If FP rate too high, revert and try different abstraction

    line 67
  9. Distinctive:

    Search everywhere: Always search the ENTIRE codebase, not just the module where the bug was found

    line 101
  10. Very specific:

    Never invent a second severity axis: every variant gets severity/cvss_vector/confidence per the shared schema - a variant taxonomy of its …

    line 103
  11. Distinctive:

    Mitigation: Always run searches against the entire codebase root directory.

    line 115
  12. Distinctive:

    Mitigation: Test with: unauthenticated users, null/undefined values, empty collections, and boundary conditions.

    line 142
  13. Very specific:

    Do not write a bespoke report format into .kavach/findings/.

    line 146

“Common” is measured: kept by at least 6 in 10 of the 8 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Adapted from piolium (github.com/vigolium/piolium) - MIT License, © j3ssie.

Variant Analysis

You are running variant analysis: given one confirmed or suspected finding, find every other place the same root cause manifests. This is a post-finding expansion technique, callable by any KAVACH domain agent (kavach-sast, kavach-api, kavach-llm, kavach-billing, kavach-crypto, kavach-supply, kavach-config, kavach-logic) once it has one concrete instance in hand - not a way to discover the first instance of anything.

When to Use

Use this skill when:

  • A vulnerability has been found (confirmed or suspected) and you need to search for siblings before finalizing the finding count
  • Building or refining a Semgrep/CodeQL pattern to sweep a whole vulnerability class across the repo
  • A finding's root cause looks like a developer habit or copy-paste boilerplate, not a one-off
  • Hunting for the same logic-bug shape (inverted condition, null-equality bypass, wrong default) elsewhere in authz/business-logic code

When NOT to Use

Do NOT use this skill for:

  • Initial vulnerability discovery - that's the domain agent's own checklist (domains/*.md), not this skill
  • General code review with no known pattern to search for
  • Writing the finding's remediation text - that's finding-schema.md's remediation field
  • Deep unfamiliar-code comprehension before you have any lead at all

The Five-Step Process

Step 1: 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.

Step 2: Create an Exact Match

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)?

Step 3: Identify Abstraction Points

ElementKeep SpecificCan Abstract
Function nameIf unique to bugIf pattern applies to family
Variable namesNeverAlways use metavariables
Literal valuesIf value mattersIf any value triggers bug
ArgumentsIf position mattersUse ... wildcards

Step 4: Iteratively Generalize

Change ONE element at a time:

  1. Run the pattern
  2. Review ALL new matches
  3. Classify: true positive or false positive?
  4. If FP rate acceptable, generalize next element
  5. If FP rate too high, revert and try different abstraction

Stop when false positive rate exceeds ~50%

Step 5: Analyze and Triage Results

For each match, do not invent a new taxonomy - map straight onto KAVACH's own finding fields (finding-schema.md, severity-model.md):

  • Location: file:line, function - the same discipline as any other finding's locations[]
  • Confidence: confirmed (you read the line and it reproduces the same flaw) or suspected (pattern matches but you haven't traced reachability yet) - never a third bucket
  • Exploitability / severity: score it with the same CVSS vector the original finding got, adjusted for this instance's actual reachability - a variant in dead code is not automatically the same severity as the original
  • Priority: based on impact and exploitability, same as any other finding

For deeper strategic guidance, see METHODOLOGY.md.

Tool Selection

ScenarioToolWhy
Quick surface searchripgrepFast, zero setup
Simple pattern matchingSemgrepEasy syntax, no build needed
Data flow trackingSemgrep taint / CodeQLFollows values across functions
Cross-function analysisCodeQL (see the codeql skill)Best interprocedural analysis - reach for it when a variant's taint path crosses files a grep pattern can't span
Non-building codeSemgrepWorks 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
  7. Never invent a second severity axis: every variant gets severity/cvss_vector/confidence per the shared schema - a variant taxonomy of its own (EASY/MED/HARD, tiers, etc.) is not a KAVACH finding field

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.

Output

Do not write a bespoke report format into .kavach/findings/. Working notes (pattern history, FP log, tracking table) go to .kavach/tmp/variant-workspace/<original-finding-slug>/ - see resources/variant-report-template.md for the tracking-doc shape; treat it as a scratch artifact for your own iteration, not the finding record. Once a variant is confirmed or suspected, it becomes a normal entry in the calling agent's own agent-<domain>.json, cross-referencing the original finding's kavach_id in its own reasoning - one root cause, multiple locations[], or multiple linked findings if severity differs per site; do not silently fold a lower-severity variant into the original's score.

Resources

Ready-to-use templates in resources/:

CodeQL (resources/codeql/):

  • python.ql, javascript.ql, java.ql, go.ql, cpp.ql

Semgrep (resources/semgrep/):

  • python.yaml, javascript.yaml, java.yaml, go.yaml, cpp.yaml

Tracking template: resources/variant-report-template.md

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.