agentscanner 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. agentscanner-0.1.0/.gitignore +9 -0
  2. agentscanner-0.1.0/DESIGN.md +291 -0
  3. agentscanner-0.1.0/LICENSE +201 -0
  4. agentscanner-0.1.0/PKG-INFO +127 -0
  5. agentscanner-0.1.0/README.md +105 -0
  6. agentscanner-0.1.0/hardened/README.md +29 -0
  7. agentscanner-0.1.0/hardened/settings.json +67 -0
  8. agentscanner-0.1.0/pyproject.toml +39 -0
  9. agentscanner-0.1.0/src/agentscanner/__init__.py +3 -0
  10. agentscanner-0.1.0/src/agentscanner/checks/__init__.py +13 -0
  11. agentscanner-0.1.0/src/agentscanner/checks/agentic_skills_ast.py +487 -0
  12. agentscanner-0.1.0/src/agentscanner/checks/agents_skills.py +73 -0
  13. agentscanner-0.1.0/src/agentscanner/checks/base.py +63 -0
  14. agentscanner-0.1.0/src/agentscanner/checks/env_secrets.py +115 -0
  15. agentscanner-0.1.0/src/agentscanner/checks/hooks.py +150 -0
  16. agentscanner-0.1.0/src/agentscanner/checks/mcp.py +148 -0
  17. agentscanner-0.1.0/src/agentscanner/checks/permissions.py +139 -0
  18. agentscanner-0.1.0/src/agentscanner/checks/prompts.py +59 -0
  19. agentscanner-0.1.0/src/agentscanner/cli.py +115 -0
  20. agentscanner-0.1.0/src/agentscanner/data.py +82 -0
  21. agentscanner-0.1.0/src/agentscanner/discovery.py +143 -0
  22. agentscanner-0.1.0/src/agentscanner/engine.py +54 -0
  23. agentscanner-0.1.0/src/agentscanner/models.py +112 -0
  24. agentscanner-0.1.0/src/agentscanner/parsers/__init__.py +1 -0
  25. agentscanner-0.1.0/src/agentscanner/parsers/json_parser.py +37 -0
  26. agentscanner-0.1.0/src/agentscanner/parsers/markdown_parser.py +37 -0
  27. agentscanner-0.1.0/src/agentscanner/reporters/__init__.py +17 -0
  28. agentscanner-0.1.0/src/agentscanner/reporters/cli.py +67 -0
  29. agentscanner-0.1.0/src/agentscanner/reporters/json.py +22 -0
  30. agentscanner-0.1.0/src/agentscanner/reporters/sarif.py +71 -0
  31. agentscanner-0.1.0/tests/fixtures/bad/.claude/agents/rogue.md +11 -0
  32. agentscanner-0.1.0/tests/fixtures/bad/.claude/settings.json +52 -0
  33. agentscanner-0.1.0/tests/fixtures/bad/.claude/skills/evil_skill.md +30 -0
  34. agentscanner-0.1.0/tests/fixtures/bad/.mcp.json +17 -0
  35. agentscanner-0.1.0/tests/fixtures/bad/CLAUDE.md +6 -0
  36. agentscanner-0.1.0/tests/fixtures/good/.claude/agents/helper.md +10 -0
  37. agentscanner-0.1.0/tests/fixtures/good/.claude/settings.json +38 -0
  38. agentscanner-0.1.0/tests/fixtures/good/.claude/skills/good_skill.md +29 -0
  39. agentscanner-0.1.0/tests/fixtures/good/.mcp.json +16 -0
  40. agentscanner-0.1.0/tests/test_checks.py +100 -0
@@ -0,0 +1,9 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ build/
6
+ dist/
7
+ .pytest_cache/
8
+ *.sarif
9
+ claudit.sarif
@@ -0,0 +1,291 @@
1
+ # Claude Code Configuration Security Scanner — Design Document
2
+
3
+ > Working title: **`agentscanner`** (Claude + audit). A Checkov/Terrascan-style static
4
+ > analyzer for Claude Code configuration artifacts: settings, permissions, hooks,
5
+ > MCP servers, agents/subagents, skills, slash commands, and `CLAUDE.md` memory.
6
+
7
+ Status: **DRAFT for review** · Owner: sanjeev.k2 · Last updated: 2026-06-15
8
+
9
+ ---
10
+
11
+ ## 1. Problem statement
12
+
13
+ Developers and product teams increasingly drive their SDLC through Claude Code,
14
+ customizing it with `settings.json`, hooks, skills, subagents, MCP servers, and
15
+ `CLAUDE.md` instructions — at **global (`~/.claude`), project (`.claude/`), local,
16
+ and enterprise/managed** scopes. These artifacts are *powerful by design*: a hook
17
+ is arbitrary code that runs on every tool call; an MCP server is an arbitrary
18
+ process; a permission rule decides what the agent may do without asking; a skill
19
+ or `CLAUDE.md` is untrusted text that steers the model.
20
+
21
+ Misconfigurations and malicious contributions in these files create real risk:
22
+ **code execution, credential exfiltration, permission bypass, supply-chain
23
+ compromise, and prompt injection** — yet there is no `checkov` for them. Reviewers
24
+ eyeball JSON and Markdown by hand, and CI has nothing to gate on.
25
+
26
+ `agentscanner` fills that gap: a fast, **static, read-only** scanner that discovers
27
+ Claude Code artifacts, evaluates them against a curated policy catalog, and emits
28
+ prioritized, framework-mapped findings (CLI table, JSON, SARIF) suitable for local
29
+ use, pre-commit, and CI.
30
+
31
+ ### Non-goals (v1)
32
+ - Not a runtime/EDR monitor — it does not observe a live Claude Code session.
33
+ - Not a full "effective permission" simulator — cross-file precedence is handled by
34
+ a *targeted* check class, not a complete merge engine (see §6, deferred to v2).
35
+ - Not an LLM-based reviewer — checks are deterministic. (An optional
36
+ `--llm-assist` triage pass is a roadmap item, off by default.)
37
+
38
+ ---
39
+
40
+ ## 2. Core security invariant — the scanner never executes what it parses
41
+
42
+ `agentscanner` ingests *untrusted* config and prompt files. The single most important
43
+ property: **it MUST NOT execute, source, shell-expand, resolve, or network-fetch
44
+ anything it reads.**
45
+
46
+ - No running hook commands, `apiKeyHelper`, `statusLine`, or `awsCredentialExport`
47
+ scripts.
48
+ - No launching MCP servers (`command`/`args` are inspected as data, never spawned).
49
+ - No shell evaluation of interpolated strings; no `eval`, no `subprocess` of parsed
50
+ content; no following of `url`/`command` targets over the network.
51
+ - File reads are bounded (size cap, no symlink-following outside the scan root).
52
+
53
+ This is both a safety property (the moment a scanner execs untrusted input, it
54
+ *becomes* the vulnerability) and a selling point we state in the README.
55
+
56
+ ---
57
+
58
+ ## 3. What we scan (artifact taxonomy)
59
+
60
+ Grounded in the **current** Claude Code schema (verified against live docs,
61
+ 2026-06; see §11 sources), not memory.
62
+
63
+ | Artifact | Locations (user / project / local / managed / plugin) | Format | Why it matters |
64
+ |---|---|---|---|
65
+ | **Settings** | `~/.claude/settings.json`, `.claude/settings.json`, `.claude/settings.local.json`, managed `/managed-settings.json`, plugin settings | JSON | permissions, hooks, env, MCP, code-exec helpers, permission mode |
66
+ | **Hooks** | inside settings (`hooks`), agent frontmatter (`hooks`) | JSON | arbitrary command/http/mcp/agent execution at 30+ lifecycle events |
67
+ | **MCP servers** | `.mcp.json`, settings `mcpServers`, agent `mcpServers` | JSON | arbitrary process / remote endpoint; plaintext secrets; supply chain |
68
+ | **Agents / subagents** | `~/.claude/agents/*.md`, `.claude/agents/*.md`, plugin `agents/` | Markdown + YAML frontmatter | tool grants, `permissionMode`, model, prompt content |
69
+ | **Skills** | `~/.claude/skills/*/SKILL.md`, `.claude/skills/...`, plugin `skills/` | Markdown + YAML frontmatter | `allowed-tools`, auto-invocation, prompt content |
70
+ | **Slash commands** | `~/.claude/commands/*.md`, `.claude/commands/*.md` | Markdown + (optional) frontmatter | `allowed-tools`, prompt content |
71
+ | **Memory / instructions** | `CLAUDE.md`, `.claude/CLAUDE.md`, imported memory files | Markdown | prompt-injection / steering vector |
72
+ | **Plugin manifest** | `.claude-plugin/marketplace.json`, `plugin.json` | JSON | provenance / trust of bundled artifacts |
73
+
74
+ ---
75
+
76
+ ## 4. Threat model (what the checks defend against)
77
+
78
+ Mapped to OWASP LLM Top 10, OWASP Agentic threats, and NIST AI RMF where relevant.
79
+
80
+ | # | Threat | Example | Primary framework |
81
+ |---|---|---|---|
82
+ | T1 | **Arbitrary code execution via hooks/helpers** | hook runs `curl … \| sh`; `apiKeyHelper` points to a fetched script | OWASP LLM05 (Improper Output Handling) / Agentic "tool misuse" |
83
+ | T2 | **Permission over-grant** | `Bash(*)`, `Bash(curl:*)`, unscoped `sudo`/`rm`/`eval` in `allow` | Agentic "excessive autonomy"; LLM06 Excessive Agency |
84
+ | T3 | **Permission bypass / weakened posture** | `defaultMode: bypassPermissions`, `dontAsk` misuse, project file re-allowing a managed/user deny | LLM06; NIST GOVERN/MANAGE |
85
+ | T4 | **Credential exfil / MITM via endpoint redirect** | `ANTHROPIC_BASE_URL`/`ANTHROPIC_AUTH_TOKEN` pointed at a non-Anthropic host | LLM02 Sensitive Info Disclosure |
86
+ | T5 | **Hardcoded secrets** | plaintext API keys/tokens in `env`, MCP `env`, settings | LLM02 |
87
+ | T6 | **MCP supply chain / untrusted server** | `npx -y`/`uvx` unpinned remote package; auto-trust all project MCP; remote `http://` MCP | LLM03 Supply Chain; MCP guidance |
88
+ | T7 | **Prompt injection in steering files** | `CLAUDE.md`/skill/agent text saying "ignore previous instructions", "disable hooks", exfil instructions; zero-width/bidi unicode | LLM01 Prompt Injection |
89
+ | T8 | **Over-privileged agents/skills** | agent `tools: *` + `permissionMode: bypassPermissions`; skill auto-invocable with broad tools | LLM06 Excessive Agency |
90
+ | T9 | **Hook command/shell injection** | hook does `sh -c "… $tool_input …"` interpolating untrusted input | LLM05 |
91
+
92
+ ---
93
+
94
+ ## 5. Check catalog (v1 MVP — high precision over breadth)
95
+
96
+ IDs follow **`CC-<CATEGORY>-NNN`** (CC = Claude Code). Each check declares the
97
+ resource type(s) it applies to, a severity, a message, a remediation, and a
98
+ framework mapping. Severities: `CRITICAL / HIGH / MEDIUM / LOW / INFO`.
99
+
100
+ **MVP set (~14, implemented first):**
101
+
102
+ | ID | Severity | Title | Applies to |
103
+ |---|---|---|---|
104
+ | `AS-HOOK-001` | CRITICAL | Hook fetches & executes remote code (`curl\|sh`, `wget\|sh`, `eval $(curl)`) | hooks |
105
+ | `AS-HOOK-002` | HIGH | Hook command runs script from relative/world-writable/untrusted path | hooks |
106
+ | `AS-HOOK-003` | MEDIUM | Context-injecting hook (SessionStart/UserPromptSubmit/InstructionsLoaded) makes network calls | hooks |
107
+ | `AS-HOOK-004` | LOW | Hook has no `timeout` (or excessive timeout) | hooks |
108
+ | `AS-PERM-001` | HIGH | Permission mode weakens prompts (`bypassPermissions` / `dontAsk` as default) | settings |
109
+ | `AS-PERM-002` | HIGH | Overly broad Bash allow (`Bash(*)`, `Bash(:*)`, bare-wildcard rules) | settings |
110
+ | `AS-PERM-003` | MEDIUM | Dangerous command allowed unscoped (`curl`, `sudo`, `rm`, `eval`, `chmod`, `nc`) | settings |
111
+ | `AS-MCP-001` | HIGH | Plaintext secret in MCP `env` (key/token pattern) | mcp |
112
+ | `AS-MCP-002` | HIGH | Remote MCP server over non-HTTPS `http://` | mcp |
113
+ | `AS-MCP-003` | HIGH | `enableAllProjectMcpServers: true` (auto-trusts all project MCP) | settings |
114
+ | `AS-MCP-004` | MEDIUM | stdio MCP uses unpinned remote fetch (`npx -y`, `uvx` w/o version) | mcp |
115
+ | `AS-ENV-001` | HIGH | API endpoint/token redirected to non-Anthropic host (`ANTHROPIC_BASE_URL`/`_AUTH_TOKEN`) | settings |
116
+ | `AS-SECRET-001` | HIGH | Hardcoded secret/API key anywhere in a config file | settings, mcp, agent |
117
+ | `AS-AGENT-001` | HIGH | Over-privileged agent/skill (`tools: *`/`All` **and** `permissionMode: bypassPermissions`/`acceptEdits`) | agent, skill |
118
+ | `AS-PROMPT-001` | MEDIUM | Prompt-injection / steering indicators in `CLAUDE.md`/skill/agent (incl. zero-width & bidi unicode) | agent, skill, command, memory |
119
+
120
+ **Roadmap (v1.x / v2):** `AS-ENV-002` (code-exec helpers `apiKeyHelper`/`statusLine`/`awsCredentialExport` → review), `AS-HOOK-005` (unsafe `tool_input` interpolation), `AS-MCP-005` (unknown/untrusted server vs. allowlist), `CC-XFILE-001` (project re-allows a denied rule — needs cross-file pass), `CC-XFILE-002` (committed permissive `settings.local.json` not gitignored), `AS-PROMPT-002` (large base64/obfuscated blobs).
121
+
122
+ > **Bypass checks rest on verified matching semantics, not guesses.** Claude Code
123
+ > matches Bash rules with space-boundary-aware wildcards, splits compound commands
124
+ > on `&& || ; | & \n` and matches each subcommand independently, strips a fixed set
125
+ > of wrappers (`timeout`, `nice`, …) but NOT `npx`/`docker exec`, and resolves
126
+ > `deny > ask > allow` with managed scope unoverridable. `AS-PERM-002/003` encode
127
+ > exactly this so we don't ship confident false positives (see §11).
128
+
129
+ ---
130
+
131
+ ## 6. Architecture
132
+
133
+ ```
134
+ ┌────────────┐
135
+ scan target → │ Discovery │ walk user/project/local/managed/plugin scopes,
136
+ └─────┬──────┘ classify each file → ArtifactType
137
+
138
+ ┌─────▼──────┐
139
+ │ Parsers │ JSON (position-preserving) + Markdown/YAML
140
+ └─────┬──────┘ frontmatter → normalized IR with line map
141
+
142
+ ┌─────▼──────┐ Resource{ type, path, attrs, raw, line_index }
143
+ │ IR │
144
+ └─────┬──────┘
145
+
146
+ ┌─────▼──────┐ registry of Check objects; each declares
147
+ │ Engine │ applies_to + run(resource) → [Finding]
148
+ └─────┬──────┘ (single-file checks now; cross-file class = v2)
149
+
150
+ ┌─────▼──────┐ baseline/suppression, severity threshold,
151
+ │ Findings │ inline `# agentscanner:ignore CC-XXX` directives
152
+ └─────┬──────┘
153
+
154
+ ┌─────▼──────┐ CLI table · JSON · SARIF (GitHub code scanning)
155
+ │ Reporters │ exit code from --fail-on / --soft-fail
156
+ └────────────┘
157
+ ```
158
+
159
+ ### Key design decisions (locked now — costly to retrofit)
160
+ 1. **Line mapping is in the IR from day one.** Every `Resource` carries a
161
+ `value → (line, col)` index. JSON via a position-preserving parse; YAML
162
+ frontmatter via `ruamel.yaml` (line-aware). Findings always cite `file:line`.
163
+ 2. **Per-file scanning for v1.** No global effective-merge resolver. Cross-file
164
+ posture issues (project re-allowing a managed/user deny) are a *separate check
165
+ class* run after all files parse — explicitly deferred to v2 to bound scope.
166
+ 3. **Curated, high-precision MVP** (~14 checks). Noise on day one kills adoption;
167
+ breadth is additive later.
168
+ 4. **Two check authoring styles.** (a) Python `Check` subclasses for logic-heavy
169
+ rules; (b) declarative **YAML policies** (jsonpath/regex/conditions) for simple,
170
+ community-contributable rules — loaded from a built-in dir and `--policy-dir`.
171
+ 5. **Rules are independently authored.** The `awesome-claude-security` repo
172
+ (GPL-3.0) is used as *inspiration and as a fixture corpus to scan*, never as
173
+ copied rule text/taxonomy — keeping `agentscanner` free to license permissively
174
+ (Apache-2.0 proposed). See §10.
175
+
176
+ ### Module layout
177
+ ```
178
+ src/agentscanner/
179
+ cli.py # Typer CLI
180
+ models.py # Severity, ArtifactType, Resource (IR), Finding
181
+ discovery.py # scope walking + classification
182
+ parsers/ # json_parser.py (line-aware), markdown_parser.py (frontmatter)
183
+ checks/
184
+ base.py # Check ABC + @register; severity/framework metadata
185
+ permissions.py mcp.py hooks.py env_secrets.py agents_skills.py prompts.py
186
+ policies/ # built-in declarative YAML rules
187
+ reporters/ # cli.py json.py sarif.py
188
+ data/ # secret regexes, dangerous-command list, allow/deny patterns
189
+ hardened/ # reference hardened settings (item 5) — the canonical GOOD fixture
190
+ tests/fixtures/{bad,good}/ # paired per-check fixtures (see §8)
191
+ ```
192
+
193
+ ---
194
+
195
+ ## 7. CLI UX (Checkov-flavored)
196
+
197
+ ```
198
+ agentscanner scan [PATH] # default: scan ./ (+ optional --include-user)
199
+ --include-user # also scan ~/.claude
200
+ --framework all|settings|hooks|mcp|agents|skills|prompts
201
+ --check AS-HOOK-001,... # run only these
202
+ --skip-check AS-PERM-003,... # skip these
203
+ --severity-threshold HIGH # only report >= threshold
204
+ --output cli|json|sarif # default cli
205
+ --output-file results.sarif
206
+ --baseline .agentscanner.baseline.json # suppress known/accepted findings
207
+ --config .agentscanner.yaml # project config (skips, thresholds, policy-dir)
208
+ --policy-dir ./policies # load custom YAML policies
209
+ --fail-on HIGH # exit nonzero if any finding >= level (CI gate)
210
+ --soft-fail # always exit 0
211
+ agentscanner list-checks # print catalog (id, severity, title)
212
+ agentscanner version
213
+ ```
214
+
215
+ > **v1 implements a subset of the flags above.** Shipped now: `scan` (with
216
+ > `--include-user`, `--check`, `--skip-check`, `--severity-threshold`, `--output`
217
+ > cli/json/sarif, `--output-file`, `--fail-on`, `--soft-fail`), `list-checks`,
218
+ > `version`. **Roadmap:** `--baseline`, `--config`, `--policy-dir` and the
219
+ > declarative-YAML policy engine (the `policies/` dir). v1 ships Python-coded
220
+ > checks only; shared patterns live in `data.py` (not a separate `data/` dir).
221
+ Distribution: **PyPI** (`pip install agentscanner` / `pipx`/`uvx`), plus a published
222
+ **pre-commit hook** and a **GitHub Action** wrapper. Python 3.9+.
223
+
224
+ ---
225
+
226
+ ## 8. Verification plan (item 3)
227
+
228
+ **Paired fixtures, not one clean run.** `tests/fixtures/bad/` has one minimal
229
+ artifact per check that MUST trigger exactly that finding; `tests/fixtures/good/`
230
+ holds clean artifacts that MUST scan with zero findings. The **`hardened/`
231
+ reference settings are the canonical known-good fixture**, and every hardening
232
+ choice maps 1:1 to a check — the hardened config and the catalog are duals.
233
+
234
+ Additional verification:
235
+ - Run `agentscanner` against **real corpora**: this machine's `~/.claude` (settings,
236
+ hooks, agents, skills) and a checkout of `awesome-claude-security` — confirm
237
+ signal, measure false-positive rate, hand-triage.
238
+ - Golden-output snapshot tests for JSON/SARIF.
239
+ - SARIF validated against the schema so GitHub code scanning ingests it.
240
+
241
+ ---
242
+
243
+ ## 9. Hardened reference settings (item 5)
244
+
245
+ Ship `hardened/settings.json` (+ commentary in `hardened/README.md`) as an
246
+ opinionated secure baseline teams can adopt: explicit `deny` for secret-file
247
+ reads/edits, scoped `ask` for `sudo`/`git push`, no `bypassPermissions` default,
248
+ no endpoint redirection, fail-open security hooks with timeouts, pinned MCP
249
+ servers, and no plaintext secrets. Each line is annotated with the `CC-*` check it
250
+ satisfies, making the file both documentation and the primary good-fixture.
251
+
252
+ ---
253
+
254
+ ## 10. Licensing & provenance
255
+
256
+ - **`agentscanner` license: Apache-2.0** (permissive; PyPI-friendly).
257
+ - `awesome-claude-security` is **GPL-3.0**. We treat it strictly as *inspiration*
258
+ and as an input corpus to scan; we do **not** copy its rule text, taxonomy, or
259
+ structure into the package (which could force GPL on `agentscanner`). Cited as prior
260
+ art in README, not vendored.
261
+
262
+ ---
263
+
264
+ ## 11. Sources (verified, current as of 2026-06)
265
+
266
+ Permission/settings/hook/agent semantics confirmed against live Claude Code docs
267
+ (`code.claude.com/docs`: `permissions`, `settings`, `env-vars`, `hooks`,
268
+ `mcp-quickstart`, `sub-agents`, `commands`). Threat framing draws on the curated
269
+ AI-security corpus: OWASP LLM Top 10 (`LLMAll_en-US_FINAL.pdf`), OWASP Agentic
270
+ threats (`Agentic-AI-Threats-and-Mitigations_v1.0a.pdf`,
271
+ `OWASP-Top-10-for-Agentic-Applications-2026-12.6-1.pdf`), MCP security
272
+ (`A-Practical-Guide-for-Secure-MCP-Server-Development…pdf`,
273
+ `…Securely-Using-third-party-MCP-Servers1.0.pdf`), and NIST AI RMF
274
+ (`AI_RMF_Playbook.pdf`).
275
+
276
+ Key verified semantics encoded by checks:
277
+ - Bash rule wildcards are space-boundary aware (`Bash(ls:*)` ≠ `lsof`); compound
278
+ commands split on `&& || ; | & \n`, each subcommand matched independently;
279
+ wrappers `timeout/time/nice/nohup/stdbuf/xargs` stripped, but `npx/docker exec/
280
+ uvx` are NOT.
281
+ - Resolution order **deny → ask → allow**; scope precedence **managed > CLI >
282
+ local > project > user**; managed deny is unoverridable.
283
+ - Permission modes: `default, acceptEdits, plan, auto, dontAsk, bypassPermissions`;
284
+ `--dangerously-skip-permissions` = session `bypassPermissions`.
285
+ - Code-exec settings keys: `hooks, apiKeyHelper, awsCredentialExport,
286
+ awsAuthRefresh, gcpAuthRefresh, otelHeadersHelper, statusLine, mcpServers`.
287
+ - Posture env vars: `ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN, ANTHROPIC_API_KEY`,
288
+ `CLAUDE_CODE_CERT_STORE`, `DISABLE_*`.
289
+ - 30+ hook events; context-injecting ones (SessionStart, UserPromptSubmit,
290
+ InstructionsLoaded) add stdout to model context (injection-relevant).
291
+ ```
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or Derivative
95
+ Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Sanjeev Jaiswal
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,127 @@
1
+ Metadata-Version: 2.4
2
+ Name: agentscanner
3
+ Version: 0.1.0
4
+ Summary: Static security scanner for agentic AI configuration: settings, permissions, hooks, MCP servers, agents, skills, and steering files (Checkov for AI agent stacks).
5
+ Project-URL: Homepage, https://github.com/jassics/agentscanner
6
+ Project-URL: Issues, https://github.com/jassics/agentscanner/issues
7
+ Author-email: "Sanjeev Jaiswal (Jassi)" <jassics@gmail.com>
8
+ License: Apache-2.0
9
+ License-File: LICENSE
10
+ Keywords: agent-security,agentic-ai,claude-code,devsecops,llm-security,mcp,sast,security,static-analysis
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Topic :: Security
17
+ Requires-Python: >=3.9
18
+ Requires-Dist: pyyaml>=6.0
19
+ Requires-Dist: rich>=13.0
20
+ Requires-Dist: typer>=0.12
21
+ Description-Content-Type: text/markdown
22
+
23
+ # agentscanner
24
+
25
+ **Static security scanner for Claude Code configuration** — settings,
26
+ permissions, hooks, MCP servers, agents/subagents, skills, slash commands, and
27
+ `CLAUDE.md`. Think *Checkov / Terrascan, but for your `.claude/` directory.*
28
+
29
+ Claude Code is customized through powerful, trust-bearing artifacts: a hook is
30
+ arbitrary code that runs on every tool call; an MCP server is an arbitrary
31
+ process; a permission rule decides what the agent may do without asking; a skill
32
+ or `CLAUDE.md` is untrusted text that steers the model. Misconfigurations and
33
+ malicious contributions create real risk — code execution, credential exfil,
34
+ permission bypass, supply-chain compromise, and prompt injection. `agentscanner` finds
35
+ them.
36
+
37
+ ## Core safety invariant
38
+
39
+ > **agentscanner never executes what it parses.** It does not run hook commands,
40
+ > launch MCP servers, resolve `apiKeyHelper`/`statusLine` scripts, or fetch any
41
+ > URL. It reads untrusted config as *data only* — the moment a scanner execs its
42
+ > input, it becomes the vulnerability.
43
+
44
+ ## Install
45
+
46
+ ```bash
47
+ pip install agentscanner # or: pipx install agentscanner / uvx agentscanner
48
+ ```
49
+
50
+ ## Usage
51
+
52
+ ```bash
53
+ agentscanner scan . # scan the current repo's .claude/, .mcp.json, CLAUDE.md
54
+ agentscanner scan . --include-user # also scan ~/.claude (user scope)
55
+ agentscanner scan . --severity-threshold HIGH
56
+ agentscanner scan . --output sarif --output-file agentscanner.sarif # for GitHub code scanning
57
+ agentscanner scan . --fail-on HIGH # CI gate: nonzero exit on HIGH+ findings
58
+ agentscanner list-checks # show the check catalog
59
+ ```
60
+
61
+ Every resource is tagged with its **scope** (project / local / user / managed /
62
+ plugin), so a single run cleanly covers a repo, your global config, or both.
63
+
64
+ ## Check catalog (v1)
65
+
66
+ | ID | Severity | What it catches |
67
+ |---|---|---|
68
+ | `AS-HOOK-001` | CRITICAL | Hook fetches & executes remote code (`curl\|sh`, `eval $(curl)`) |
69
+ | `AS-HOOK-002` | HIGH | Hook runs a script from a relative / world-writable path |
70
+ | `AS-HOOK-003` | MEDIUM | Context-injecting hook (SessionStart/UserPromptSubmit) makes network calls |
71
+ | `AS-HOOK-004` | LOW | Hook has no `timeout` |
72
+ | `AS-PERM-001` | HIGH | `defaultMode: bypassPermissions` / `acceptEdits` weakens prompts |
73
+ | `AS-PERM-002` | HIGH | Overly broad Bash allow (`Bash(*)`, `Bash(:*)`) |
74
+ | `AS-PERM-003` | MEDIUM | Dangerous command allowed unscoped (`curl`, `sudo`, `rm`, `eval`, …) |
75
+ | `AS-MCP-001` | HIGH | Plaintext secret in MCP server `env` |
76
+ | `AS-MCP-002` | HIGH | Remote MCP server over cleartext `http://` |
77
+ | `AS-MCP-003` | HIGH | `enableAllProjectMcpServers: true` (auto-trust all project MCP) |
78
+ | `AS-MCP-004` | MEDIUM | stdio MCP pulls an unpinned remote package (`npx -y pkg`) |
79
+ | `AS-ENV-001` | HIGH | API endpoint/token redirected away from Anthropic |
80
+ | `AS-SECRET-001` | HIGH | Hardcoded secret/API key in a config file |
81
+ | `AS-AGENT-001` | HIGH | Over-privileged agent/skill (`bypassPermissions`, `tools: *`) |
82
+ | `AS-PROMPT-001` | MEDIUM | Prompt-injection / hidden-unicode indicators in steering files |
83
+ | `AS-SKILL-001` | CRITICAL | Skill requests write access to agent identity files |
84
+ | `AS-SKILL-002` | HIGH | Skill has a social-engineering `Prerequisites` section with pipe-to-shell |
85
+ | `AS-SKILL-003` | HIGH | Universal-Format skill missing a cryptographic signature |
86
+ | `AS-SKILL-004` | HIGH | Skill sets `permissions.network: true` (binary boolean, not a domain allowlist) |
87
+ | `AS-SKILL-005` | HIGH | Skill declares explicit shell access |
88
+ | `AS-SKILL-006` | HIGH | Skill `risk_tier` contradicts declared permissions (risk-tier spoofing) |
89
+ | `AS-SKILL-007` | CRITICAL | Skill file contains YAML unsafe-execution tags |
90
+ | `AS-SKILL-008` | HIGH | Skill explicitly disables sandboxed execution |
91
+ | `AS-SKILL-009` | MEDIUM | Universal-Format skill missing `version` field (update-drift risk) |
92
+ | `AS-SKILL-010` | MEDIUM | Skill body contains a standalone base64-encoded block (obfuscated payload) |
93
+ | `AS-SKILL-011` | MEDIUM | Universal-Format skill missing `publisher` field (governance gap) |
94
+ | `AS-SKILL-012` | MEDIUM | Multi-platform skill missing a signature (security metadata lost in translation) |
95
+
96
+ See [`DESIGN.md`](DESIGN.md) for the architecture, threat model, and the verified
97
+ Claude Code semantics the permission checks are grounded in. A secure baseline
98
+ config lives in [`hardened/`](hardened/).
99
+
100
+ ## CI
101
+
102
+ GitHub Actions (SARIF upload to code scanning):
103
+
104
+ ```yaml
105
+ - run: pipx install agentscanner
106
+ - run: agentscanner scan . --output sarif --output-file agentscanner.sarif --soft-fail
107
+ - uses: github/codeql-action/upload-sarif@v3
108
+ with: { sarif_file: agentscanner.sarif }
109
+ ```
110
+
111
+ pre-commit:
112
+
113
+ ```yaml
114
+ - repo: local
115
+ hooks:
116
+ - id: agentscanner
117
+ name: agentscanner
118
+ entry: agentscanner scan . --fail-on HIGH
119
+ language: system
120
+ pass_filenames: false
121
+ ```
122
+
123
+ ## Prior art & license
124
+
125
+ Inspired by [`awesome-claude-security`](https://github.com/jassics/awesome-claude-security)
126
+ (used as inspiration and as a corpus to scan, not as a source of rule text).
127
+ All rules are independently authored. **License: Apache-2.0.**