@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.
Files changed (97) hide show
  1. package/dist/LocalToolResolver.d.ts +84 -0
  2. package/dist/LocalToolResolver.js +353 -0
  3. package/dist/api/enact-api.d.ts +124 -0
  4. package/dist/api/enact-api.js +406 -0
  5. package/dist/api/index.d.ts +2 -0
  6. package/dist/api/index.js +2 -0
  7. package/dist/api/types.d.ts +83 -0
  8. package/dist/api/types.js +1 -0
  9. package/dist/core/DaggerExecutionProvider.d.ts +169 -0
  10. package/dist/core/DaggerExecutionProvider.js +996 -0
  11. package/dist/core/DirectExecutionProvider.d.ts +23 -0
  12. package/dist/core/DirectExecutionProvider.js +406 -0
  13. package/dist/core/EnactCore.d.ts +138 -0
  14. package/dist/core/EnactCore.js +609 -0
  15. package/dist/core/index.d.ts +3 -0
  16. package/dist/core/index.js +3 -0
  17. package/dist/exec/index.d.ts +3 -0
  18. package/dist/exec/index.js +3 -0
  19. package/dist/exec/logger.d.ts +11 -0
  20. package/dist/exec/logger.js +57 -0
  21. package/dist/exec/validate.d.ts +5 -0
  22. package/dist/exec/validate.js +167 -0
  23. package/dist/index.d.ts +25 -0
  24. package/dist/index.js +29 -0
  25. package/dist/lib/enact-direct.d.ts +156 -0
  26. package/dist/lib/enact-direct.js +158 -0
  27. package/dist/lib/index.d.ts +1 -0
  28. package/dist/lib/index.js +1 -0
  29. package/dist/security/index.d.ts +3 -0
  30. package/dist/security/index.js +3 -0
  31. package/dist/security/security.d.ts +23 -0
  32. package/dist/security/security.js +137 -0
  33. package/dist/security/sign.d.ts +103 -0
  34. package/dist/security/sign.js +532 -0
  35. package/dist/security/verification-enforcer.d.ts +41 -0
  36. package/dist/security/verification-enforcer.js +181 -0
  37. package/dist/services/McpCoreService.d.ts +102 -0
  38. package/dist/services/McpCoreService.js +120 -0
  39. package/dist/services/index.d.ts +1 -0
  40. package/dist/services/index.js +1 -0
  41. package/dist/types.d.ts +130 -0
  42. package/dist/types.js +3 -0
  43. package/dist/utils/config.d.ts +32 -0
  44. package/dist/utils/config.js +78 -0
  45. package/dist/utils/env-loader.d.ts +54 -0
  46. package/dist/utils/env-loader.js +270 -0
  47. package/dist/utils/help.d.ts +36 -0
  48. package/dist/utils/help.js +248 -0
  49. package/dist/utils/index.d.ts +7 -0
  50. package/dist/utils/index.js +7 -0
  51. package/dist/utils/logger.d.ts +35 -0
  52. package/dist/utils/logger.js +75 -0
  53. package/dist/utils/silent-monitor.d.ts +67 -0
  54. package/dist/utils/silent-monitor.js +242 -0
  55. package/dist/utils/timeout.d.ts +5 -0
  56. package/dist/utils/timeout.js +23 -0
  57. package/dist/utils/version.d.ts +4 -0
  58. package/dist/utils/version.js +14 -0
  59. package/dist/web/env-manager-server.d.ts +29 -0
  60. package/dist/web/env-manager-server.js +367 -0
  61. package/dist/web/index.d.ts +1 -0
  62. package/dist/web/index.js +1 -0
  63. package/package.json +79 -0
  64. package/src/LocalToolResolver.ts +424 -0
  65. package/src/api/enact-api.ts +569 -0
  66. package/src/api/index.ts +2 -0
  67. package/src/api/types.ts +93 -0
  68. package/src/core/DaggerExecutionProvider.ts +1308 -0
  69. package/src/core/DirectExecutionProvider.ts +484 -0
  70. package/src/core/EnactCore.ts +833 -0
  71. package/src/core/index.ts +3 -0
  72. package/src/exec/index.ts +3 -0
  73. package/src/exec/logger.ts +63 -0
  74. package/src/exec/validate.ts +238 -0
  75. package/src/index.ts +42 -0
  76. package/src/lib/enact-direct.ts +258 -0
  77. package/src/lib/index.ts +1 -0
  78. package/src/security/index.ts +3 -0
  79. package/src/security/security.ts +188 -0
  80. package/src/security/sign.ts +797 -0
  81. package/src/security/verification-enforcer.ts +268 -0
  82. package/src/services/McpCoreService.ts +203 -0
  83. package/src/services/index.ts +1 -0
  84. package/src/types.ts +190 -0
  85. package/src/utils/config.ts +97 -0
  86. package/src/utils/env-loader.ts +370 -0
  87. package/src/utils/help.ts +257 -0
  88. package/src/utils/index.ts +7 -0
  89. package/src/utils/logger.ts +83 -0
  90. package/src/utils/silent-monitor.ts +328 -0
  91. package/src/utils/timeout.ts +26 -0
  92. package/src/utils/version.ts +16 -0
  93. package/src/web/env-manager-server.ts +465 -0
  94. package/src/web/index.ts +1 -0
  95. package/src/web/static/app.js +663 -0
  96. package/src/web/static/index.html +117 -0
  97. 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
+ }