@enactprotocol/shared 1.2.13 → 2.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 (134) hide show
  1. package/README.md +44 -0
  2. package/package.json +16 -58
  3. package/src/config.ts +476 -0
  4. package/src/constants.ts +36 -0
  5. package/src/execution/command.ts +314 -0
  6. package/src/execution/index.ts +73 -0
  7. package/src/execution/runtime.ts +308 -0
  8. package/src/execution/types.ts +379 -0
  9. package/src/execution/validation.ts +508 -0
  10. package/src/index.ts +237 -30
  11. package/src/manifest/index.ts +36 -0
  12. package/src/manifest/loader.ts +187 -0
  13. package/src/manifest/parser.ts +173 -0
  14. package/src/manifest/validator.ts +309 -0
  15. package/src/paths.ts +108 -0
  16. package/src/registry.ts +219 -0
  17. package/src/resolver.ts +345 -0
  18. package/src/types/index.ts +30 -0
  19. package/src/types/manifest.ts +255 -0
  20. package/src/types.ts +5 -188
  21. package/src/utils/fs.ts +281 -0
  22. package/src/utils/logger.ts +270 -59
  23. package/src/utils/version.ts +304 -36
  24. package/tests/config.test.ts +515 -0
  25. package/tests/execution/command.test.ts +317 -0
  26. package/tests/execution/validation.test.ts +384 -0
  27. package/tests/fixtures/invalid-tool.yaml +4 -0
  28. package/tests/fixtures/valid-tool.md +62 -0
  29. package/tests/fixtures/valid-tool.yaml +40 -0
  30. package/tests/index.test.ts +8 -0
  31. package/tests/manifest/loader.test.ts +291 -0
  32. package/tests/manifest/parser.test.ts +345 -0
  33. package/tests/manifest/validator.test.ts +394 -0
  34. package/tests/manifest-types.test.ts +358 -0
  35. package/tests/paths.test.ts +153 -0
  36. package/tests/registry.test.ts +231 -0
  37. package/tests/resolver.test.ts +272 -0
  38. package/tests/utils/fs.test.ts +388 -0
  39. package/tests/utils/logger.test.ts +480 -0
  40. package/tests/utils/version.test.ts +390 -0
  41. package/tsconfig.json +12 -0
  42. package/tsconfig.tsbuildinfo +1 -0
  43. package/dist/LocalToolResolver.d.ts +0 -84
  44. package/dist/LocalToolResolver.js +0 -353
  45. package/dist/api/enact-api.d.ts +0 -130
  46. package/dist/api/enact-api.js +0 -428
  47. package/dist/api/index.d.ts +0 -2
  48. package/dist/api/index.js +0 -2
  49. package/dist/api/types.d.ts +0 -103
  50. package/dist/api/types.js +0 -1
  51. package/dist/constants.d.ts +0 -7
  52. package/dist/constants.js +0 -10
  53. package/dist/core/DaggerExecutionProvider.d.ts +0 -169
  54. package/dist/core/DaggerExecutionProvider.js +0 -1029
  55. package/dist/core/DirectExecutionProvider.d.ts +0 -23
  56. package/dist/core/DirectExecutionProvider.js +0 -406
  57. package/dist/core/EnactCore.d.ts +0 -162
  58. package/dist/core/EnactCore.js +0 -597
  59. package/dist/core/NativeExecutionProvider.d.ts +0 -9
  60. package/dist/core/NativeExecutionProvider.js +0 -16
  61. package/dist/core/index.d.ts +0 -3
  62. package/dist/core/index.js +0 -3
  63. package/dist/exec/index.d.ts +0 -3
  64. package/dist/exec/index.js +0 -3
  65. package/dist/exec/logger.d.ts +0 -11
  66. package/dist/exec/logger.js +0 -57
  67. package/dist/exec/validate.d.ts +0 -5
  68. package/dist/exec/validate.js +0 -167
  69. package/dist/index.d.ts +0 -21
  70. package/dist/index.js +0 -25
  71. package/dist/lib/enact-direct.d.ts +0 -150
  72. package/dist/lib/enact-direct.js +0 -159
  73. package/dist/lib/index.d.ts +0 -1
  74. package/dist/lib/index.js +0 -1
  75. package/dist/security/index.d.ts +0 -3
  76. package/dist/security/index.js +0 -3
  77. package/dist/security/security.d.ts +0 -23
  78. package/dist/security/security.js +0 -137
  79. package/dist/security/sign.d.ts +0 -103
  80. package/dist/security/sign.js +0 -666
  81. package/dist/security/verification-enforcer.d.ts +0 -53
  82. package/dist/security/verification-enforcer.js +0 -204
  83. package/dist/services/McpCoreService.d.ts +0 -98
  84. package/dist/services/McpCoreService.js +0 -124
  85. package/dist/services/index.d.ts +0 -1
  86. package/dist/services/index.js +0 -1
  87. package/dist/types.d.ts +0 -132
  88. package/dist/types.js +0 -3
  89. package/dist/utils/config.d.ts +0 -111
  90. package/dist/utils/config.js +0 -342
  91. package/dist/utils/env-loader.d.ts +0 -54
  92. package/dist/utils/env-loader.js +0 -270
  93. package/dist/utils/help.d.ts +0 -36
  94. package/dist/utils/help.js +0 -248
  95. package/dist/utils/index.d.ts +0 -7
  96. package/dist/utils/index.js +0 -7
  97. package/dist/utils/logger.d.ts +0 -35
  98. package/dist/utils/logger.js +0 -75
  99. package/dist/utils/silent-monitor.d.ts +0 -67
  100. package/dist/utils/silent-monitor.js +0 -242
  101. package/dist/utils/timeout.d.ts +0 -5
  102. package/dist/utils/timeout.js +0 -23
  103. package/dist/utils/version.d.ts +0 -4
  104. package/dist/utils/version.js +0 -35
  105. package/dist/web/env-manager-server.d.ts +0 -29
  106. package/dist/web/env-manager-server.js +0 -367
  107. package/dist/web/index.d.ts +0 -1
  108. package/dist/web/index.js +0 -1
  109. package/src/LocalToolResolver.ts +0 -424
  110. package/src/api/enact-api.ts +0 -604
  111. package/src/api/index.ts +0 -2
  112. package/src/api/types.ts +0 -114
  113. package/src/core/DaggerExecutionProvider.ts +0 -1357
  114. package/src/core/DirectExecutionProvider.ts +0 -484
  115. package/src/core/EnactCore.ts +0 -847
  116. package/src/core/index.ts +0 -3
  117. package/src/exec/index.ts +0 -3
  118. package/src/exec/logger.ts +0 -63
  119. package/src/exec/validate.ts +0 -238
  120. package/src/lib/enact-direct.ts +0 -254
  121. package/src/lib/index.ts +0 -1
  122. package/src/services/McpCoreService.ts +0 -201
  123. package/src/services/index.ts +0 -1
  124. package/src/utils/config.ts +0 -438
  125. package/src/utils/env-loader.ts +0 -370
  126. package/src/utils/help.ts +0 -257
  127. package/src/utils/index.ts +0 -7
  128. package/src/utils/silent-monitor.ts +0 -328
  129. package/src/utils/timeout.ts +0 -26
  130. package/src/web/env-manager-server.ts +0 -465
  131. package/src/web/index.ts +0 -1
  132. package/src/web/static/app.js +0 -663
  133. package/src/web/static/index.html +0 -117
  134. package/src/web/static/style.css +0 -291
@@ -1,137 +0,0 @@
1
- // src/security/security.ts - Simplified security module for CLI core
2
- import logger from "../exec/logger";
3
- /**
4
- * Verify the signature of an Enact tool before execution
5
- * @param tool The tool to verify
6
- * @returns Boolean indicating validity
7
- */
8
- /**
9
- * Verify that a command is safe to execute
10
- * @param command The command to verify
11
- * @param tool The tool containing the command
12
- * @returns Object with safety status and warnings
13
- */
14
- export function verifyCommandSafety(command, tool) {
15
- const warnings = [];
16
- const blocked = [];
17
- // Dangerous command patterns that should be blocked
18
- const dangerousPatterns = [
19
- /rm\s+-rf\s+\//, // rm -rf /
20
- /rm\s+-rf\s+\*/, // rm -rf *
21
- />\s*\/dev\/sd[a-z]/, // Writing to disk devices
22
- /dd\s+if=.*of=\/dev/, // Direct disk writing
23
- /mkfs/, // Format filesystem
24
- /fdisk/, // Disk partitioning
25
- /passwd/, // Password changes
26
- /sudo\s+passwd/, // Password changes with sudo
27
- /chmod\s+777/, // Overly permissive permissions
28
- /curl.*\|\s*sh/, // Piping curl to shell
29
- /wget.*\|\s*sh/, // Piping wget to shell
30
- /exec\s+sh/, // Executing shell
31
- /\/etc\/passwd/, // Accessing password file
32
- /\/etc\/shadow/, // Accessing shadow file
33
- ];
34
- // Check for dangerous patterns
35
- for (const pattern of dangerousPatterns) {
36
- if (pattern.test(command)) {
37
- blocked.push(`Potentially dangerous command pattern detected: ${pattern.source}`);
38
- }
39
- }
40
- // Warning patterns that are suspicious but not necessarily blocked
41
- const warningPatterns = [
42
- /sudo\s+/, // Sudo usage
43
- /su\s+/, // User switching
44
- /systemctl/, // System service control
45
- /service\s+/, // Service control
46
- /mount/, // Mounting filesystems
47
- /umount/, // Unmounting filesystems
48
- /iptables/, // Firewall rules
49
- /crontab/, // Cron job management
50
- ];
51
- // Check for warning patterns
52
- for (const pattern of warningPatterns) {
53
- if (pattern.test(command)) {
54
- warnings.push(`Potentially privileged operation detected: ${pattern.source}`);
55
- }
56
- }
57
- // Check for version pinning (security best practice)
58
- if (command.includes("npx ") && !command.match(/npx\s+[^@#\s]+[@#]/)) {
59
- if (!command.includes("github:")) {
60
- warnings.push("NPX package not version-pinned - consider using @version or github:org/repo#commit");
61
- }
62
- }
63
- if (command.includes("uvx ") &&
64
- !command.includes("git+") &&
65
- !command.includes("@")) {
66
- warnings.push("UVX package not version-pinned - consider using @version or git+ URL");
67
- }
68
- if (command.includes("docker run") &&
69
- !command.match(/:[^@\s]+(@sha256:|:\w)/)) {
70
- warnings.push("Docker image not version-pinned - consider using specific tags or digests");
71
- }
72
- // Check for network access patterns
73
- if (tool.annotations?.openWorldHint !== true) {
74
- const networkPatterns = [
75
- /curl\s+/, // HTTP requests
76
- /wget\s+/, // HTTP requests
77
- /http[s]?:\/\//, // HTTP URLs
78
- /ftp:\/\//, // FTP URLs
79
- /ssh\s+/, // SSH connections
80
- /scp\s+/, // SCP transfers
81
- /rsync.*::/, // Rsync over network
82
- ];
83
- for (const pattern of networkPatterns) {
84
- if (pattern.test(command)) {
85
- warnings.push("Network access detected but openWorldHint not set to true");
86
- break;
87
- }
88
- }
89
- }
90
- // Check for destructive operations
91
- if (tool.annotations?.destructiveHint !== true) {
92
- const destructivePatterns = [
93
- /rm\s+/, // File removal
94
- /rmdir\s+/, // Directory removal
95
- /mv\s+.*\s+\/dev\//, // Moving to device files
96
- />\s*[^&]/, // File redirection (overwriting)
97
- /tee\s+/, // Writing to files
98
- ];
99
- for (const pattern of destructivePatterns) {
100
- if (pattern.test(command)) {
101
- warnings.push("Potentially destructive operation detected but destructiveHint not set to true");
102
- break;
103
- }
104
- }
105
- }
106
- return {
107
- isSafe: blocked.length === 0,
108
- warnings,
109
- ...(blocked.length > 0 && { blocked }),
110
- };
111
- }
112
- /**
113
- * Sanitize environment variables to prevent injection attacks
114
- * @param envVars Environment variables to sanitize
115
- * @returns Sanitized environment variables
116
- */
117
- export function sanitizeEnvironmentVariables(envVars) {
118
- const sanitized = {};
119
- for (const [key, value] of Object.entries(envVars)) {
120
- // Validate environment variable name
121
- if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) {
122
- logger.warn(`Invalid environment variable name: ${key}`);
123
- continue;
124
- }
125
- // Convert value to string and sanitize
126
- const strValue = String(value);
127
- // Check for potentially dangerous characters
128
- if (strValue.includes("\n") || strValue.includes("\r")) {
129
- logger.warn(`Environment variable ${key} contains newline characters`);
130
- }
131
- if (strValue.includes("$(") || strValue.includes("`")) {
132
- logger.warn(`Environment variable ${key} contains command substitution patterns`);
133
- }
134
- sanitized[key] = strValue;
135
- }
136
- return sanitized;
137
- }
@@ -1,103 +0,0 @@
1
- interface SignatureData {
2
- algorithm: string;
3
- type: string;
4
- signer: string;
5
- created: string;
6
- value: string;
7
- role?: string;
8
- }
9
- interface EnactTool {
10
- name: string;
11
- description: string;
12
- command: string;
13
- timeout?: string;
14
- tags?: string[];
15
- version?: string;
16
- enact?: string;
17
- protocol_version?: string;
18
- input_schema?: any;
19
- output_schema?: any;
20
- annotations?: any;
21
- env_vars?: Record<string, any>;
22
- examples?: any;
23
- resources?: any;
24
- raw_content?: string;
25
- signatures?: Array<SignatureData>;
26
- [key: string]: any;
27
- }
28
- interface VerificationPolicy {
29
- requireRoles?: string[];
30
- minimumSignatures?: number;
31
- trustedSigners?: string[];
32
- allowedAlgorithms?: string[];
33
- }
34
- /**
35
- * Get all trusted public keys mapped by their base64 representation
36
- * @returns Map of base64 public key -> PEM content
37
- */
38
- export declare function getTrustedPublicKeysMap(): Map<string, string>;
39
- /**
40
- * Sign an Enact tool and add to the signatures map
41
- * Signs only critical security fields for focused and reliable validation
42
- */
43
- export declare function signTool(toolPath: string, privateKeyPath: string, publicKeyPath: string, signerInfo: {
44
- id: string;
45
- role?: string;
46
- }, outputPath?: string): Promise<string>;
47
- /**
48
- * Verify tool signature using critical security fields only
49
- * This verifies signatures against only the security-critical fields
50
- */
51
- export declare function verifyToolSignature(toolObject: Record<string, unknown>, signatureB64: string, publicKeyObj: CryptoKey): Promise<boolean>;
52
- /**
53
- * Verify an Enact tool with embedded signatures against trusted keys
54
- * Only verifies signatures against critical security fields for focused validation
55
- */
56
- export declare function verifyTool(toolYaml: string | EnactTool, policy?: VerificationPolicy): Promise<{
57
- isValid: boolean;
58
- message: string;
59
- validSignatures: number;
60
- totalSignatures: number;
61
- verifiedSigners: Array<{
62
- signer: string;
63
- role?: string;
64
- keyId: string;
65
- }>;
66
- errors: string[];
67
- }>;
68
- /**
69
- * Check if a tool should be executed based on verification policy
70
- * @param tool Tool to check
71
- * @param policy Verification policy
72
- * @returns Whether execution should proceed
73
- */
74
- export declare function shouldExecuteTool(tool: EnactTool, policy?: VerificationPolicy): Promise<{
75
- allowed: boolean;
76
- reason: string;
77
- }>;
78
- /**
79
- * Generate a new ECC key pair
80
- */
81
- export declare function generateKeyPair(outputDir: string, prefix?: string): {
82
- privateKeyPath: string;
83
- publicKeyPath: string;
84
- };
85
- /**
86
- * Add a public key to trusted keys
87
- */
88
- export declare function addTrustedKey(keyPath: string, keyName?: string): string;
89
- /**
90
- * List all trusted keys with their base64 representations
91
- */
92
- export declare function listTrustedKeys(): Array<{
93
- id: string;
94
- filename: string;
95
- base64Key: string;
96
- fingerprint: string;
97
- }>;
98
- export declare const VERIFICATION_POLICIES: {
99
- PERMISSIVE: VerificationPolicy;
100
- ENTERPRISE: VerificationPolicy;
101
- PARANOID: VerificationPolicy;
102
- };
103
- export type { EnactTool, VerificationPolicy, SignatureData };