@goplus/agentguard 1.0.14 → 1.1.3

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 (91) hide show
  1. package/README.md +33 -2
  2. package/dist/cli.d.ts +3 -0
  3. package/dist/cli.d.ts.map +1 -0
  4. package/dist/cli.js +172 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/cloud/client.d.ts +19 -0
  7. package/dist/cloud/client.d.ts.map +1 -0
  8. package/dist/cloud/client.js +86 -0
  9. package/dist/cloud/client.js.map +1 -0
  10. package/dist/config.d.ts +31 -0
  11. package/dist/config.d.ts.map +1 -0
  12. package/dist/config.js +131 -0
  13. package/dist/config.js.map +1 -0
  14. package/dist/index.d.ts +7 -0
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +25 -1
  17. package/dist/index.js.map +1 -1
  18. package/dist/installers.d.ts +10 -0
  19. package/dist/installers.d.ts.map +1 -0
  20. package/dist/installers.js +137 -0
  21. package/dist/installers.js.map +1 -0
  22. package/dist/mcp-server.js +3 -2
  23. package/dist/mcp-server.js.map +1 -1
  24. package/dist/postinstall.d.ts +3 -0
  25. package/dist/postinstall.d.ts.map +1 -0
  26. package/dist/postinstall.js +13 -0
  27. package/dist/postinstall.js.map +1 -0
  28. package/dist/runtime/audit.d.ts +10 -0
  29. package/dist/runtime/audit.d.ts.map +1 -0
  30. package/dist/runtime/audit.js +94 -0
  31. package/dist/runtime/audit.js.map +1 -0
  32. package/dist/runtime/evaluator.d.ts +3 -0
  33. package/dist/runtime/evaluator.d.ts.map +1 -0
  34. package/dist/runtime/evaluator.js +197 -0
  35. package/dist/runtime/evaluator.js.map +1 -0
  36. package/dist/runtime/policy.d.ts +12 -0
  37. package/dist/runtime/policy.d.ts.map +1 -0
  38. package/dist/runtime/policy.js +81 -0
  39. package/dist/runtime/policy.js.map +1 -0
  40. package/dist/runtime/protect.d.ts +22 -0
  41. package/dist/runtime/protect.d.ts.map +1 -0
  42. package/dist/runtime/protect.js +172 -0
  43. package/dist/runtime/protect.js.map +1 -0
  44. package/dist/runtime/redaction.d.ts +6 -0
  45. package/dist/runtime/redaction.d.ts.map +1 -0
  46. package/dist/runtime/redaction.js +103 -0
  47. package/dist/runtime/redaction.js.map +1 -0
  48. package/dist/runtime/types.d.ts +62 -0
  49. package/dist/runtime/types.d.ts.map +1 -0
  50. package/dist/runtime/types.js +3 -0
  51. package/dist/runtime/types.js.map +1 -0
  52. package/dist/scanner/rules/trojan.js +1 -1
  53. package/dist/scanner/rules/trojan.js.map +1 -1
  54. package/dist/tests/cloud-live.test.d.ts +2 -0
  55. package/dist/tests/cloud-live.test.d.ts.map +1 -0
  56. package/dist/tests/cloud-live.test.js +68 -0
  57. package/dist/tests/cloud-live.test.js.map +1 -0
  58. package/dist/tests/installer.test.d.ts +2 -0
  59. package/dist/tests/installer.test.d.ts.map +1 -0
  60. package/dist/tests/installer.test.js +32 -0
  61. package/dist/tests/installer.test.js.map +1 -0
  62. package/dist/tests/runtime-cloud.test.d.ts +2 -0
  63. package/dist/tests/runtime-cloud.test.d.ts.map +1 -0
  64. package/dist/tests/runtime-cloud.test.js +202 -0
  65. package/dist/tests/runtime-cloud.test.js.map +1 -0
  66. package/dist/version.d.ts +2 -0
  67. package/dist/version.d.ts.map +1 -0
  68. package/dist/version.js +7 -0
  69. package/dist/version.js.map +1 -0
  70. package/docs/SECURITY-POLICY.md +558 -0
  71. package/docs/architecture.md +54 -0
  72. package/docs/claude-code.md +41 -0
  73. package/docs/cloud-connect.md +73 -0
  74. package/docs/cloud-native-api.md +526 -0
  75. package/docs/codex.md +38 -0
  76. package/docs/goplus-api.md +38 -0
  77. package/docs/mcp-server.md +39 -0
  78. package/docs/openclaw.md +41 -0
  79. package/docs/privacy-boundary.md +37 -0
  80. package/docs/sdk.md +83 -0
  81. package/docs/trust-cli.md +58 -0
  82. package/examples/openclaw-docker/Dockerfile +10 -0
  83. package/examples/openclaw-docker/README.md +16 -0
  84. package/examples/openclaw-docker/docker-compose.yml +8 -0
  85. package/examples/openclaw-docker/plugin.ts +8 -0
  86. package/package.json +7 -2
  87. package/skills/agentguard/SKILL.md +157 -61
  88. package/skills/agentguard/{scripts/package.json → package.json} +2 -1
  89. package/skills/agentguard/patrol-checks.md +12 -2
  90. package/skills/agentguard/scan-rules.md +1 -1
  91. package/skills/agentguard/scripts/checkup-report.js +71 -30
@@ -0,0 +1,558 @@
1
+ # GoPlus AgentGuard Security Policy
2
+
3
+ Unified security policy reference for all platforms (Claude Code, OpenClaw, and future integrations).
4
+
5
+ ---
6
+
7
+ ## 1. Overview
8
+
9
+ ### Design Principles
10
+
11
+ 1. **Defense in Depth**: Multiple layers of protection (static scan, runtime evaluation, trust registry)
12
+ 2. **Fail-Secure**: Unknown or ambiguous actions default to denial/confirmation
13
+ 3. **Least Privilege**: Skills receive minimal capabilities by default
14
+ 4. **User Sovereignty**: Users always retain final approval authority
15
+
16
+ ### Three-Module Architecture
17
+
18
+ | Module | Purpose | When Invoked |
19
+ |--------|---------|--------------|
20
+ | **Static Scanner** | Detect malicious patterns in code/prompts | Before execution (`/agentguard scan`) |
21
+ | **Action Evaluator** | Runtime policy decisions on agent actions | On tool calls (hooks) |
22
+ | **Trust Registry** | Skill identity and capability attestation | Skill invocation & lookup |
23
+
24
+ ---
25
+
26
+ ## 2. Protection Levels
27
+
28
+ Configure via `/agentguard config <level>`:
29
+
30
+ | Level | Description | DENY Behavior | CONFIRM Behavior |
31
+ |-------|-------------|---------------|------------------|
32
+ | **strict** | Maximum security. All risk operations blocked. | Block | Block (treated as deny) |
33
+ | **balanced** (default) | Critical threats blocked, high-risk prompts user. | Block | Prompt user |
34
+ | **permissive** | Only critical threats blocked, others prompt. | Block if critical; else prompt | Prompt if high/critical |
35
+
36
+ ### Decision Matrix
37
+
38
+ | Risk Level | strict | balanced | permissive |
39
+ |------------|--------|----------|------------|
40
+ | critical + DENY | Block | Block | Block |
41
+ | critical + CONFIRM | Block | Prompt | Prompt |
42
+ | high + DENY | Block | Block | Prompt |
43
+ | high + CONFIRM | Block | Prompt | Prompt |
44
+ | medium + DENY | Block | Block | Prompt |
45
+ | medium + CONFIRM | Block | Prompt | Allow |
46
+ | low | Allow | Allow | Allow |
47
+
48
+ ---
49
+
50
+ ## 3. Decision Framework
51
+
52
+ ### Decision Types
53
+
54
+ | Decision | Meaning | Typical Outcome |
55
+ |----------|---------|-----------------|
56
+ | **ALLOW** | Safe to proceed | Action executes |
57
+ | **DENY** | Must not proceed | Action blocked (error to agent) |
58
+ | **CONFIRM** | Requires user approval | Prompt user for confirmation |
59
+
60
+ ### Risk Levels
61
+
62
+ | Level | Priority Range | Description |
63
+ |-------|----------------|-------------|
64
+ | **critical** | 90-100 | Immediate block — private keys, destructive commands |
65
+ | **high** | 70-89 | Strong risk — API secrets, untrusted network exfil |
66
+ | **medium** | 50-69 | Moderate risk — system commands, network activity |
67
+ | **low** | 0-49 | Minimal risk — safe/read-only operations |
68
+
69
+ ---
70
+
71
+ ## 4. Runtime Action Rules (ActionScanner)
72
+
73
+ ### 4.1 Command Execution (`exec_command`)
74
+
75
+ #### Safe Commands (Always ALLOW)
76
+
77
+ Commands matching the safe list are allowed without restriction, **unless** they contain shell metacharacters or access sensitive paths.
78
+
79
+ | Category | Commands |
80
+ |----------|----------|
81
+ | **Read-only** | `ls`, `echo`, `pwd`, `whoami`, `date`, `hostname`, `uname`, `tree`, `du`, `df`, `sort`, `uniq`, `diff`, `cd` |
82
+ | **File inspection** | `cat`, `head`, `tail`, `wc`, `grep`, `find`, `which`, `type` |
83
+ | **File operations** | `mkdir`, `cp`, `mv`, `touch` |
84
+ | **Git** | `git status`, `git log`, `git diff`, `git branch`, `git show`, `git remote`, `git clone`, `git checkout`, `git pull`, `git fetch`, `git merge`, `git add`, `git commit`, `git push` |
85
+ | **Package managers** | `npm install`, `npm run`, `npm test`, `npm ci`, `npm start`, `npx`, `yarn`, `pnpm`, `pip install`, `pip3 install` |
86
+ | **Version checks** | `node -v`, `npm -v`, `python --version`, `tsc --version`, `go version`, `rustc --version`, `java -version` |
87
+ | **Build & run** | `tsc`, `go build`, `go run`, `cargo build`, `cargo run`, `cargo test`, `make` |
88
+
89
+ **Shell metacharacters that disqualify safe commands**: `;`, `|`, `&`, `` ` ``, `$`, `(`, `)`, `{`, `}`
90
+
91
+ #### Dangerous Commands (Always DENY — Critical)
92
+
93
+ | Pattern | Description |
94
+ |---------|-------------|
95
+ | `rm -rf` / `rm -fr` | Recursive delete |
96
+ | `mkfs` | Format filesystem |
97
+ | `dd if=` | Raw disk write |
98
+ | `:(){:\|:&};:` | Fork bomb (with space variants) |
99
+ | `chmod 777` / `chmod -R 777` | World-writable permissions |
100
+ | `> /dev/sda` | Disk overwrite |
101
+ | `mv /* ` | Move root contents |
102
+ | `curl\|sh` / `wget\|bash` | Download and execute |
103
+
104
+ #### Sensitive Data Access (High Risk — CONFIRM)
105
+
106
+ | Pattern | Target |
107
+ |---------|--------|
108
+ | `cat /etc/passwd` | User database |
109
+ | `cat /etc/shadow` | Password hashes |
110
+ | `cat ~/.ssh` | SSH keys |
111
+ | `cat ~/.aws` | AWS credentials |
112
+ | `cat ~/.kube` | Kubernetes config |
113
+ | `cat ~/.npmrc` | npm auth tokens |
114
+ | `cat ~/.netrc` | Network credentials |
115
+ | `printenv` / `env` / `set` | All environment variables |
116
+
117
+ #### System Commands (Medium Risk — Audit)
118
+
119
+ `sudo`, `su`, `chown`, `chmod`, `chgrp`, `useradd`, `userdel`, `groupadd`, `passwd`, `visudo`, `systemctl`, `service`, `init`, `shutdown`, `reboot`, `halt`
120
+
121
+ #### Network Commands (Medium Risk — Audit)
122
+
123
+ `curl`, `wget`, `nc`/`netcat`/`ncat`, `ssh`, `scp`, `rsync`, `ftp`, `sftp`
124
+
125
+ #### Shell Injection Patterns (Medium Risk)
126
+
127
+ | Pattern | Description |
128
+ |---------|-------------|
129
+ | `; command` | Command separator |
130
+ | `\| command` | Pipe |
131
+ | `` `command` `` | Backtick execution |
132
+ | `$(command)` | Command substitution |
133
+ | `&& command` | Conditional chain |
134
+ | `\|\| command` | Or chain |
135
+
136
+ ---
137
+
138
+ ### 4.2 Network Requests (`network_request`)
139
+
140
+ #### Webhook / Exfiltration Domains (DENY unless allowlisted)
141
+
142
+ | Domain | Service |
143
+ |--------|---------|
144
+ | `discord.com` / `discordapp.com` | Discord webhooks |
145
+ | `api.telegram.org` | Telegram bot API |
146
+ | `hooks.slack.com` | Slack webhooks |
147
+ | `webhook.site` | Webhook testing |
148
+ | `requestbin.com` | Request inspection |
149
+ | `pipedream.com` | Workflow automation |
150
+ | `ngrok.io` / `ngrok-free.app` | Tunneling |
151
+ | `beeceptor.com` | API mocking |
152
+ | `mockbin.org` | HTTP mocking |
153
+
154
+ #### High-Risk TLDs (Medium → High with POST/PUT)
155
+
156
+ `.xyz`, `.top`, `.tk`, `.ml`, `.ga`, `.cf`, `.gq`, `.work`, `.click`, `.link`
157
+
158
+ #### Request Body Secret Scanning
159
+
160
+ | Secret Type | Priority | Risk Level | Decision |
161
+ |-------------|----------|------------|----------|
162
+ | Private Key (`0x` + 64 hex) | 100 | critical | DENY |
163
+ | Mnemonic (12-24 BIP-39 words) | 100 | critical | DENY |
164
+ | SSH Private Key (`-----BEGIN.*PRIVATE KEY`) | 90 | critical | DENY |
165
+ | AWS Secret Key (40-char near AWS context) | 80 | high | CONFIRM |
166
+ | AWS Access Key (`AKIA[0-9A-Z]{16}`) | 70 | high | CONFIRM |
167
+ | GitHub Token (`gh[pousr]_...`) | 70 | high | CONFIRM |
168
+ | Bearer/JWT Token (`ey...`) | 60 | medium | CONFIRM |
169
+ | API Secret (generic patterns) | 50 | medium | CONFIRM |
170
+ | DB Connection String | 50 | medium | CONFIRM |
171
+ | Password in Config | 40 | low | CONFIRM |
172
+
173
+ #### Network Decision Logic
174
+
175
+ 1. Invalid URL → **DENY** (high)
176
+ 2. Domain in webhook list & not allowlisted → **DENY** (high)
177
+ 3. Body contains private key / mnemonic / SSH key → **DENY** (critical)
178
+ 4. Body contains other secrets → risk based on priority
179
+ 5. High-risk TLD & not allowlisted → **CONFIRM** (medium)
180
+ 6. POST/PUT to untrusted domain → escalate medium → high
181
+ 7. Domain in allowlist → **ALLOW** (low)
182
+
183
+ ---
184
+
185
+ ### 4.3 File Operations (`read_file` / `write_file`)
186
+
187
+ #### Sensitive Paths (DENY or CONFIRM based on level)
188
+
189
+ | Path Pattern | Description |
190
+ |--------------|-------------|
191
+ | `.env`, `.env.local`, `.env.production` | Environment secrets |
192
+ | `.ssh/`, `id_rsa`, `id_ed25519` | SSH keys |
193
+ | `.aws/credentials`, `.aws/config` | AWS credentials |
194
+ | `.npmrc`, `.netrc` | Package/network auth |
195
+ | `credentials.json`, `serviceAccountKey.json` | Service accounts |
196
+ | `.kube/config` | Kubernetes config |
197
+
198
+ ---
199
+
200
+ ### 4.4 Secret Leak Detection Priority
201
+
202
+ | Secret Type | Priority | Risk Level |
203
+ |-------------|----------|------------|
204
+ | `PRIVATE_KEY` | 100 | critical |
205
+ | `MNEMONIC` | 100 | critical |
206
+ | `SSH_KEY` | 90 | critical |
207
+ | `AWS_SECRET` | 80 | high |
208
+ | `AWS_KEY` | 70 | high |
209
+ | `GITHUB_TOKEN` | 70 | high |
210
+ | `BEARER_TOKEN` | 60 | medium |
211
+ | `API_SECRET` | 50 | medium |
212
+ | `DB_CONNECTION` | 50 | medium |
213
+ | `PASSWORD_CONFIG` | 40 | low |
214
+
215
+ ---
216
+
217
+ ### 4.5 Web3 Operations (`web3_tx` / `web3_sign`)
218
+
219
+ #### GoPlus Integration
220
+
221
+ | Check | Description | Trigger → Action |
222
+ |-------|-------------|------------------|
223
+ | **Phishing Site** | Origin URL on phishing list | `PHISHING_ORIGIN` → DENY (critical) |
224
+ | **Malicious Address** | Target address blacklisted | `MALICIOUS_ADDRESS` → DENY (critical) |
225
+ | **Honeypot Related** | Address associated with honeypot | `HONEYPOT_RELATED` → flag (high) |
226
+ | **Unlimited Approval** | Token approval for max uint256 | `UNLIMITED_APPROVAL` → CONFIRM (high) |
227
+ | **Simulation Failed** | Transaction simulation error | `SIMULATION_FAILED` → flag (medium) |
228
+
229
+ #### Environment Variables
230
+
231
+ ```bash
232
+ GOPLUS_API_KEY=your_key # Required for simulation
233
+ GOPLUS_API_SECRET=your_secret # Required for simulation
234
+ ```
235
+
236
+ #### Degradation Strategy
237
+
238
+ When GoPlus is unavailable:
239
+ 1. `SIMULATION_UNAVAILABLE` tag is set
240
+ 2. Decision falls back to policy-based rules only
241
+ 3. Capability model and secret scanning still apply
242
+
243
+ ---
244
+
245
+ ## 5. Static Scan Rules (24 Rules)
246
+
247
+ ### Critical Severity
248
+
249
+ | Rule | ID | Target Files |
250
+ |------|-----|--------------|
251
+ | Auto-Update / Remote Code Execution | `AUTO_UPDATE` | `.js`, `.ts`, `.py`, `.sh`, `.md` |
252
+ | Remote Code Loader | `REMOTE_LOADER` | `.js`, `.ts`, `.mjs`, `.py`, `.md` |
253
+ | Read SSH Keys | `READ_SSH_KEYS` | All |
254
+ | Read Keychain/Browser Credentials | `READ_KEYCHAIN` | All |
255
+ | Private Key Pattern | `PRIVATE_KEY_PATTERN` | All |
256
+ | Mnemonic Pattern | `MNEMONIC_PATTERN` | All |
257
+ | Wallet Draining | `WALLET_DRAINING` | `.js`, `.ts`, `.sol` |
258
+ | Prompt Injection | `PROMPT_INJECTION` | All |
259
+ | Webhook Exfiltration URL | `WEBHOOK_EXFIL` | All |
260
+ | Trojan Distribution | `TROJAN_DISTRIBUTION` | `.md` |
261
+
262
+ ### High Severity
263
+
264
+ | Rule | ID | Target Files |
265
+ |------|-----|--------------|
266
+ | Shell Execution | `SHELL_EXEC` | `.js`, `.ts`, `.mjs`, `.cjs`, `.py`, `.md` |
267
+ | Unlimited Approval | `UNLIMITED_APPROVAL` | `.js`, `.ts`, `.sol` |
268
+ | Dangerous Selfdestruct | `DANGEROUS_SELFDESTRUCT` | `.sol` |
269
+ | Reentrancy Pattern | `REENTRANCY_PATTERN` | `.sol` |
270
+ | Signature Replay | `SIGNATURE_REPLAY` | `.sol` |
271
+ | Obfuscation | `OBFUSCATION` | `.js`, `.ts`, `.mjs`, `.py`, `.md` |
272
+ | Unrestricted Network Exfil | `NET_EXFIL_UNRESTRICTED` | `.js`, `.ts`, `.mjs`, `.py`, `.md` |
273
+ | Suspicious Paste URL | `SUSPICIOUS_PASTE_URL` | All |
274
+
275
+ ### Medium Severity
276
+
277
+ | Rule | ID | Target Files |
278
+ |------|-----|--------------|
279
+ | Read Environment Secrets | `READ_ENV_SECRETS` | `.js`, `.ts`, `.mjs`, `.py` |
280
+ | Hidden Transfer | `HIDDEN_TRANSFER` | `.sol` |
281
+ | Proxy Upgrade | `PROXY_UPGRADE` | `.sol`, `.js`, `.ts` |
282
+ | Flash Loan Risk | `FLASH_LOAN_RISK` | `.sol`, `.js`, `.ts` |
283
+ | Suspicious IP Address | `SUSPICIOUS_IP` | All |
284
+ | Social Engineering | `SOCIAL_ENGINEERING` | `.md` |
285
+
286
+ ---
287
+
288
+ ## 6. Trust Registry & Capability Model
289
+
290
+ ### Trust Levels
291
+
292
+ | Level | Priority | Description |
293
+ |-------|----------|-------------|
294
+ | `untrusted` | 0 | Unknown skill — read-only access only |
295
+ | `restricted` | 1 | Limited capabilities — per attestation |
296
+ | `trusted` | 2 | Full capabilities within attestation |
297
+
298
+ ### Capability Model Structure
299
+
300
+ ```typescript
301
+ interface CapabilityModel {
302
+ network_allowlist: string[]; // Allowed domains (glob patterns)
303
+ filesystem_allowlist: string[]; // Allowed paths (glob patterns)
304
+ exec: 'allow' | 'deny'; // Command execution
305
+ secrets_allowlist: string[]; // Allowed secret patterns
306
+ web3?: {
307
+ chains_allowlist: number[]; // Chain IDs
308
+ rpc_allowlist: string[]; // RPC endpoints
309
+ tx_policy: 'allow' | 'confirm_high_risk' | 'deny';
310
+ };
311
+ }
312
+ ```
313
+
314
+ ### Capability Presets
315
+
316
+ #### `none` — Most Restrictive
317
+ ```json
318
+ {
319
+ "network_allowlist": [],
320
+ "filesystem_allowlist": [],
321
+ "exec": "deny",
322
+ "secrets_allowlist": []
323
+ }
324
+ ```
325
+
326
+ #### `read_only`
327
+ ```json
328
+ {
329
+ "network_allowlist": [],
330
+ "filesystem_allowlist": ["./**"],
331
+ "exec": "deny",
332
+ "secrets_allowlist": []
333
+ }
334
+ ```
335
+
336
+ #### `trading_bot`
337
+ ```json
338
+ {
339
+ "network_allowlist": [
340
+ "api.binance.com", "api.bybit.com", "api.okx.com",
341
+ "api.coinbase.com", "*.dextools.io", "*.coingecko.com"
342
+ ],
343
+ "filesystem_allowlist": ["./config/**", "./logs/**"],
344
+ "exec": "deny",
345
+ "secrets_allowlist": ["*_API_KEY", "*_API_SECRET"],
346
+ "web3": {
347
+ "chains_allowlist": [1, 56, 137, 42161],
348
+ "rpc_allowlist": ["*"],
349
+ "tx_policy": "confirm_high_risk"
350
+ }
351
+ }
352
+ ```
353
+
354
+ #### `defi`
355
+ ```json
356
+ {
357
+ "network_allowlist": ["*"],
358
+ "filesystem_allowlist": [],
359
+ "exec": "deny",
360
+ "secrets_allowlist": [],
361
+ "web3": {
362
+ "chains_allowlist": [1, 56, 137, 42161, 10, 8453, 43114],
363
+ "rpc_allowlist": ["*"],
364
+ "tx_policy": "confirm_high_risk"
365
+ }
366
+ }
367
+ ```
368
+
369
+ ### Capability Enforcement
370
+
371
+ | Action Type | Capability Check |
372
+ |-------------|------------------|
373
+ | `exec_command` | `can_exec !== false` |
374
+ | `network_request` | `can_network !== false` |
375
+ | `write_file` | `can_write !== false` |
376
+ | `read_file` | `can_read !== false` |
377
+ | `web3_tx` / `web3_sign` | `can_web3 !== false` |
378
+
379
+ ---
380
+
381
+ ## 7. Platform Integration
382
+
383
+ ### 7.1 Claude Code
384
+
385
+ **Hook Events**: `PreToolUse`, `PostToolUse`
386
+
387
+ **Tool Mapping**:
388
+
389
+ | Claude Code Tool | Action Type |
390
+ |------------------|-------------|
391
+ | `Bash` | `exec_command` |
392
+ | `Write` | `write_file` |
393
+ | `Edit` | `write_file` |
394
+ | `WebFetch` | `network_request` |
395
+ | `WebSearch` | `network_request` |
396
+
397
+ **Configuration** (`~/.claude/settings.json`):
398
+
399
+ ```json
400
+ {
401
+ "hooks": {
402
+ "PreToolUse": [
403
+ {
404
+ "matcher": { "tool_name": "*" },
405
+ "hooks": ["agentguard-hook"]
406
+ }
407
+ ]
408
+ }
409
+ }
410
+ ```
411
+
412
+ ### 7.2 OpenClaw
413
+
414
+ **Hook Events**: `before_tool_call`, `after_tool_call`
415
+
416
+ **Tool Mapping**:
417
+
418
+ | OpenClaw Tool | Action Type |
419
+ |---------------|-------------|
420
+ | `exec` / `exec_*` | `exec_command` |
421
+ | `write` | `write_file` |
422
+ | `read` | `read_file` |
423
+ | `web_fetch` | `network_request` |
424
+ | `browser` | `network_request` |
425
+
426
+ **Auto-Scan & Registration**:
427
+
428
+ When AgentGuard registers as an OpenClaw plugin, it automatically:
429
+
430
+ 1. **Scans all loaded plugins** - Static analysis of each plugin's source code
431
+ 2. **Determines trust level** - Based on scan results (critical findings → untrusted)
432
+ 3. **Infers capabilities** - Based on registered tools and scan risk level
433
+ 4. **Registers to trust registry** - Auto-attests each plugin
434
+ 5. **Builds tool mapping** - Maps `toolName → pluginId` for initiating skill inference
435
+
436
+ **Trust Level Assignment**:
437
+
438
+ | Scan Result | Trust Level | Capabilities |
439
+ |-------------|-------------|--------------|
440
+ | critical / dangerous patterns | `untrusted` | read-only |
441
+ | high risk | `restricted` | limited per scan |
442
+ | medium risk | `restricted` | limited per scan |
443
+ | low risk | `trusted` | full per tool type |
444
+
445
+ **Configuration** (Plugin registration):
446
+
447
+ ```typescript
448
+ import { registerOpenClawPlugin } from '@goplus/agentguard';
449
+
450
+ // Basic registration (auto-scan enabled)
451
+ registerOpenClawPlugin(api);
452
+
453
+ // With options
454
+ registerOpenClawPlugin(api, {
455
+ level: 'balanced', // Protection level
456
+ skipAutoScan: false, // Set true to disable auto-scanning
457
+ });
458
+ ```
459
+
460
+ **Exported Utilities**:
461
+
462
+ ```typescript
463
+ import {
464
+ getPluginIdFromTool, // Get plugin ID from tool name
465
+ getPluginScanResult, // Get cached scan result for plugin
466
+ } from '@goplus/agentguard';
467
+ ```
468
+
469
+ ---
470
+
471
+ ## 8. Quick Reference Tables
472
+
473
+ ### Always Block (Critical — DENY)
474
+
475
+ | Category | Rules |
476
+ |----------|-------|
477
+ | **Destructive commands** | `rm -rf`, `mkfs`, `dd if=`, fork bomb, `chmod 777`, `curl\|bash` |
478
+ | **Key exfiltration** | Private keys (0x+64 hex), mnemonics (12-24 BIP39), SSH keys |
479
+ | **Webhook exfil** | Discord/Telegram/Slack webhooks (unless allowlisted) |
480
+ | **Prompt injection** | `ignore previous instructions`, jailbreak attempts |
481
+ | **Malicious addresses** | GoPlus-flagged phishing/blacklisted addresses |
482
+
483
+ ### Require Confirmation (High — CONFIRM in balanced)
484
+
485
+ | Category | Rules |
486
+ |----------|-------|
487
+ | **Sensitive data access** | `cat /etc/passwd`, `cat ~/.ssh`, `env`, `printenv` |
488
+ | **API key leakage** | AWS/GitHub/Bearer tokens in request body |
489
+ | **Untrusted domains** | POST/PUT to non-allowlisted domains |
490
+ | **Web3 high-risk** | Unlimited approval, unknown spender |
491
+ | **Untrusted skills** | Skills not in trust registry |
492
+
493
+ ### Audit but Allow (Medium — ALLOW with logging)
494
+
495
+ | Category | Rules |
496
+ |----------|-------|
497
+ | **Install commands** | `npm install`, `pip install`, `git clone` |
498
+ | **System commands** | `sudo`, `systemctl`, `chmod` |
499
+ | **Network commands** | `curl`, `wget`, `ssh` |
500
+ | **Shell metacharacters** | Commands with pipes, semicolons, etc. |
501
+
502
+ ### Safe Pass-through (Low — ALLOW)
503
+
504
+ | Category | Commands |
505
+ |----------|----------|
506
+ | **Read-only** | `ls`, `cat`, `grep`, `find`, `pwd`, `whoami` |
507
+ | **Git operations** | `git status`, `git log`, `git diff`, `git add`, `git commit`, `git push` |
508
+ | **Build commands** | `npm run`, `npm test`, `tsc`, `go build`, `cargo build` |
509
+ | **Version checks** | `node -v`, `npm -v`, `python --version` |
510
+
511
+ ---
512
+
513
+ ## 9. Default Policy Summary
514
+
515
+ ```yaml
516
+ # Secret Exfiltration
517
+ secret_exfil:
518
+ private_key: DENY (always)
519
+ mnemonic: DENY (always)
520
+ ssh_key: DENY (always)
521
+ api_secret: CONFIRM
522
+
523
+ # Command Execution
524
+ exec_command:
525
+ dangerous: DENY (always)
526
+ safe_list: ALLOW
527
+ default: evaluate by capability
528
+
529
+ # Network
530
+ network:
531
+ webhook_domain: DENY (unless allowlisted)
532
+ body_contains_secret: DENY/CONFIRM by priority
533
+ untrusted_domain: CONFIRM
534
+
535
+ # Web3
536
+ web3:
537
+ phishing_origin: DENY
538
+ malicious_address: DENY
539
+ unlimited_approval: CONFIRM
540
+ unknown_spender: CONFIRM
541
+
542
+ # File Operations
543
+ file:
544
+ sensitive_path_write: DENY/CONFIRM by level
545
+ read: ALLOW (unless sensitive)
546
+ ```
547
+
548
+ ---
549
+
550
+ ## 10. Changelog
551
+
552
+ | Date | Version | Changes |
553
+ |------|---------|---------|
554
+ | 2025-02 | 1.0.0 | Initial unified policy document |
555
+
556
+ ---
557
+
558
+ *This document consolidates security policies from `skills/agentguard/action-policies.md`, `skills/agentguard/scan-rules.md`, and implementation in `src/action/detectors/`.*
@@ -0,0 +1,54 @@
1
+ # Architecture
2
+
3
+ ## Project Structure
4
+
5
+ ```
6
+ agentguard/
7
+ ├── skills/agentguard/ # Agent Skills definition
8
+ │ ├── SKILL.md # Skill entry point
9
+ │ ├── scan-rules.md # Detection rule reference
10
+ │ ├── action-policies.md # Action policy reference
11
+ │ ├── web3-patterns.md # Web3 patterns reference
12
+ │ └── scripts/ # CLI tools (trust-cli, action-cli, guard-hook)
13
+ ├── hooks/hooks.json # Plugin hooks configuration
14
+ ├── src/ # TypeScript source
15
+ │ ├── scanner/ # 20-rule static analysis engine
16
+ │ ├── action/ # Runtime action evaluator + GoPlus integration
17
+ │ ├── registry/ # Trust level management
18
+ │ ├── policy/ # Default policies and presets
19
+ │ └── tests/ # Test suite
20
+ ├── examples/vulnerable-skill/ # Demo project for testing
21
+ ├── data/registry.json # Trust registry storage
22
+ ├── setup.sh # One-click install script
23
+ └── dist/ # Compiled output
24
+ ```
25
+
26
+ ## Two-Layer Architecture
27
+
28
+ ```
29
+ ┌──────────────────────────────────────────────────────┐
30
+ │ Layer 1: Auto Guard (hooks — install once, forget) │
31
+ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
32
+ │ │ PreToolUse │ │ PostToolUse │ │ Config │ │
33
+ │ │ Block danger │ │ Audit log │ │ 3 levels │ │
34
+ │ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │
35
+ │ └────────┬───────┘ │ │
36
+ │ ▼ │ │
37
+ │ ActionScanner Engine ◄────────────┘ │
38
+ └──────────────────────────────────────────────────────┘
39
+ ┌──────────────────────────────────────────────────────┐
40
+ │ Layer 2: Deep Scan (skill — on demand) │
41
+ │ /agentguard scan — 20-rule static analysis │
42
+ │ /agentguard action — Runtime action evaluation │
43
+ │ /agentguard trust — Skill trust management │
44
+ │ /agentguard report — Security event log │
45
+ └──────────────────────────────────────────────────────┘
46
+ ```
47
+
48
+ ## Testing
49
+
50
+ ```bash
51
+ npm install && npm run build && npm test
52
+ ```
53
+
54
+ 32 tests across 4 suites: scanner rules, exec command detector, network request detector, and registry CRUD.
@@ -0,0 +1,41 @@
1
+ # Claude Code
2
+
3
+ Claude Code can call AgentGuard before risky tool use.
4
+
5
+ ## Minimal runtime hook
6
+
7
+ To write the template automatically in the current project:
8
+
9
+ ```bash
10
+ agentguard init --agent claude-code
11
+ ```
12
+
13
+ This creates `.claude/hooks/agentguard-protect.sh` and `.claude/settings.local.json`.
14
+
15
+ Configure a PreToolUse hook that pipes Claude Code hook JSON to `agentguard protect`:
16
+
17
+ ```json
18
+ {
19
+ "matcher": "Bash",
20
+ "hooks": [
21
+ {
22
+ "type": "command",
23
+ "command": "AGENTGUARD_AGENT_HOST=claude-code AGENTGUARD_ACTION_TYPE=shell AGENTGUARD_TOOL_NAME=Bash agentguard protect"
24
+ }
25
+ ]
26
+ }
27
+ ```
28
+
29
+ Recommended matchers:
30
+
31
+ - `Bash` → `shell`
32
+ - `Read` → `file_read`
33
+ - `Write`, `Edit`, `MultiEdit` → `file_write`
34
+ - `WebFetch`, `WebSearch` → `network`
35
+
36
+ ## Decisions
37
+
38
+ - `allow` and `warn` exit `0`
39
+ - `require_approval` and `block` exit `2`
40
+
41
+ Connected Cloud approvals print the approval id when creation succeeds.