agentleFS
zahidoverflowzahidoverflow/viperclaw/skills/viper-semgrep-rule-author/SKILL.md

viper-semgrep-rule-author

Skill22 starsChanged 15 days agoMITView on GitHub

Custom SAST & Semgrep Rule Authoring Guide (modeled on semgrep/skills). Converts verified CWE findings into deterministic, low-noise CI guardrail rules with unit tests.

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    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. Very specific:

    Run semgrep --test on positive and negative fixtures before enabling any rule in CI.

    line 58
  2. Very specific:

    Run viperclaw taint . alongside custom Semgrep rules in CI.

    line 96
  3. Distinctive:

    Verify zero regressions before promoting a rule to blocking status.

    line 97

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “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

Custom SAST & Semgrep Rule Authoring Guide (viper-semgrep-rule-author)

1. Executive Scope, Standards & CWE/OWASP Mapping

  • Frameworks & Standards: Semgrep Rule Syntax v2, OWASP SAMM Security Testing, CWE Top 25
  • Primary CWE Mapping: CWE-89 (SQL Injection), CWE-78 (OS Command Injection), CWE-79 (XSS), CWE-918 (SSRF)
  • ViperClaw MCP Tools: viper_taint_scan, viper_verify_and_report
  • ViperClaw CLI Command: viperclaw taint ./src --db .viperclaw/graph.db

2. Threat Model & Root-Cause Architecture

flowchart LR
  Bug["Verified Code Finding"] --> Pattern["Minimal AST / Taint Rule"] --> Tests["ruleid + ok Test Fixtures"] --> CI["Blocking Pre-Merge Gate"]

Root-Cause Analysis

Fixing a vulnerability in one controller does not prevent the same insecure API pattern from reappearing in another service. Encoding every verified root cause into a deterministic AST or taint rule stops whole vulnerability classes permanently in CI.


3. Deterministic Discovery & Grep/AST Audit Commands

# 1. Identify recurring sink patterns across the repository
viperclaw taint ./src --db .viperclaw/graph.db

# 2. Locate existing Semgrep / custom lint rule directories
rg --files -g "*semgrep*" -g "*.rules.yml"

4. Senior Security Engineer 8-Point Audit Checklist

Control IDAudit Verification TargetPass CriteriaFail / Vulnerability Indicator
RULE-01Prefer mode: taint for Dataflow BugsInjection rules model pattern-sources, pattern-sanitizers, and pattern-sinks instead of fragile regexes.Regex-only rule flags hardcoded constant strings as SQLi.
RULE-02Explicit Sanitizer ModelingSafe casts (int(), UUID(), parameterized bindings) are declared in pattern-sanitizers.High false-positive rate causes engineers to disable the CI rule.
RULE-03Paired ruleid: and ok: TestsEvery custom rule ships with test fixtures containing both vulnerable (ruleid:) and hardened (ok:) cases.Untested rule shipped directly to CI.
RULE-04Actionable Fix GuidanceRule message explains the exact safe internal wrapper or API to use instead.Generic message ("Unsafe call detected") with no migration guidance.
RULE-05Complete Metadata (CWE/OWASP/Confidence)Every rule specifies cwe, owasp, category: security, confidence, and impact.Unclassified findings break SARIF triage dashboards.
RULE-06Scoped Language & Path FiltersRules exclude generated vendored files and test mocks where appropriate (paths.exclude).Alerts fire on unit-test fixtures instead of production routes.
RULE-07Low-Noise Blocking ThresholdOnly HIGH confidence rules block PR merges; experimental rules run in audit mode first.Noisy rules block unrelated pull requests.
RULE-08Periodic Precision MeasurementTrack true-positive vs. false-positive rate on PR comments quarterly.Stale rules silently ignored via inline nosemgrep comments.

5. False-Positive Elimination & CVSS v3.1 Triage Rubric

False-Positive Gate

  1. Run semgrep --test on positive and negative fixtures before enabling any rule in CI.
  2. Audit nosemgrep suppressions during PR review to ensure real issues are not silenced.
Severity TierBaseline CVSS v3.1 VectorQualifying Security Impact
HIGH (7.5)CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:NUnenforced guardrail allowing recurring injection or auth-boundary regressions across services.
MEDIUM (5.3)CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:L/I:L/A:NMissing sanitizer definitions or untested CI rules permitting drift.
LOW (3.1)CVSS:3.1/AV:N/AC:H/PR:H/UI:N/S:U/C:L/I:N/A:NIncomplete CWE/OWASP metadata in SARIF rule exports.

6. Production Remediation Patterns (Vulnerable vs. Hardened Code)

# ✅ HARDENED: Precision taint rule with explicit sanitizer and CWE metadata
rules:
  - id: python-raw-sql-taint
    mode: taint
    languages: [python]
    severity: ERROR
    message: "User-controlled data reaches cursor.execute() without parameterization. Use bound parameters."
    metadata:
      cwe: "CWE-89"
      owasp: "A03:2021"
      confidence: HIGH
    pattern-sources:
      - pattern: request.args.get(...)
      - pattern: request.form.get(...)
    pattern-sanitizers:
      - pattern: int(...)
    pattern-sinks:
      - pattern: $CURSOR.execute($QUERY)

7. Regression Testing & Continuous Verification

  1. Validate every rule against paired ruleid: and ok: unit test cases.
  2. Run viperclaw taint . alongside custom Semgrep rules in CI.
  3. Verify zero regressions before promoting a rule to blocking status.

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.