AGENT SKILL

security-audit

Audits a codebase for security vulnerabilities, independently verifies each one, and writes a report. Use when asked for a full, multi-phase codebase security audit or pen test, or for focused security guidance on code.

License 许可
MIT
最近更新
2026-11-04
Stars
★ 4
Forks
2

01 前言 Front Matter

name
security-audit
group
process
description
Audits a codebase for security vulnerabilities, independently verifies each one, and writes a report. Use when asked for a full, multi-phase codebase security audit or pen test, or for focused security guidance on code.
argument-hint
[guide|audit] [path]
disable-model-invocation
true

02 资源文件 19

03 SKILL.md 正文

Security Audit

Find vulnerabilities that violate a real trust boundary, then give owners the source evidence, safe reproduction, priority, and smallest effective fix. This is a defensive, source-first workflow. A candidate without a concrete affected principal, resource, or security outcome is not a confirmed finding.

Operating modes

This skill is guidance by default. Loading it does not authorize the complete audit workflow or file creation.

  • Guidance mode: For security questions, focused reviews, methodology, triage, or investigation of specific findings, use only the relevant parts of this skill: read ATTACK-CLASSES.md and the one companion matching the target's boundary, apply Universal execution safety, and create no files. Do not automatically run all six phases, create an output directory, or write audit artifacts. You may launch focused agents when useful; they return results to the current task.
  • Full audit mode: Use the complete workflow when the user explicitly asks to audit or pen-test a codebase, asks for a full, comprehensive, or end-to-end security review, or requests report artifacts. Run all six phases and write the files defined below.

If the request could mean either mode, ask one focused question before creating files or starting the complete workflow.

Platform terminology

This skill is agent-neutral:

  • Parent is the agent that coordinates the run and owns shared state.
  • Task tool is the platform's delegation or sub-agent mechanism.
  • research agent is a delegated agent for focused source exploration and factual verification.
  • general agent is a delegated agent for broad investigation and bounded local execution.
  • subagent_type: in a heading names which of these two delegated agent roles runs that work. A heading without it runs as general.
  • On Claude Code the Task tool is Agent (task on OpenCode). Map research to explorer for reconnaissance 1a, 1c, and 1d only. Map general, the coverage critics, reconnaissance 1b, and every Phase 5 verifier to security-auditor. Open every brief with: "Ignore your default report format; reply with only the JSON object. Do not run network audit tools."

Use equivalent platform capabilities while preserving role, write-isolation, prompt, and independence boundaries.

Wherever a file says to launch agents "in parallel", launch at most as many at once as CLAUDE_CODE_MAX_CONCURRENT_SUBAGENTS allows (agent-notes sets 5), and start the next batch as agents finish, because the Agent tool refuses launches past the cap.

Companion files

Select the companions that match the target's trust boundaries:

Universal execution safety

These rules apply in both operating modes. Source inspection is read-only. Run target-controlled builds, tests, processes, browsers, emulators, fuzzers, and fixture processing only inside an OS-enforced sandbox that provides all of these controls:

  • no external network; use only an isolated loopback namespace when the check needs local client/server traffic;
  • an empty environment populated from an explicit allowlist with safe values, with scratch-local HOME, temporary directories, and caches;
  • a read-only target and toolchain, with the target-controlled process able to write only inside its assigned scratch/ directory; and
  • explicit low CPU, memory, process, file-size, disk, and wall-clock limits.

The agent, outside the target-controlled process, may make a disposable source copy in an assigned scratch/ directory when a build must write beside source. In guidance mode, do not retain target-controlled files. In full audit mode, only trusted parent-side code may promote the minimum non-secret result to retained artifacts/ using the procedure under Write isolation. Never expose a retained output directory (other than the agent's own assigned scratch/), another agent's directory, the host home directory, credentials, sockets, or shared services to target code. Do not install dependencies or let builds fetch them. Use only tools and dependencies already available locally. If every control cannot be enforced, do not execute target code: report the missing sandbox capability as a needs-validation blocker and give a safe validation plan.

Claude Code is source-only. No OS-enforced sandbox is assumed there. Unless the user names a sandbox command that enforces every control listed above, set execution_policy: "source-only" in run-metadata.json, run nothing from the target, and put execution: disabled in every hunter and verifier brief. A lead that needs a run stays needs_validation. Tell the user this before wave 1. With execution disabled no record can meet the confirmed evidence bar; report source-grounded leads as needs_validation with the exact unresolved fact, and say so in the report.

Use dummy principals, fixtures, and secrets. Do not probe deployed endpoints, external services, shared infrastructure, production identities, other users' data, or live control planes. Do not test availability against a live or shared process, publish artifacts, alter releases, spend paid API quota, or continue beyond the minimum local effect needed to establish a defect. If the decisive fact is outside source or the sandboxed fixture, report it as needing validation.

Full audit setup

In full audit mode, resolve these values before reconnaissance:

  • Skill directory: the absolute directory containing this SKILL.md.
  • Target: the absolute repository root under review.
  • Repo name: a stable repository identifier from the directory or local Git remote. Lowercase it, replace every character outside [a-z0-9._-] with -, and require ^[a-z0-9][a-z0-9._-]{0,63}$ (never . or ..). Then append -<first 8 hex of sha256 of the absolute target path>.
  • Output directory: a new writable directory outside the target, defaulting to ~/security-audit-skill/<repo-name>/run-<N>, where <N> is the next unused integer. Create run-<N> with mkdir -m 700 (exclusive; on collision take the next <N>), and keep the resolved default path under ~/security-audit-skill/. Quote every path in shell commands. Use a directory inside the target only when the user explicitly selects it and the parent verifies that version control ignores the whole directory. Otherwise stop and request an external path.
  • Source ref: the reviewed commit and whether the worktree is dirty. Run git against the target only as git -c core.fsmonitor= -c core.hooksPath=/dev/null …, or with git ls-files, rev-parse, and log --stat. Do not treat unreviewed generated or modified files as another revision.

The files under <output-dir> are audit artifacts outside the project. The parent writes them and runs the validators itself; do not delegate this to coder. Ask the mode, profile, scope, budget, and output-directory questions once, inside the plan you present for approval, together with the estimated agent count.

Write isolation

The parent creates and is the only writer of shared run files:

  • run-metadata.json
  • architecture.md
  • coverage-ledger.json
  • findings.json
  • REPORT.md
  • FINDINGS-DETAIL.md
  • NEEDS-VALIDATION.md

Each hunter or verifier receives a unique root under <output-dir>/agents/<agent-id>/, with separate scratch/ and artifacts/ directories. Canonical agent IDs match ^[a-z0-9][a-z0-9_-]{0,63}$ and must not equal a Windows device name such as con, prn, aux, nul, com1 through com9, or lpt1 through lpt9. Lowercase IDs prevent case-fold collisions. The agent and every target-controlled process may write only to scratch/; retained artifacts/ is parent-owned, is never exposed to the sandbox, and is writable only by trusted parent-side promotion code. Agents may not change shared files, target source, retained artifacts, or another agent's directory. Do not use /tmp or the host home directory as a writable fallback.

The promotion procedure for retained artifacts is in WRITE-ISOLATION.md. On Claude Code with execution disabled there is nothing to promote; skip it.

For a reproduced check, record the command, exact test input, sandbox limits, and only the allowlisted environment variable names plus safe non-secret values needed to reproduce it. Never capture or copy the ambient environment, inherited variables, credential values, authentication state, or unrelated host paths. Launch from an empty environment rather than trying to redact one after execution.

Before delegation, the parent writes run-metadata.json with at least run_id, repo, target, source_ref, profile, scope_paths, budget (null if unset), execution_policy ("sandboxed-source-and-local-only", or "source-only" as set under Universal execution safety), selected companion files, prior-run paths, shared-file owners, and run_status: "in_progress". Update metadata only when those facts change; candidate state belongs in the coverage ledger and findings.json.

Full audit planning

Coverage and prior runs, run profiles and scope, and the cost budget are in PLANNING.md. Read it before reconnaissance in full audit mode.

Core principles

Require a boundary and result

For every candidate, name the lower-trust principal, accepted input or action, intended control, crossed boundary, affected principal or resource, and concrete observed or owner-observable result. Do not elevate a missing best practice, guessed deployment behavior, generic parser crash, or self-impact into a security finding.

Use bounded local evidence

Static analysis establishes the source path. Sandboxed local tests resolve behavior when all execution controls are available: a minimal function harness, existing unit test, small parser fixture, dummy-tenant integration test, locally rendered configuration, or bounded isolated-loopback client. Stop at a wrong return value, unauthorized dummy record, sanitizer finding, policy difference, or other minimum effect. Do not extend the local check beyond the minimum boundary result or produce persistence, post-fault, or concealment material.

Respect source visibility

Deployment controls, proxy behavior, provider settings, browser headers, identity policy, broker ACLs, packaging, and topology are real controls. If they are required and absent from the repository, do not assume either presence or absence. Use needs_validation with the exact missing fact and a safe owner-observed or local plan.

Separate priority from certainty

Only confirmed records receive severity. Likelihood and impact must reflect the demonstrated conditions and result; overall severity cannot exceed demonstrated impact. needs_validation means a specific source-grounded boundary hypothesis is blocked, not a low-confidence confirmed vulnerability, and it has no severity.

Calibrate overall severity with these anchors:

  • critical — an unauthenticated actor gains code execution, full data-store access, or takeover of arbitrary accounts.
  • high — an actor fully defeats an explicit security control with real consequences: authentication bypass, cross-tenant read or write, stored script execution affecting other users, authenticated code execution, or an unauthenticated remote stop of a shared service.
  • medium — a real boundary violation with limited blast radius, uncommon preconditions, or consequences confined to a narrow resource set.
  • low — disclosure of non-secret internals, or an effect requiring sustained effort for minimal gain.
  • informational — a confirmed but minimal-impact observation, useful mainly as a prerequisite inside a larger finding.

The high/medium discriminator: does the demonstrated result fully defeat an explicit control for an action with real consequences, or only weaken it? If you cannot state the concrete damage, the severity is lower than it feels.

Recommend the smallest effective source fix

For each confirmed finding, identify the invariant the code must enforce and the narrowest source change that enforces it at the last trusted decision point. Prefer specific repository-relative changes and regression tests over generic hardening advice. The audit describes fixes; it does not modify target source.

Full audit workflow

In full audit mode, follow all six phases in order:

  1. Reconnaissance — map the source, trust boundaries, local build paths, companion selections, prior evidence, and initial deterministic coverage ledger with RECONNAISSANCE.md.
  2. Coverage-led hunting waves — assign isolated hunters from the ledger and collect structured candidate results with HUNTING.md, ATTACK-CLASSES.md, and the selected domain companions.
  3. Candidate validation — consolidate fingerprints and give every candidate to a fresh source verifier as defined in VALIDATION-AND-REPORTING.md.
  4. Structured output — write all final confirmed, needs_validation, and rejected records to findings.json; validate it with report-schema.json and validate-findings.cjs, and validate the coverage claim with validate-coverage-ledger.cjs.
  5. Independent record verification — use fresh agents to verify final source claims and reconcile corrections or state changes.
  6. Target-neutral report — derive REPORT.md, FINDINGS-DETAIL.md, and NEEDS-VALIDATION.md from the final records, with no live-probe instructions.

Do not end the run before one of exactly two terminal states: (a) all Phase 6 artifacts are written and both validators pass, or (b) run_status: "incomplete" is recorded with its exact reason and the gap is disclosed in the report. Never stop mid-phase unless the user stops the run. If node is missing, the validators cannot run: record run_status: "incomplete" with incomplete_reason: "validators_unavailable".

Anti-patterns

  1. Checklist deviations presented as vulnerabilities.
  2. Defense-in-depth advice with no reachable boundary violation.
  3. Live or shared-environment testing where bounded local evidence is insufficient.
  4. Guessing provider, proxy, browser, identity, or deployment behavior not present in source.
  5. Treating intended same-principal authority or self-impact as a cross-boundary result.
  6. Reporting a parser or runtime effect stronger than the observed effect.
  7. Emitting prose-only hunter results that cannot be deduplicated or verified.
  8. Re-reporting carried same-source prior confirmed records or using them as exemplars that anchor the hunt.
  9. Assigning severity to needs_validation records.
  10. Writing the report before independent verification or letting prose and JSON disagree.

04 同仓库更多 Skills