agentleFS
zahidoverflowzahidoverflow/viperclaw/skills/viper-js-harvester/SKILL.md

viper-js-harvester

Skill22 starsChanged 15 days agoMITView on GitHub

Client-Side Bundle & SPA Manifest Auditor. Reviews Webpack, Vite, and Next.js build artifacts to inventory client routes, API references, DOM sinks, and accidentally bundled secrets.

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Run the following discovery commands across the target repository before manual code review:

    line 30
  2. Distinctive:

    Verify whether an upstream API Gateway, global middleware, or ORM hook already enforces the control before flagging a controller.

    line 62
  3. Distinctive:

    Write a Positive Unit Test confirming authorized, schema-valid requests succeed.

    line 100
  4. Distinctive:

    Write a Negative Security Regression Test confirming unauthorized, cross-tenant, or malformed inputs are deterministically rejected.

    line 101

≈ “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

Client-Side Bundle, SPA Manifest & DOM Security Auditor (viper-js-harvester)

1. Executive Scope, Standards & CWE/OWASP Mapping

  • Frameworks & Standards: OWASP WSTG-CLNT (Client-Side Testing), OWASP Top 10:2025 A03/A05, CWE-79, CWE-798, CWE-540
  • Primary CWE Mapping: CWE-79 (DOM-Based XSS), CWE-798 (Hardcoded Credentials in Client Bundle), CWE-540 (Inclusion of Sensitive Information in Source Code), CWE-345 (Insufficient Verification of Data Authenticity in postMessage)
  • ViperClaw MCP Tools: viper_harvest_js, viper_browser_ingest, viper_graph_upsert, viper_verify_and_report
  • ViperClaw CLI Command: viperclaw harvest-js ./dist --base-url https://app.example.com/ --db .viperclaw/graph.db --output js_audit.json

2. Threat Model & Root-Cause Architecture

flowchart LR
  Source["URL Hash / postMessage / Storage"] --> Router["SPA Client Router & Chunks"] --> Sink["innerHTML / eval / fetch()"] --> DOM["Browser DOM & Credential Store"]

Root-Cause Analysis

Modern bundlers (Webpack, Vite, Next.js, Rollup) inline NEXT_PUBLIC_* / VITE_* environment variables at build time and emit code-split chunk manifests (webpackChunk, _buildManifest.js) that expose internal routes, unreleased admin views, and unvalidated DOM sinks.


3. Deterministic Discovery & Grep/AST Audit Commands

Run the following discovery commands across the target repository before manual code review:

# 1. Automated ViperClaw analysis
viperclaw harvest-js ./dist --base-url https://app.example.com/ --db .viperclaw/graph.db --output js_audit.json

# 2. Rapid static pattern discovery (ripgrep)
rg -n "(dangerouslySetInnerHTML|innerHTML\s*=|outerHTML\s*=|document\.write\()"
rg -n "addEventListener\(\s*.message."
rg -n "(NEXT_PUBLIC_|VITE_|REACT_APP_)[A-Z0-9_]*(KEY|SECRET|TOKEN|PRIVATE)"

4. Senior Security Engineer 8-Point Audit Checklist

Control IDAudit Verification TargetPass CriteriaFail / Vulnerability Indicator
JS-01Build-Time Env Leak AuditNo private keys or backend tokens prefixed with NEXT_PUBLIC_, VITE_, or REACT_APP_.Service-role keys, Stripe secret keys, or internal tokens embedded in .js bundles.
JS-02Production Source Map Hygiene.js.map source maps disabled in public production builds or restricted to internal error trackers.Publicly downloadable .js.map files exposing full proprietary TypeScript source and comments.
JS-03Lazy-Chunk Route AuthorizationAll administrative or debug routes referenced in lazy chunks enforce server-side RBAC.Client-side-only route guards (if (user.isAdmin)) protecting sensitive API endpoints.
JS-04DOM HTML Sink SanitizationUses of innerHTML / dangerouslySetInnerHTML sanitize inputs via DOMPurify.sanitize().Raw user/API HTML injected directly into DOM nodes.
JS-05postMessage Origin & Source Checkswindow.addEventListener('message') validates exact event.origin and schema.Wildcard or substring .includes() origin check on incoming postMessage events.
JS-06Client Redirect & javascript: URI GuardDynamic href / window.location.assign values validate http:/https: protocol.Unvalidated redirect_url allowing javascript: execution in <a href={url}>.
JS-07Client Token Storage SecuritySession tokens stored in HttpOnly; Secure; SameSite cookies rather than localStorage.Long-lived JWTs or refresh tokens stored in window.localStorage.
JS-08Subresource Integrity (SRI)External third-party <script> tags include integrity="sha384-..." and crossorigin.Unpinned third-party CDN scripts loaded without SRI hashes.

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

False-Positive Gate

  1. Verify whether an upstream API Gateway, global middleware, or ORM hook already enforces the control before flagging a controller.
  2. Confirm the code path is reachable from an external entrypoint (not dead code, CLI-only admin script, or unit-test fixture).
Severity TierBaseline CVSS v3.1 VectorQualifying Security Impact
CRITICAL (9.1)CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:NProduction cloud/database service-role secret key hardcoded in public JS bundle.
HIGH (7.5)CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:NUnloaded admin lazy chunk reveals unauthenticated internal API endpoints leaking PII.
MEDIUM (6.1)CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:NDOM-based XSS via unvalidated window.postMessage or location.search into innerHTML.
LOW (3.7)CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:N/A:NPublic .js.map source maps exposed without sensitive credentials.

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

// ❌ VULNERABLE: Substring origin check & direct innerHTML sink in postMessage handler
window.addEventListener("message", (event) => {
  if (event.origin.indexOf("example.com") !== -1) {
    document.getElementById("preview")!.innerHTML = event.data.html;
  }
});

// ✅ HARDENED: Strict origin allowlist + DOMPurify sanitization
import DOMPurify from "dompurify";
const ALLOWED_ORIGINS = new Set(["https://app.example.com", "https://portal.example.com"]);

window.addEventListener("message", (event: MessageEvent) => {
  if (!ALLOWED_ORIGINS.has(event.origin)) return;
  if (typeof event.data?.html === "string") {
    const clean = DOMPurify.sanitize(event.data.html, { USE_PROFILES: { html: true } });
    document.getElementById("preview")!.innerHTML = clean;
  }
});

7. Regression Testing & Continuous Verification

  1. Write a Positive Unit Test confirming authorized, schema-valid requests succeed.
  2. Write a Negative Security Regression Test confirming unauthorized, cross-tenant, or malformed inputs are deterministically rejected.
  3. Re-run viperclaw taint and viperclaw verify to confirm zero remaining unmitigated flows in .viperclaw/graph.db.

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.