ai-install-guard 0.0.0-stage → 0.1.0
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.
- package/.claude-plugin/marketplace.json +23 -0
- package/.claude-plugin/plugin.json +23 -0
- package/CHANGELOG.md +21 -0
- package/LICENSE +201 -0
- package/README.md +110 -2
- package/hooks/guard/decisions.ts +91 -0
- package/hooks/guard/pane.tsx +206 -0
- package/hooks/guard/view.ts +69 -0
- package/hooks/hooks.json +1 -0
- package/hooks/mod-host.ts +31 -0
- package/hooks/register.tsx +154 -0
- package/hooks/scan/checks/code.ts +536 -0
- package/hooks/scan/checks/context.ts +655 -0
- package/hooks/scan/checks/hooks.ts +156 -0
- package/hooks/scan/checks/magic.ts +40 -0
- package/hooks/scan/checks/mod.ts +290 -0
- package/hooks/scan/checks/patterns.ts +106 -0
- package/hooks/scan/checks/prompts.ts +316 -0
- package/hooks/scan/checks/quality.ts +56 -0
- package/hooks/scan/checks/secrets.ts +107 -0
- package/hooks/scan/checks/structure.ts +357 -0
- package/hooks/scan/checks/text.ts +362 -0
- package/hooks/scan/checks/types.ts +89 -0
- package/hooks/scan/checks/validator.ts +97 -0
- package/hooks/scan/hash.ts +38 -0
- package/hooks/scan/host.ts +51 -0
- package/hooks/scan/inventory.ts +240 -0
- package/hooks/scan/report.ts +63 -0
- package/hooks/scan/safe-text.ts +28 -0
- package/hooks/scan/scan.ts +274 -0
- package/hooks/scan/verdict.ts +58 -0
- package/package.json +46 -4
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ai-install-guard",
|
|
3
|
+
"description": "A pre-install security gate for Claude Code.",
|
|
4
|
+
"owner": {
|
|
5
|
+
"name": "Boaz Ziniman",
|
|
6
|
+
"email": "ziniman@gmail.com",
|
|
7
|
+
"url": "https://github.com/ziniman"
|
|
8
|
+
},
|
|
9
|
+
"plugins": [
|
|
10
|
+
{
|
|
11
|
+
"name": "ai-install-guard",
|
|
12
|
+
"source": "./",
|
|
13
|
+
"version": "0.1.0",
|
|
14
|
+
"description": "Scans plugins, mods, skills and MCP servers without running them, shows a PASS / WARN / FAIL verdict, and installs nothing until you approve.",
|
|
15
|
+
"category": "security",
|
|
16
|
+
"keywords": [
|
|
17
|
+
"security",
|
|
18
|
+
"supply-chain",
|
|
19
|
+
"static-analysis"
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ai-install-guard",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A pre-install security gate for Claude Code: scans plugins, mods, skills and MCP servers without running them, and installs nothing until you approve.",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Boaz Ziniman",
|
|
7
|
+
"email": "ziniman@gmail.com",
|
|
8
|
+
"url": "https://github.com/ziniman"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/ziniman/ai-install-guard",
|
|
11
|
+
"repository": "https://github.com/ziniman/ai-install-guard",
|
|
12
|
+
"license": "Apache-2.0",
|
|
13
|
+
"types": "./types/index.d.ts",
|
|
14
|
+
"keywords": [
|
|
15
|
+
"security",
|
|
16
|
+
"supply-chain",
|
|
17
|
+
"static-analysis",
|
|
18
|
+
"plugins",
|
|
19
|
+
"skills",
|
|
20
|
+
"mcp",
|
|
21
|
+
"mods"
|
|
22
|
+
]
|
|
23
|
+
}
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to ai-install-guard. Ordered newest to oldest.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## v0.1.0 · 2026-10-22
|
|
8
|
+
|
|
9
|
+
**`pane`** - `/guard scan` opens a verdict pane: the recommendation and its reasons in a coloured banner, the counts, and every check grouped with failures first, each row opening to its evidence and advice. Approve and Reject record the decision against the exact tree hash; on Do not install or Could not verify the button reads Approve anyway and asks a second time. Details opens every row and Copy report copies the full text. Progress shows in the pane and the status line, and a toast says when the verdict is ready
|
|
10
|
+
|
|
11
|
+
**`/guard report`, `/guard list`, `/guard forget`** - Reopen the last report, list your decisions, and forget the ones about a name
|
|
12
|
+
|
|
13
|
+
**`checks`** - Deterministic checks for structure and manifest (Claude Code's own validator, binaries and disguised files, symbolic links that leave the folder, data after an image's end, bundled permission settings), mod capabilities (every hooked event and `$` call in plain language, high-risk calls, capability mismatch), classic shell hooks and their scripts, skills, commands and agents (prompt injection, credential instructions, broad `allowed-tools`, remote instructions, look-alike names, text aimed at the scanner), code patterns (hidden Unicode with tag characters decoded, execution, obfuscation, credentials with network code, persistence, install scripts, registry redirects, network addresses) and committed secrets, each with a fixture and a test
|
|
14
|
+
|
|
15
|
+
**`/guard scan`** - Prints a verdict (Safe to install, Install with caution, Do not install, Could not verify), its top reasons and one line per check; `--details` adds every finding and its advice. Quoted text is escaped and marked as untrusted
|
|
16
|
+
|
|
17
|
+
**`/guard scan`** - Lists every file of a local folder, reads and hashes each one, records symbolic links with where they land without following them, and prints a SHA-256 tree hash that pins the exact content
|
|
18
|
+
|
|
19
|
+
**`release`** - Versioning, npm publishing and GitHub releases run from CI when a version bump is merged, as in ai-instruct
|
|
20
|
+
|
|
21
|
+
---
|
package/LICENSE
ADDED
|
@@ -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
|
|
95
|
+
Derivative 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 [yyyy] [name of copyright owner]
|
|
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.
|
package/README.md
CHANGED
|
@@ -1,3 +1,111 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# AI Install Guard
|
|
4
|
+
|
|
5
|
+
**A security gate for Claude Code. Nothing new gets installed until you have seen what it can do.**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/ai-install-guard)
|
|
8
|
+
[](https://www.npmjs.com/package/ai-install-guard)
|
|
9
|
+
[](https://github.com/ziniman/ai-install-guard/stargazers)
|
|
10
|
+
[](https://github.com/ziniman/ai-install-guard/blob/main/LICENSE)
|
|
11
|
+
[](https://github.com/ziniman/ai-install-guard/commits/main)
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
/plugin install ai-install-guard --marketplace ziniman/ai-install-guard
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
> **Status: early development.** Today `/guard scan <path>` runs the deterministic checks on a local folder and shows the verdict in a pane, where you approve or reject that exact version. Remote fetching and the install gates below are being built in stages; see [Roadmap](#roadmap).
|
|
20
|
+
|
|
21
|
+
Everything you add to Claude Code runs with your permissions. A plugin can ship shell hooks that run every session, an MCP server can download and launch a package, a mod can read files or auto-approve tools, and a skill can carry hidden instructions the model will follow. The install prompt asks you to trust the author, and an update can change the files after you looked.
|
|
22
|
+
|
|
23
|
+
AI Install Guard is a Claude Code mod that stops every new plugin, mod, skill, MCP server or marketplace, and every update to one, scans it without running any of its code, and installs nothing until you approve it.
|
|
24
|
+
|
|
25
|
+
## Who it is for
|
|
26
|
+
|
|
27
|
+
You, before you add something to Claude Code. It runs inside your own session, needs no account, server or agent, and is open source, so you can read every check it makes. This release makes no network calls; later stages fetch the candidate itself, and any outside lookup stays optional and off by default. Today you run `/guard scan` on a folder yourself before installing it; the gates that hold an install automatically come in later stages (see [Roadmap](#roadmap)).
|
|
28
|
+
|
|
29
|
+
Company security platforms such as AIR, Pluto and Neo watch a whole fleet of agents and enforce policy across it. The guard does not replace them: it is an open, local check for one developer's installs, and it works the same whether or not your company runs one.
|
|
30
|
+
|
|
31
|
+
## How it works
|
|
32
|
+
|
|
33
|
+
1. **Fetch without running.** The candidate is fetched at an exact commit into a folder the guard owns. Nothing is installed, built or run.
|
|
34
|
+
2. **Check every file.** Deterministic checks read the hooks, MCP servers, mod code, skills, scripts, images and manifest.
|
|
35
|
+
3. **Show a verdict.** A pane shows **Safe to install**, **Install with caution**, **Do not install** or **Could not verify**, a PASS / WARN / FAIL list with file and line evidence, and two buttons: **Install** and **Reject**.
|
|
36
|
+
4. **Install only what was scanned.** Install is pinned to the scanned commit and content hash. If the source changed since the scan, it is scanned again first.
|
|
37
|
+
|
|
38
|
+
Approvals are remembered by commit and content hash, so the same version is never scanned twice, and an update is reviewed as a diff: anything new since the version you approved is listed and flagged. An optional model review can add warnings but can never clear a failure, so a README that says "this plugin is safe" changes nothing.
|
|
39
|
+
|
|
40
|
+
## Where it steps in
|
|
41
|
+
|
|
42
|
+
| Layer | Catches | What happens |
|
|
43
|
+
|-------|---------|--------------|
|
|
44
|
+
| Slash command | `/plugin install`, `/plugin update`, `/plugin marketplace add` | Held until you press Install |
|
|
45
|
+
| Claude's own tool calls | `claude plugin install`, `claude mcp add`, copies into skills folders, edits to `.mcp.json` or settings, `npx -y`, `curl \| sh` | Denied, with a note to the model that a scan is pending |
|
|
46
|
+
| Mod loading | Any mod about to load, however it got there | Refused if its files do not match what you approved |
|
|
47
|
+
| First use of a skill | Skills and commands, including ones copied in by hand | Blocked until scanned |
|
|
48
|
+
| Session start | Anything installed while the guard was not running | Scanned, with Keep or Uninstall |
|
|
49
|
+
|
|
50
|
+
## What it checks
|
|
51
|
+
|
|
52
|
+
| Threat | What gets flagged |
|
|
53
|
+
|--------|-------------------|
|
|
54
|
+
| Code execution | Shell hooks, MCP servers that launch binaries or unpinned `npx` / `uvx` packages, mods that run processes |
|
|
55
|
+
| Data theft | Reads of `~/.ssh`, `~/.aws`, `.env`, keychains or secret env vars, combined with network calls |
|
|
56
|
+
| Prompt injection | Hidden instructions in skills, commands, agents and tool descriptions, including invisible Unicode |
|
|
57
|
+
| Permission escalation | Mods that auto-approve tools, writes to Claude settings or permissions, skills granting broad `Bash` |
|
|
58
|
+
| Persistence | Writes to shell rc files, crontab, launchd, systemd, git hooks |
|
|
59
|
+
| Supply chain | Marketplaces on a moving branch, brand-new repos, look-alike names, committed secrets, binaries, data hidden after the end of images |
|
|
60
|
+
| Sneaky updates | An update that adds capabilities, hooks, domains or servers without saying so |
|
|
61
|
+
|
|
62
|
+
## Commands
|
|
63
|
+
|
|
64
|
+
| Command | What it does |
|
|
65
|
+
|---------|--------------|
|
|
66
|
+
| `/guard scan <path>` | Scan a local folder without installing it and open the verdict pane |
|
|
67
|
+
| `/guard scan --details <path>` | The same, and print the full report with every finding and its advice |
|
|
68
|
+
| `/guard report` | Reopen the last report |
|
|
69
|
+
| `/guard list` | Your approved and rejected versions, newest first |
|
|
70
|
+
| `/guard forget <name>` | Forget decisions about a name, so it is judged again |
|
|
71
|
+
|
|
72
|
+
In the pane, **Approve** (`i`) and **Reject** (`r`) record your decision for that exact content (its tree hash). When the verdict is Do not install or Could not verify, the button reads **Approve anyway** and asks a second time. **Details** (`d`) opens every row, and **Copy report** (`c`) copies the full report as text. Where no pane can show (a headless `claude -p` run), `/guard scan` prints the report instead.
|
|
73
|
+
|
|
74
|
+
## What the guard itself can do
|
|
75
|
+
|
|
76
|
+
A security tool should be held to its own rules, so here is everything this mod uses, as `claude plugin validate .` lists it:
|
|
77
|
+
|
|
78
|
+
| Capability | Why |
|
|
79
|
+
|------------|-----|
|
|
80
|
+
| `process.run` | Runs `claude plugin validate` on a candidate (it reads source and runs none of it), `readlink` to see where a symbolic link points without following it, and `printenv HOME` to expand `~`. Later stages add `git` to fetch candidates into the guard's own temporary folder. It never runs anything from a candidate. |
|
|
81
|
+
| `fs.read`, `fs.list`, `fs.stat` | Reads the candidate's files to scan them. It never writes files. |
|
|
82
|
+
| `command.register` | Adds the `/guard` command. |
|
|
83
|
+
| `store`, `state` | Remembers your decisions and the last report, and holds what the pane shows. |
|
|
84
|
+
| `ui` | The verdict pane, its status line and toasts, and copying the report. |
|
|
85
|
+
|
|
86
|
+
Later stages add `http.fetch` (public repository metadata) and, optionally, `model.complete` (a review that can only add warnings).
|
|
87
|
+
|
|
88
|
+
## What it is not
|
|
89
|
+
|
|
90
|
+
- **Not a proof of safety.** Static analysis raises the bar and makes every capability visible; a determined attacker can still evade it.
|
|
91
|
+
- **Install it first.** It judges only mods that load after it. For a company, the strongest setup is deploying it through managed settings so it loads first.
|
|
92
|
+
- **No per-plugin block for classic shell hooks.** Claude Code runs them outside mods, so the guard scans before install and uninstalls on reject.
|
|
93
|
+
|
|
94
|
+
## Roadmap
|
|
95
|
+
|
|
96
|
+
1. [x] Skeleton mod: `/guard scan <path>` lists and hashes a local folder
|
|
97
|
+
2. [x] Checks for structure, mod capabilities, classic hooks, skills, code patterns and committed secrets
|
|
98
|
+
3. [x] The verdict pane with Install and Reject
|
|
99
|
+
4. [ ] Remote fetch pinned to a commit, provenance checks (with an optional reputation lookup against outside catalogs and vulnerability databases), MCP server checks
|
|
100
|
+
5. [ ] Gates on `/plugin` and on Claude's own install commands, with approvals
|
|
101
|
+
6. [ ] Module load gate with hash match, skill gate, session-start reconciliation
|
|
102
|
+
7. [ ] Update diffs and the optional model review
|
|
103
|
+
8. [ ] Full documentation
|
|
104
|
+
|
|
105
|
+
## Contributing
|
|
106
|
+
|
|
107
|
+
Issues and pull requests are welcome. See [.claude/CLAUDE.md](./.claude/CLAUDE.md) for how the repo is laid out, how to run the checks, and how releases work.
|
|
108
|
+
|
|
109
|
+
## License
|
|
110
|
+
|
|
111
|
+
Apache 2.0 - see [LICENSE](./LICENSE). Free to use, modify, and redistribute.
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { EngineInterface } from 'claude-code'
|
|
2
|
+
|
|
3
|
+
import type { GuardVerdict, GuardView } from '../../types'
|
|
4
|
+
import { safeLine } from '../scan/safe-text'
|
|
5
|
+
|
|
6
|
+
/** One decision, remembered across sessions so the same tree is never judged twice. */
|
|
7
|
+
export type Decision = {
|
|
8
|
+
target: string
|
|
9
|
+
root?: string
|
|
10
|
+
treeHash: string
|
|
11
|
+
verdict: string
|
|
12
|
+
/** The verdict the decision was made on; an approval holds up to this one. */
|
|
13
|
+
verdictKind: GuardVerdict['kind']
|
|
14
|
+
decision: 'approved' | 'rejected'
|
|
15
|
+
/** Approved although the verdict was Do not install or Could not verify. */
|
|
16
|
+
overridden: boolean
|
|
17
|
+
decidedAt: number
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const DECISIONS = 'decisions'
|
|
21
|
+
/** Room for the report text, well inside the store's 4 MiB in all. */
|
|
22
|
+
export const MAX_REPORT_CHARS = 1_000_000
|
|
23
|
+
const LAST_VIEW = 'last-view'
|
|
24
|
+
/** The store is capped at 4 MiB in all: keep the newest decisions only. */
|
|
25
|
+
const MAX_DECISIONS = 500
|
|
26
|
+
/** How serious each verdict is, to tell whether an approval still covers it. */
|
|
27
|
+
const SEVERITY: Record<GuardVerdict['kind'], number> = { safe: 0, caution: 1, unverified: 2, reject: 3 }
|
|
28
|
+
|
|
29
|
+
export async function loadDecisions($: EngineInterface): Promise<Decision[]> {
|
|
30
|
+
const stored = await $.store.get(DECISIONS)
|
|
31
|
+
return Array.isArray(stored) ? (stored as Decision[]) : []
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export async function recordDecision($: EngineInterface, decision: Decision): Promise<void> {
|
|
35
|
+
const others = (await loadDecisions($)).filter(item => item.treeHash !== decision.treeHash)
|
|
36
|
+
await $.store.set(DECISIONS, [decision, ...others].slice(0, MAX_DECISIONS))
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Removes the decisions about `name`: its target as typed, its folder, or the
|
|
41
|
+
* last part of either. A name inside another (tool in my-tool-2) does not count.
|
|
42
|
+
*/
|
|
43
|
+
export async function forgetDecisions($: EngineInterface, name: string): Promise<Decision[]> {
|
|
44
|
+
const all = await loadDecisions($)
|
|
45
|
+
const last = (path: string): string => path.replace(/\/+$/, '').split('/').pop() ?? path
|
|
46
|
+
// Stored paths are display-safe; compare the name both as typed and made
|
|
47
|
+
// safe, without trailing slashes.
|
|
48
|
+
const wanted = new Set([name, safeLine(name)].map(value => value.replace(/\/+$/, '')))
|
|
49
|
+
const matches = (item: Decision): boolean =>
|
|
50
|
+
[item.target, item.root ?? '', last(item.target), last(item.root ?? '')].some(candidate => candidate !== '' && wanted.has(candidate.replace(/\/+$/, '')))
|
|
51
|
+
const kept = all.filter(item => !matches(item))
|
|
52
|
+
await $.store.set(DECISIONS, kept)
|
|
53
|
+
// The last report must not keep claiming a decision that is gone.
|
|
54
|
+
const forgotten = all.filter(matches)
|
|
55
|
+
const view = await loadLastView($)
|
|
56
|
+
if (view?.decision !== undefined && forgotten.some(item => item.treeHash === view.treeHash)) {
|
|
57
|
+
await saveLastView($, { ...view, decision: undefined, confirming: false })
|
|
58
|
+
}
|
|
59
|
+
return forgotten
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The decision that still holds for this tree at this verdict. A rejection
|
|
64
|
+
* always holds. An approval holds only while the verdict is no worse than the
|
|
65
|
+
* one it was given on: the same files can judge worse in another place (a
|
|
66
|
+
* copy whose absolute link now leaves the folder), and that needs a new look.
|
|
67
|
+
*/
|
|
68
|
+
export async function decisionFor($: EngineInterface, treeHash: string, kind: GuardVerdict['kind']): Promise<Decision | undefined> {
|
|
69
|
+
const found = (await loadDecisions($)).find(item => item.treeHash === treeHash)
|
|
70
|
+
if (found === undefined || found.decision === 'rejected') return found
|
|
71
|
+
const approvedUpTo = SEVERITY[found.verdictKind] as number | undefined
|
|
72
|
+
return approvedUpTo !== undefined && SEVERITY[kind] <= approvedUpTo ? found : undefined
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Saves the view /guard report reopens. When it cannot be saved, the old one
|
|
77
|
+
* is removed, so a reopened report never shows an older verdict as current.
|
|
78
|
+
*/
|
|
79
|
+
export async function saveLastView($: EngineInterface, view: GuardView): Promise<void> {
|
|
80
|
+
try {
|
|
81
|
+
await $.store.set(LAST_VIEW, view)
|
|
82
|
+
} catch (error) {
|
|
83
|
+
await $.store.delete(LAST_VIEW).catch(() => undefined)
|
|
84
|
+
throw error
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export async function loadLastView($: EngineInterface): Promise<GuardView | undefined> {
|
|
89
|
+
const stored = await $.store.get(LAST_VIEW)
|
|
90
|
+
return stored !== null && typeof stored === 'object' ? (stored as GuardView) : undefined
|
|
91
|
+
}
|