@enactprotocol/shared 1.0.12
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/dist/LocalToolResolver.d.ts +84 -0
- package/dist/LocalToolResolver.js +353 -0
- package/dist/api/enact-api.d.ts +124 -0
- package/dist/api/enact-api.js +406 -0
- package/dist/api/index.d.ts +2 -0
- package/dist/api/index.js +2 -0
- package/dist/api/types.d.ts +83 -0
- package/dist/api/types.js +1 -0
- package/dist/core/DaggerExecutionProvider.d.ts +169 -0
- package/dist/core/DaggerExecutionProvider.js +996 -0
- package/dist/core/DirectExecutionProvider.d.ts +23 -0
- package/dist/core/DirectExecutionProvider.js +406 -0
- package/dist/core/EnactCore.d.ts +138 -0
- package/dist/core/EnactCore.js +609 -0
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.js +3 -0
- package/dist/exec/index.d.ts +3 -0
- package/dist/exec/index.js +3 -0
- package/dist/exec/logger.d.ts +11 -0
- package/dist/exec/logger.js +57 -0
- package/dist/exec/validate.d.ts +5 -0
- package/dist/exec/validate.js +167 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +29 -0
- package/dist/lib/enact-direct.d.ts +156 -0
- package/dist/lib/enact-direct.js +158 -0
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.js +1 -0
- package/dist/security/index.d.ts +3 -0
- package/dist/security/index.js +3 -0
- package/dist/security/security.d.ts +23 -0
- package/dist/security/security.js +137 -0
- package/dist/security/sign.d.ts +103 -0
- package/dist/security/sign.js +532 -0
- package/dist/security/verification-enforcer.d.ts +41 -0
- package/dist/security/verification-enforcer.js +181 -0
- package/dist/services/McpCoreService.d.ts +102 -0
- package/dist/services/McpCoreService.js +120 -0
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +1 -0
- package/dist/types.d.ts +130 -0
- package/dist/types.js +3 -0
- package/dist/utils/config.d.ts +32 -0
- package/dist/utils/config.js +78 -0
- package/dist/utils/env-loader.d.ts +54 -0
- package/dist/utils/env-loader.js +270 -0
- package/dist/utils/help.d.ts +36 -0
- package/dist/utils/help.js +248 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.js +7 -0
- package/dist/utils/logger.d.ts +35 -0
- package/dist/utils/logger.js +75 -0
- package/dist/utils/silent-monitor.d.ts +67 -0
- package/dist/utils/silent-monitor.js +242 -0
- package/dist/utils/timeout.d.ts +5 -0
- package/dist/utils/timeout.js +23 -0
- package/dist/utils/version.d.ts +4 -0
- package/dist/utils/version.js +14 -0
- package/dist/web/env-manager-server.d.ts +29 -0
- package/dist/web/env-manager-server.js +367 -0
- package/dist/web/index.d.ts +1 -0
- package/dist/web/index.js +1 -0
- package/package.json +79 -0
- package/src/LocalToolResolver.ts +424 -0
- package/src/api/enact-api.ts +569 -0
- package/src/api/index.ts +2 -0
- package/src/api/types.ts +93 -0
- package/src/core/DaggerExecutionProvider.ts +1308 -0
- package/src/core/DirectExecutionProvider.ts +484 -0
- package/src/core/EnactCore.ts +833 -0
- package/src/core/index.ts +3 -0
- package/src/exec/index.ts +3 -0
- package/src/exec/logger.ts +63 -0
- package/src/exec/validate.ts +238 -0
- package/src/index.ts +42 -0
- package/src/lib/enact-direct.ts +258 -0
- package/src/lib/index.ts +1 -0
- package/src/security/index.ts +3 -0
- package/src/security/security.ts +188 -0
- package/src/security/sign.ts +797 -0
- package/src/security/verification-enforcer.ts +268 -0
- package/src/services/McpCoreService.ts +203 -0
- package/src/services/index.ts +1 -0
- package/src/types.ts +190 -0
- package/src/utils/config.ts +97 -0
- package/src/utils/env-loader.ts +370 -0
- package/src/utils/help.ts +257 -0
- package/src/utils/index.ts +7 -0
- package/src/utils/logger.ts +83 -0
- package/src/utils/silent-monitor.ts +328 -0
- package/src/utils/timeout.ts +26 -0
- package/src/utils/version.ts +16 -0
- package/src/web/env-manager-server.ts +465 -0
- package/src/web/index.ts +1 -0
- package/src/web/static/app.js +663 -0
- package/src/web/static/index.html +117 -0
- package/src/web/static/style.css +291 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
// src/security/security.ts - Simplified security module for CLI core
|
|
2
|
+
import logger from "../exec/logger";
|
|
3
|
+
import type { EnactTool } from "../types";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Verify the signature of an Enact tool before execution
|
|
7
|
+
* @param tool The tool to verify
|
|
8
|
+
* @returns Boolean indicating validity
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Verify that a command is safe to execute
|
|
13
|
+
* @param command The command to verify
|
|
14
|
+
* @param tool The tool containing the command
|
|
15
|
+
* @returns Object with safety status and warnings
|
|
16
|
+
*/
|
|
17
|
+
export function verifyCommandSafety(
|
|
18
|
+
command: string,
|
|
19
|
+
tool: EnactTool,
|
|
20
|
+
): {
|
|
21
|
+
isSafe: boolean;
|
|
22
|
+
warnings: string[];
|
|
23
|
+
blocked?: string[];
|
|
24
|
+
} {
|
|
25
|
+
const warnings: string[] = [];
|
|
26
|
+
const blocked: string[] = [];
|
|
27
|
+
|
|
28
|
+
// Dangerous command patterns that should be blocked
|
|
29
|
+
const dangerousPatterns = [
|
|
30
|
+
/rm\s+-rf\s+\//, // rm -rf /
|
|
31
|
+
/rm\s+-rf\s+\*/, // rm -rf *
|
|
32
|
+
/>\s*\/dev\/sd[a-z]/, // Writing to disk devices
|
|
33
|
+
/dd\s+if=.*of=\/dev/, // Direct disk writing
|
|
34
|
+
/mkfs/, // Format filesystem
|
|
35
|
+
/fdisk/, // Disk partitioning
|
|
36
|
+
/passwd/, // Password changes
|
|
37
|
+
/sudo\s+passwd/, // Password changes with sudo
|
|
38
|
+
/chmod\s+777/, // Overly permissive permissions
|
|
39
|
+
/curl.*\|\s*sh/, // Piping curl to shell
|
|
40
|
+
/wget.*\|\s*sh/, // Piping wget to shell
|
|
41
|
+
/exec\s+sh/, // Executing shell
|
|
42
|
+
/\/etc\/passwd/, // Accessing password file
|
|
43
|
+
/\/etc\/shadow/, // Accessing shadow file
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
// Check for dangerous patterns
|
|
47
|
+
for (const pattern of dangerousPatterns) {
|
|
48
|
+
if (pattern.test(command)) {
|
|
49
|
+
blocked.push(
|
|
50
|
+
`Potentially dangerous command pattern detected: ${pattern.source}`,
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Warning patterns that are suspicious but not necessarily blocked
|
|
56
|
+
const warningPatterns = [
|
|
57
|
+
/sudo\s+/, // Sudo usage
|
|
58
|
+
/su\s+/, // User switching
|
|
59
|
+
/systemctl/, // System service control
|
|
60
|
+
/service\s+/, // Service control
|
|
61
|
+
/mount/, // Mounting filesystems
|
|
62
|
+
/umount/, // Unmounting filesystems
|
|
63
|
+
/iptables/, // Firewall rules
|
|
64
|
+
/crontab/, // Cron job management
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
// Check for warning patterns
|
|
68
|
+
for (const pattern of warningPatterns) {
|
|
69
|
+
if (pattern.test(command)) {
|
|
70
|
+
warnings.push(
|
|
71
|
+
`Potentially privileged operation detected: ${pattern.source}`,
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Check for version pinning (security best practice)
|
|
77
|
+
if (command.includes("npx ") && !command.match(/npx\s+[^@#\s]+[@#]/)) {
|
|
78
|
+
if (!command.includes("github:")) {
|
|
79
|
+
warnings.push(
|
|
80
|
+
"NPX package not version-pinned - consider using @version or github:org/repo#commit",
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (
|
|
86
|
+
command.includes("uvx ") &&
|
|
87
|
+
!command.includes("git+") &&
|
|
88
|
+
!command.includes("@")
|
|
89
|
+
) {
|
|
90
|
+
warnings.push(
|
|
91
|
+
"UVX package not version-pinned - consider using @version or git+ URL",
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (
|
|
96
|
+
command.includes("docker run") &&
|
|
97
|
+
!command.match(/:[^@\s]+(@sha256:|:\w)/)
|
|
98
|
+
) {
|
|
99
|
+
warnings.push(
|
|
100
|
+
"Docker image not version-pinned - consider using specific tags or digests",
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Check for network access patterns
|
|
105
|
+
if (tool.annotations?.openWorldHint !== true) {
|
|
106
|
+
const networkPatterns = [
|
|
107
|
+
/curl\s+/, // HTTP requests
|
|
108
|
+
/wget\s+/, // HTTP requests
|
|
109
|
+
/http[s]?:\/\//, // HTTP URLs
|
|
110
|
+
/ftp:\/\//, // FTP URLs
|
|
111
|
+
/ssh\s+/, // SSH connections
|
|
112
|
+
/scp\s+/, // SCP transfers
|
|
113
|
+
/rsync.*::/, // Rsync over network
|
|
114
|
+
];
|
|
115
|
+
|
|
116
|
+
for (const pattern of networkPatterns) {
|
|
117
|
+
if (pattern.test(command)) {
|
|
118
|
+
warnings.push(
|
|
119
|
+
"Network access detected but openWorldHint not set to true",
|
|
120
|
+
);
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Check for destructive operations
|
|
127
|
+
if (tool.annotations?.destructiveHint !== true) {
|
|
128
|
+
const destructivePatterns = [
|
|
129
|
+
/rm\s+/, // File removal
|
|
130
|
+
/rmdir\s+/, // Directory removal
|
|
131
|
+
/mv\s+.*\s+\/dev\//, // Moving to device files
|
|
132
|
+
/>\s*[^&]/, // File redirection (overwriting)
|
|
133
|
+
/tee\s+/, // Writing to files
|
|
134
|
+
];
|
|
135
|
+
|
|
136
|
+
for (const pattern of destructivePatterns) {
|
|
137
|
+
if (pattern.test(command)) {
|
|
138
|
+
warnings.push(
|
|
139
|
+
"Potentially destructive operation detected but destructiveHint not set to true",
|
|
140
|
+
);
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return {
|
|
147
|
+
isSafe: blocked.length === 0,
|
|
148
|
+
warnings,
|
|
149
|
+
...(blocked.length > 0 && { blocked }),
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Sanitize environment variables to prevent injection attacks
|
|
155
|
+
* @param envVars Environment variables to sanitize
|
|
156
|
+
* @returns Sanitized environment variables
|
|
157
|
+
*/
|
|
158
|
+
export function sanitizeEnvironmentVariables(
|
|
159
|
+
envVars: Record<string, any>,
|
|
160
|
+
): Record<string, string> {
|
|
161
|
+
const sanitized: Record<string, string> = {};
|
|
162
|
+
|
|
163
|
+
for (const [key, value] of Object.entries(envVars)) {
|
|
164
|
+
// Validate environment variable name
|
|
165
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) {
|
|
166
|
+
logger.warn(`Invalid environment variable name: ${key}`);
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Convert value to string and sanitize
|
|
171
|
+
const strValue = String(value);
|
|
172
|
+
|
|
173
|
+
// Check for potentially dangerous characters
|
|
174
|
+
if (strValue.includes("\n") || strValue.includes("\r")) {
|
|
175
|
+
logger.warn(`Environment variable ${key} contains newline characters`);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (strValue.includes("$(") || strValue.includes("`")) {
|
|
179
|
+
logger.warn(
|
|
180
|
+
`Environment variable ${key} contains command substitution patterns`,
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
sanitized[key] = strValue;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return sanitized;
|
|
188
|
+
}
|