Skip to main content
Glama
sec-audit-swarm
by mesutgungor
README.md
# `sec-audit-swarm`

**An offline, multi-agent defensive source-code security audit swarm, Antigravity Plugin, stdio MCP Server, and Python CLI.**

`sec-audit-swarm` combines **10+ deterministic security engines** (SAST, IaC, SCA + call-graph reachability, Secrets, AI/MCP, CI/CD, OpenAPI, SBOM) with **coverage-led multi-agent auditing**, **disclosure-grade adversarial verification**, **diff-anchored PR reviews**, and **closed-loop worktree patch verification** — all strictly offline and read-only against your target repository.

---

## Key Capabilities

- **Deterministic Polyglot Preflight (Offline):** Orchestrates built-in Python AST / Dockerfile / Compose / Secret analyzers alongside local `semgrep` (**33** baseline rules + **132** vendored AI/MCP best-practice rules), `bandit`, `ruff`, `gosec`, `cppcheck`, `shellcheck`, `gitleaks`, `trivy` (IaC + SCA), `checkov`, `osv-scanner`, and `zizmor`.
- **AI, LLM & MCP Server Security Scanner:** Dedicated AST and config checks for MCP tool command injection, SSRF, path traversal, tool poisoning, unpinned `npx`/`uvx`, plaintext `mcp.json` secrets, wildcard `autoApprove`, unsafe ML deserialization (`torch.load`), and hidden Unicode directives.
- **SCA Static Call-Graph Reachability:** Classifies dependency CVEs as `reachable_direct`, `imported_only`, or `transitive_or_unused` across Python, JS/TS, and Go.
- **Semantic File Grouping & Coverage Ledger:** Groups coupled files into token-bounded domain bundles (`G-XXX`) and tracks per-unit audit completion (`audited`, `not_applicable`, `pending`, `stale_needs_revalidation`) with SHA-256 additive `--resume-from` support.
- **Mechanical Separation of Duties & 3-State Verdicts:** SQLite WAL blackboard (`blackboard.db`) + append-only `audit_log.jsonl` enforces `verifier_worker != author_worker`, separates `vulnerability` vs. defense-in-depth `hardening_note`, and assigns `needs_validation` items `severity: unassigned` + explicit `unresolved_question` (exported to `NEEDS-VALIDATION.md`).
- **Disclosure-Grade Verifier Metadata:** Tracks `verification_tier` (`static_verified` vs. `runtime_reproduced`), `preconditions`, `mitigated_paths`, and `existing_test_refs` across Markdown, JSON, and SARIF 2.1.0.
- **Diff-Anchored GitHub & GitLab PR Reviews:** Parses `git diff --unified=0` hunks, verifies disk line bounds, auto-corrects minor line drift, and exports ready-to-post `github_pr_review.json`, `gitlab_mr_review.json`, and `pr_review_comment.md`.
- **Rule-Routing Debugger & Per-Repo Policy:** `.sec-audit-rules.json` supports custom regex rules, scanner disables, path exclusions, and severity overrides; `rules-check <target> <file>` explains exactly which scanners and rules apply to any file.
- **Closed-Loop Non-Destructive Remediation:** Generates unified `.diff` patches + defensive regression unit tests and verifies them inside ephemeral temporary Git worktrees without ever modifying the target repository.
- **Audit-Grade Exports:** Emits `report.sarif` (SARIF 2.1.0), `report.md`, `NEEDS-VALIDATION.md`, `findings.json`, `coverage-ledger.json`, `validation_report.json`, `custom_semgrep_rules.yml`, `threat_model_and_compliance.md` (Mermaid trust-boundary diagram + 6-framework compliance matrix), and `sbom.cdx.json` (CycloneDX SBOM).
- **Zero-Dependency Stdio MCP Server:** Exposes 10 defensive tools over JSON-RPC 2.0 (`sec-audit-swarm mcp-server`) for Antigravity, Claude Code, Cursor, VS Code, or any MCP client.

---

## Installation

`sec-audit-swarm` requires **Python 3.10+** and has **zero required Python runtime dependencies** (stdlib only).

```bash
git clone https://github.com/mesutgungor/sec-audit-swarm.git
cd sec-audit-swarm
python3 -m pip install -e .
```

### Optional Local Scanner Binaries (Recommended)
Install any subset of local scanners you want `init` to auto-detect and orchestrate:
```bash
# macOS (Homebrew)
brew install semgrep bandit ruff trivy checkov osv-scanner gitleaks shellcheck gosec cppcheck zizmor
```

---

## Quick Start

### 1. Standalone CLI Audit
```bash
# 1. Run static preflight & seed coverage ledger
sec-audit-swarm init /path/to/repo --db audit_state/blackboard.db

# 2. Inspect status, coverage ledger, and semantic file groups
sec-audit-swarm status --db audit_state/blackboard.db
sec-audit-swarm coverage list --db audit_state/blackboard.db
sec-audit-swarm group-files /path/to/repo --max-tokens 12000

# 3. Debug which scanners, Semgrep rules, and custom policies apply to a file
sec-audit-swarm rules-check /path/to/repo path/to/file.py

# 4. Independently verify findings (verifier != author)
sec-audit-swarm verify-finding F-001 --db audit_state/blackboard.db \
  --verdict verified --verifier static-verifier --kind vulnerability \
  --preconditions "Default config" --rationale "Confirmed unmitigated sink."

# 5. Deterministically validate integrity & export all 9 audit artifacts
sec-audit-swarm validate-run --db audit_state/blackboard.db
sec-audit-swarm export --db audit_state/blackboard.db --out audit_state

# 6. Export diff-anchored GitHub/GitLab PR review & evaluate CI policy gate
sec-audit-swarm pr-review --db audit_state/blackboard.db --base-ref main --out audit_state
sec-audit-swarm gate --db audit_state/blackboard.db --fail-on critical,high
```

### 2. Antigravity Plugin (Native Swarm & `run_workflow`)
This repository is packaged as a native **Antigravity Plugin** (`plugin.json`, `skills/defensive-audit-swarm/`, `rules/AGENTS.md`, `mcp_config.json`, `assets/logo.svg`).

To install locally in Antigravity:
```bash
cp -R . ~/.gemini/config/plugins/sec-audit-swarm
```
Then invoke `/defensive-audit-swarm <TARGET_DIR>` to launch either:
- **Mode 1 (Native Interactive Swarm):** Parallel domain specialists (`auth-access`, `input-dataflow`, `crypto-secrets`, `container-config`, `ai-mcp-agentic`) + independent adversarial verifier(s) on the live Swarm board.
- **Mode 2 (Deterministic `run_workflow`):** Automated phased pipeline via `workflows/defensive_audit_workflow.py` (including Phase 2.5 Coverage Critic and Phase 4 pre-export validation).

### 3. MCP Server (Antigravity, Claude Code, Cursor, VS Code)
Add `sec-audit-swarm` to your MCP client configuration:
```json
{
  "mcpServers": {
    "sec-audit-swarm": {
      "command": "python3",
      "args": ["-m", "sec_audit", "mcp-server"]
    }
  }
}
```
Exposed MCP tools: `sec_audit_scan`, `sec_audit_rules_check`, `sec_audit_group_files`, `sec_audit_reachability`, `sec_audit_list_findings`, `sec_audit_coverage_ledger`, `sec_audit_validate_run`, `sec_audit_pr_review`, `sec_audit_export`, and `sec_audit_gate`.

### 4. Incremental PR Mode, Additive Resume & Repo Policy
- **Git-diff PR scoping:** `sec-audit-swarm init /path/to/repo --since main`
- **Additive multi-run resume:** `sec-audit-swarm init /path/to/repo --resume-from <PREV_RUN_ID>` (carries forward SHA-256-unchanged coverage units and verdicts; marks modified files `stale_needs_revalidation`).
- **Suppressions:** Place `.sec-audit-ignore` in your target repo (`CWE-328`, `fp:<hash>`, `file.py:42`, `vendor/`).
- **Custom rules & overrides:** Place `.sec-audit-rules.json` in your target repo to add custom regex rules, disable specific scanners/CWEs, exclude globs, or override severities by path.

---

## Repository Structure

```text
sec-audit-swarm/
├── plugin.json                        # Antigravity Plugin manifest
├── mcp_config.json                    # Stdio MCP Server definition
├── pyproject.toml                     # Python package & CLI entrypoints
├── rules/AGENTS.md                    # Defensive audit workspace/plugin rules
├── skills/defensive-audit-swarm/      # Skill + 7 modular domain playbooks
├── assets/logo.svg                    # Plugin icon
├── sec_audit/                         # Core engine (blackboard, scanners, MCP, exports)
│   └── rules/                         # Bundled offline Semgrep baseline + AI/MCP rules
├── workflows/                         # Antigravity run_workflow pipelines
├── sample_app/                        # Intentional test fixture for smoke-testing
└── tests/                             # Unit & integration test suite
```

## Defensive Scope
`sec-audit-swarm` is strictly an **offline, static, defensive auditing and hardening toolkit**. It does not generate exploit payloads or perform active network probing against live services.

## License
MIT License — see [LICENSE](./LICENSE).

TDQS

B3.4/5.0

Scored across 10 tools

Disambiguation5/5

Each tool targets a distinct phase of the audit workflow: scanning, rule explanation, file grouping, reachability, findings listing, PR anchoring, export, gating, coverage, and validation. Boundaries are clear despite scan/validate/gate all relating to audit execution because their inputs and outputs differ.

Naming Consistency3/5

All names share the sec_audit_ prefix, but suffixes mix verbs, nouns, and noun_verb combinations (scan, rules_check, group_files, reachability, coverage_ledger, validate_run). Readable but not a consistent verb_noun convention.

Tool Count5/5

10 tools is well-scoped for a multi-stage security audit workflow, with each phase represented once. No obvious padding.

Completeness4/5

The surface covers the scan-to-report lifecycle: scan, rules, grouping, reachability, findings, PR review, export, gate, coverage, and validation. Minor gap: no explicit tool to update finding status/verification or manage blackboard runs, though list_findings filters by status.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues