skills/security-auditing/SKILL.md
Use when auditing skills, commands, hooks, and MCP tools for security vulnerabilities. Triggers: 'security audit', 'scan for vulnerabilities', 'check security', 'audit skills', 'audit MCP tools', 'is this safe', 'check for injection', 'OWASP'. NOT for: general code review (use code-review --audit).
npx skillsauth add axiomantic/spellbook security-auditingInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Follow ALL six phases in order. Do NOT skip classification or trace analysis for HIGH/CRITICAL findings. Scanner results alone are insufficient; interpret, deduplicate, and contextualize. </CRITICAL>
| Input | Required | Description |
|-------|----------|-------------|
| Scope | Yes | What to audit: skills, mcp, changeset, all, or specific paths |
| Security mode | No | standard (default), paranoid, or permissive |
| Diff text | If changeset | Unified diff for changeset scanning |
| Output | Type | Description |
|--------|------|-------------|
| Audit report | File | Structured findings at $SPELLBOOK_CONFIG_DIR/docs/<project-encoded>/audits/security-audit-<timestamp>.md |
| Verdict | Enum | PASS, WARN, or FAIL |
| Summary | Inline | Finding counts by severity and category |
The spellbook.security.scanner module provides these entry points:
| Function | Target | Description |
|----------|--------|-------------|
| scan_skill(file_path) | Single .md file | Scans against injection, exfiltration, escalation, obfuscation rules plus invisible chars and entropy |
| scan_directory(dir_path) | Directory of .md files | Recursive scan of all markdown files |
| scan_changeset(diff_text) | Unified diff | Scans only added lines in .md files |
| scan_python_file(file_path) | Single .py file | Scans against MCP-specific rules (shell injection, eval, path traversal, etc.) |
| scan_mcp_directory(dir_path) | Directory of .py files | Recursive scan of all Python files |
All functions accept an optional security_mode parameter: "standard", "paranoid", or "permissive".
| Category | Rule Prefix | Examples | |----------|-------------|----------| | Injection | INJ-001..010 | Instruction overrides, role reassignment, system prompt injection | | Exfiltration | EXF-001..009 | HTTP transfer tools, credential file access, reverse shells | | Escalation | ESC-001..008 | Permission bypass, sudo, dynamic execution, shell injection | | Obfuscation | OBF-001..004 | Base64 payloads, hex escapes, char code obfuscation | | MCP Tool | MCP-001..009 | Shell execution, dynamic eval, unsanitized paths, SQL injection | | Invisible | INVIS-001 | Zero-width Unicode characters | | Entropy | ENT-001 | High-entropy code blocks |
| Mode | Minimum Severity | Use When |
|------|-----------------|----------|
| permissive | CRITICAL only | Quick smoke test |
| standard | HIGH and above | Normal audits |
| paranoid | MEDIUM and above | Pre-release, supply chain review |
Identify the audit scope and catalog all targets.
<!-- SUBAGENT: Dispatch explore subagent if scope is broad (e.g., "all" or full directory). For targeted audits of 1-3 files, stay in main context. -->Parse scope argument:
skills - all files under skills/mcp - all Python files under spellbook/changeset - staged or branch diffall - both skills and mcp directoriesCatalog targets in a structured inventory listing:
Determine security mode from user input or default to standard.
Run the scanner against all cataloged targets.
<!-- SUBAGENT: Dispatch subagent to run scanner. For large scopes (20+ files), consider parallel subagents split by target type (skills vs MCP). -->Run appropriate scanner functions based on scope:
For skill/command files (markdown):
uv run python -m spellbook.security.scanner --skills
Or for specific files:
uv run python -m spellbook.security.scanner --mode skill <path>
For MCP tool files (Python):
uv run python -m spellbook.security.scanner --mode mcp spellbook/
For changeset scanning:
git diff --cached | uv run python -m spellbook.security.scanner --changeset
Or branch-based:
uv run python -m spellbook.security.scanner --base origin/main
Scanner failure path: If any scanner command fails (non-zero exit, missing module, timeout), record the error, note which targets were not scanned, and flag the audit as incomplete. Do not proceed to Phase 3 with partial results unless the user explicitly approves.
Capture all scanner output. Each finding includes:
Record raw findings before classification.
Deduplicate findings, assess real severity, and identify false positives.
<CRITICAL> Classification is the most abuse-prone phase. The temptation to downgrade or dismiss findings to produce a clean report is real. Resist it. Every downgrade requires documented evidence. Every false positive requires rationale. If you cannot explain why a finding is benign in one sentence of evidence, it is not a false positive. </CRITICAL>Deduplicate: Group identical rule triggers across files. A rule that fires 50 times on the same pattern in different files is one finding, not 50.
Assess each finding:
| Field | Question | |-------|----------| | Real severity | Does the context make this more or less dangerous than the rule's default? | | False positive? | Is this legitimate code that happens to match a security pattern? | | Exploitable? | Could an attacker actually leverage this in a Spellbook context? | | Context | What file is this in, and what is its trust level? |
Apply trust-level context:
| Trust Level | Content | Threshold | |-------------|---------|-----------| | system (5) | Core framework code | Only CRITICAL matters | | verified (4) | Reviewed library skills | HIGH and above | | user (3) | User-installed content | MEDIUM and above | | untrusted (2) | Third-party skills | All findings | | hostile (1) | Unknown origin | All findings, paranoid mode |
Classify each finding using this template:
Remove confirmed false positives from the active findings list. Document them separately for transparency.
For HIGH and CRITICAL findings that survived classification, trace attack chains.
<analysis> A finding in isolation tells you a pattern exists. An attack chain tells you what damage is possible. The difference between "this file contains a dynamic execution call" and "an attacker can inject arbitrary code via untrusted skill content that reaches that call through the MCP server" is the difference between awareness and actionable intelligence. </analysis>Fractal exploration (optional): When a finding is HIGH or CRITICAL severity, invoke fractal-thinking with intensity pulse and seed: "What attack vectors exist against [component] and what are the second-order effects?". Use the synthesis to enrich the attack chain graph.
For each HIGH/CRITICAL finding, answer:
| Question | Purpose | |----------|---------| | What is the entry point? | How does attacker-controlled input reach this code? | | What is the trust boundary? | Does input cross from untrusted to trusted context? | | What is the impact? | Data loss, code execution, privilege escalation, exfiltration? | | What is the attack scenario? | Step-by-step exploitation narrative | | What prevents exploitation? | Existing mitigations, if any |
Document attack chains with these fields:
Example minimal attack chain:
Re-assess severity based on attack chain analysis. A HIGH finding with a trivial exploitation path and no mitigations becomes CRITICAL. A CRITICAL finding behind multiple defense layers may remain CRITICAL but with lower exploitability.
Generate the structured audit report.
The audit report is a markdown document with these sections in order:
Save the report to $SPELLBOOK_CONFIG_DIR/docs/<project-encoded>/audits/security-audit-<timestamp>.md.
Enforce the audit verdict as a quality gate.
| Condition | Verdict | Action | |-----------|---------|--------| | Zero findings after classification | PASS | Proceed | | Only LOW/MEDIUM findings | WARN | Proceed with acknowledgment | | Any HIGH finding with no attack chain | WARN | Proceed with acknowledgment | | Any HIGH finding with viable attack chain | FAIL | Block until remediated | | Any CRITICAL finding (regardless of chain) | FAIL | Block until remediated |
code-review --auditcode-review --audit handles correctness, performance, and maintainability passesdevelop Phase 4develop Phase 4 dispatches a subagent that invokes this skilldistilling-prs for PR Reviewdistilling-prs can invoke this skill on the PR diffBefore completing the audit, verify:
Completeness:
Classification Quality:
Trace Quality:
Report Quality:
Gate:
<FINAL_EMPHASIS> The scanner finds patterns. You find vulnerabilities. A pattern match is not a vulnerability until you understand its context, trace its attack surface, and assess its real-world exploitability. Do the work. Every phase matters. </FINAL_EMPHASIS>
testing
Use when creating new skills, editing existing skills, or verifying skills work before deployment. Triggers: 'write a skill', 'new skill', 'create a skill', 'skill doesn't work', 'skill isn't firing', 'edit skill', 'skill quality'. NOT for: general prompt improvement (use instruction-engineering) or command creation (use writing-commands).
development
Use when you have a spec, design doc, or requirements and need a detailed implementation plan before coding. Triggers: 'write a plan', 'create implementation plan', 'plan this out', 'break this down into steps', 'convert design to tasks', 'implementation order'. Also invoked by develop during planning. NOT for: reviewing existing plans (use reviewing-impl-plans).
testing
Use when creating new commands, editing existing commands, or reviewing command quality. Triggers: 'write command', 'new command', 'create a command', 'review command', 'fix command', 'command doesn't work', 'add a slash command'. NOT for: skill creation (use writing-skills).
development
Use when about to claim discovery during debugging. Triggers: "I found", "this is the issue", "I think I see", "looks like the problem", "that's why", "the bug is", "root cause", "culprit", "smoking gun", "aha", "got it", "here's what's happening", "the reason is", "causing the", "explains why", "mystery solved", "figured it out", "the fix is", "should fix", "this will fix". Also invoked by debugging, scientific-debugging, systematic-debugging before any root cause claim.