@claude-flow/security 3.0.0-alpha.1 → 3.0.0-alpha.11

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 (150) hide show
  1. package/README.md +292 -234
  2. package/__tests__/acceptance/security-compliance.test.ts +674 -674
  3. package/__tests__/authorization-propagator.test.ts +155 -0
  4. package/__tests__/credential-generator.test.ts +310 -310
  5. package/__tests__/fixtures/configurations.ts +425 -419
  6. package/__tests__/fixtures/index.ts +21 -21
  7. package/__tests__/helpers/create-mock.ts +469 -469
  8. package/__tests__/helpers/index.ts +32 -32
  9. package/__tests__/input-validator.test.ts +382 -381
  10. package/__tests__/integration/security-flow.test.ts +606 -606
  11. package/__tests__/keychain-adapter.test.ts +60 -0
  12. package/__tests__/oauth-browser.test.ts +13 -0
  13. package/__tests__/oauth-export-surface.test.ts +21 -0
  14. package/__tests__/oauth-pkce.test.ts +37 -0
  15. package/__tests__/password-hasher.test.ts +239 -239
  16. package/__tests__/path-validator.test.ts +302 -302
  17. package/__tests__/plugin-integrity-verifier.test.ts +199 -0
  18. package/__tests__/safe-executor.test.ts +292 -292
  19. package/__tests__/token-generator.test.ts +371 -371
  20. package/__tests__/tool-output-guardrail.test.ts +256 -0
  21. package/__tests__/unit/credential-generator.test.ts +182 -182
  22. package/__tests__/unit/password-hasher.test.ts +359 -359
  23. package/__tests__/unit/path-validator.test.ts +509 -509
  24. package/__tests__/unit/safe-executor.test.ts +667 -667
  25. package/__tests__/unit/token-generator.test.ts +310 -310
  26. package/dist/CVE-REMEDIATION.d.ts +17 -6
  27. package/dist/CVE-REMEDIATION.d.ts.map +1 -1
  28. package/dist/CVE-REMEDIATION.js +328 -12
  29. package/dist/CVE-REMEDIATION.js.map +1 -1
  30. package/dist/authorization/propagator.d.ts +148 -0
  31. package/dist/authorization/propagator.d.ts.map +1 -0
  32. package/dist/authorization/propagator.js +182 -0
  33. package/dist/authorization/propagator.js.map +1 -0
  34. package/dist/credential-generator.js +9 -9
  35. package/dist/domain/services/security-domain-service.js +1 -1
  36. package/dist/domain/services/security-domain-service.js.map +1 -1
  37. package/dist/index.d.ts +9 -1
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +21 -1
  40. package/dist/index.js.map +1 -1
  41. package/dist/keychain-adapter.d.ts +48 -0
  42. package/dist/keychain-adapter.d.ts.map +1 -0
  43. package/dist/keychain-adapter.js +0 -0
  44. package/dist/keychain-adapter.js.map +1 -0
  45. package/dist/oauth/browser.d.ts +31 -0
  46. package/dist/oauth/browser.d.ts.map +1 -0
  47. package/dist/oauth/browser.js +55 -0
  48. package/dist/oauth/browser.js.map +1 -0
  49. package/dist/oauth/callback-server.d.ts +37 -0
  50. package/dist/oauth/callback-server.d.ts.map +1 -0
  51. package/dist/oauth/callback-server.js +86 -0
  52. package/dist/oauth/callback-server.js.map +1 -0
  53. package/dist/oauth/client.d.ts +57 -0
  54. package/dist/oauth/client.d.ts.map +1 -0
  55. package/dist/oauth/client.js +120 -0
  56. package/dist/oauth/client.js.map +1 -0
  57. package/dist/oauth/pkce.d.ts +25 -0
  58. package/dist/oauth/pkce.d.ts.map +1 -0
  59. package/dist/oauth/pkce.js +36 -0
  60. package/dist/oauth/pkce.js.map +1 -0
  61. package/dist/password-hasher.d.ts.map +1 -1
  62. package/dist/password-hasher.js +8 -1
  63. package/dist/password-hasher.js.map +1 -1
  64. package/dist/plugins/integrity-verifier.d.ts +125 -0
  65. package/dist/plugins/integrity-verifier.d.ts.map +1 -0
  66. package/dist/plugins/integrity-verifier.js +186 -0
  67. package/dist/plugins/integrity-verifier.js.map +1 -0
  68. package/dist/safe-executor.d.ts +7 -0
  69. package/dist/safe-executor.d.ts.map +1 -1
  70. package/dist/safe-executor.js +21 -1
  71. package/dist/safe-executor.js.map +1 -1
  72. package/dist/tool-output-guardrail.d.ts +126 -0
  73. package/dist/tool-output-guardrail.d.ts.map +1 -0
  74. package/dist/tool-output-guardrail.js +257 -0
  75. package/dist/tool-output-guardrail.js.map +1 -0
  76. package/node_modules-incomplete-release-test/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +1 -0
  77. package/package.json +33 -28
  78. package/scripts/verify-oauth-exports.mjs +29 -0
  79. package/src/CVE-REMEDIATION.ts +591 -251
  80. package/src/application/index.ts +10 -10
  81. package/src/application/services/security-application-service.ts +193 -193
  82. package/src/authorization/propagator.ts +279 -0
  83. package/src/credential-generator.ts +368 -368
  84. package/src/domain/entities/security-context.ts +173 -173
  85. package/src/domain/index.ts +17 -17
  86. package/src/domain/services/security-domain-service.ts +296 -296
  87. package/src/index.ts +340 -271
  88. package/src/input-validator.ts +466 -466
  89. package/src/keychain-adapter.ts +0 -0
  90. package/src/oauth/browser.ts +58 -0
  91. package/src/oauth/callback-server.ts +97 -0
  92. package/src/oauth/client.ts +153 -0
  93. package/src/oauth/pkce.ts +45 -0
  94. package/src/password-hasher.ts +277 -270
  95. package/src/path-validator.ts +525 -525
  96. package/src/plugins/integrity-verifier.ts +265 -0
  97. package/src/safe-executor.ts +546 -525
  98. package/src/token-generator.ts +463 -463
  99. package/src/tool-output-guardrail.ts +360 -0
  100. package/tmp.json +0 -0
  101. package/tsconfig.json +9 -9
  102. package/tsconfig.tsbuildinfo +1 -1
  103. package/vitest.config.ts +20 -0
  104. package/.agentic-flow/intelligence.json +0 -16
  105. package/__tests__/coverage/base.css +0 -224
  106. package/__tests__/coverage/block-navigation.js +0 -87
  107. package/__tests__/coverage/coverage-final.json +0 -11
  108. package/__tests__/coverage/favicon.png +0 -0
  109. package/__tests__/coverage/index.html +0 -161
  110. package/__tests__/coverage/lcov-report/base.css +0 -224
  111. package/__tests__/coverage/lcov-report/block-navigation.js +0 -87
  112. package/__tests__/coverage/lcov-report/favicon.png +0 -0
  113. package/__tests__/coverage/lcov-report/index.html +0 -161
  114. package/__tests__/coverage/lcov-report/prettify.css +0 -1
  115. package/__tests__/coverage/lcov-report/prettify.js +0 -2
  116. package/__tests__/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  117. package/__tests__/coverage/lcov-report/sorter.js +0 -210
  118. package/__tests__/coverage/lcov-report/src/CVE-REMEDIATION.ts.html +0 -838
  119. package/__tests__/coverage/lcov-report/src/application/services/index.html +0 -116
  120. package/__tests__/coverage/lcov-report/src/application/services/security-application-service.ts.html +0 -664
  121. package/__tests__/coverage/lcov-report/src/credential-generator.ts.html +0 -1189
  122. package/__tests__/coverage/lcov-report/src/domain/entities/index.html +0 -116
  123. package/__tests__/coverage/lcov-report/src/domain/entities/security-context.ts.html +0 -604
  124. package/__tests__/coverage/lcov-report/src/domain/services/index.html +0 -116
  125. package/__tests__/coverage/lcov-report/src/domain/services/security-domain-service.ts.html +0 -973
  126. package/__tests__/coverage/lcov-report/src/index.html +0 -206
  127. package/__tests__/coverage/lcov-report/src/input-validator.ts.html +0 -1483
  128. package/__tests__/coverage/lcov-report/src/password-hasher.ts.html +0 -895
  129. package/__tests__/coverage/lcov-report/src/path-validator.ts.html +0 -1660
  130. package/__tests__/coverage/lcov-report/src/safe-executor.ts.html +0 -1660
  131. package/__tests__/coverage/lcov-report/src/token-generator.ts.html +0 -1474
  132. package/__tests__/coverage/lcov.info +0 -3650
  133. package/__tests__/coverage/prettify.css +0 -1
  134. package/__tests__/coverage/prettify.js +0 -2
  135. package/__tests__/coverage/sort-arrow-sprite.png +0 -0
  136. package/__tests__/coverage/sorter.js +0 -210
  137. package/__tests__/coverage/src/CVE-REMEDIATION.ts.html +0 -838
  138. package/__tests__/coverage/src/application/services/index.html +0 -116
  139. package/__tests__/coverage/src/application/services/security-application-service.ts.html +0 -664
  140. package/__tests__/coverage/src/credential-generator.ts.html +0 -1189
  141. package/__tests__/coverage/src/domain/entities/index.html +0 -116
  142. package/__tests__/coverage/src/domain/entities/security-context.ts.html +0 -604
  143. package/__tests__/coverage/src/domain/services/index.html +0 -116
  144. package/__tests__/coverage/src/domain/services/security-domain-service.ts.html +0 -973
  145. package/__tests__/coverage/src/index.html +0 -206
  146. package/__tests__/coverage/src/input-validator.ts.html +0 -1483
  147. package/__tests__/coverage/src/password-hasher.ts.html +0 -895
  148. package/__tests__/coverage/src/path-validator.ts.html +0 -1660
  149. package/__tests__/coverage/src/safe-executor.ts.html +0 -1660
  150. package/__tests__/coverage/src/token-generator.ts.html +0 -1474
@@ -1,173 +1,173 @@
1
- /**
2
- * Security Context Entity - Domain Layer
3
- *
4
- * Represents security context for operations with validation and policy enforcement.
5
- *
6
- * @module v3/security/domain/entities
7
- */
8
-
9
- import { randomUUID } from 'crypto';
10
-
11
- /**
12
- * Permission levels
13
- */
14
- export type PermissionLevel = 'read' | 'write' | 'execute' | 'admin';
15
-
16
- /**
17
- * Security context properties
18
- */
19
- export interface SecurityContextProps {
20
- id?: string;
21
- principalId: string;
22
- principalType: 'agent' | 'user' | 'system';
23
- permissions: PermissionLevel[];
24
- allowedPaths?: string[];
25
- blockedPaths?: string[];
26
- allowedCommands?: string[];
27
- blockedCommands?: string[];
28
- metadata?: Record<string, unknown>;
29
- expiresAt?: Date;
30
- createdAt?: Date;
31
- }
32
-
33
- /**
34
- * Security Context - Entity
35
- */
36
- export class SecurityContext {
37
- private _id: string;
38
- private _principalId: string;
39
- private _principalType: 'agent' | 'user' | 'system';
40
- private _permissions: Set<PermissionLevel>;
41
- private _allowedPaths: Set<string>;
42
- private _blockedPaths: Set<string>;
43
- private _allowedCommands: Set<string>;
44
- private _blockedCommands: Set<string>;
45
- private _metadata: Record<string, unknown>;
46
- private _expiresAt?: Date;
47
- private _createdAt: Date;
48
-
49
- private constructor(props: SecurityContextProps) {
50
- this._id = props.id ?? randomUUID();
51
- this._principalId = props.principalId;
52
- this._principalType = props.principalType;
53
- this._permissions = new Set(props.permissions);
54
- this._allowedPaths = new Set(props.allowedPaths ?? []);
55
- this._blockedPaths = new Set(props.blockedPaths ?? []);
56
- this._allowedCommands = new Set(props.allowedCommands ?? []);
57
- this._blockedCommands = new Set(props.blockedCommands ?? []);
58
- this._metadata = props.metadata ?? {};
59
- this._expiresAt = props.expiresAt;
60
- this._createdAt = props.createdAt ?? new Date();
61
- }
62
-
63
- static create(props: SecurityContextProps): SecurityContext {
64
- return new SecurityContext(props);
65
- }
66
-
67
- static fromPersistence(props: SecurityContextProps): SecurityContext {
68
- return new SecurityContext(props);
69
- }
70
-
71
- get id(): string { return this._id; }
72
- get principalId(): string { return this._principalId; }
73
- get principalType(): string { return this._principalType; }
74
- get permissions(): PermissionLevel[] { return Array.from(this._permissions); }
75
- get allowedPaths(): string[] { return Array.from(this._allowedPaths); }
76
- get blockedPaths(): string[] { return Array.from(this._blockedPaths); }
77
- get allowedCommands(): string[] { return Array.from(this._allowedCommands); }
78
- get blockedCommands(): string[] { return Array.from(this._blockedCommands); }
79
- get metadata(): Record<string, unknown> { return { ...this._metadata }; }
80
- get expiresAt(): Date | undefined { return this._expiresAt; }
81
- get createdAt(): Date { return new Date(this._createdAt); }
82
-
83
- // Business Logic
84
-
85
- hasPermission(level: PermissionLevel): boolean {
86
- return this._permissions.has(level) || this._permissions.has('admin');
87
- }
88
-
89
- isExpired(): boolean {
90
- if (!this._expiresAt) return false;
91
- return Date.now() > this._expiresAt.getTime();
92
- }
93
-
94
- canAccessPath(path: string): boolean {
95
- if (this.isExpired()) return false;
96
-
97
- // Check blocked paths first
98
- for (const blocked of this._blockedPaths) {
99
- if (path.startsWith(blocked) || this.matchGlob(path, blocked)) {
100
- return false;
101
- }
102
- }
103
-
104
- // If no allowed paths specified, allow all non-blocked
105
- if (this._allowedPaths.size === 0) return true;
106
-
107
- // Check allowed paths
108
- for (const allowed of this._allowedPaths) {
109
- if (path.startsWith(allowed) || this.matchGlob(path, allowed)) {
110
- return true;
111
- }
112
- }
113
-
114
- return false;
115
- }
116
-
117
- canExecuteCommand(command: string): boolean {
118
- if (this.isExpired()) return false;
119
-
120
- const cmdBase = command.split(' ')[0];
121
-
122
- // Check blocked commands first
123
- if (this._blockedCommands.has(cmdBase) || this._blockedCommands.has(command)) {
124
- return false;
125
- }
126
-
127
- // If no allowed commands specified, allow all non-blocked
128
- if (this._allowedCommands.size === 0) return true;
129
-
130
- // Check allowed commands
131
- return this._allowedCommands.has(cmdBase) || this._allowedCommands.has(command);
132
- }
133
-
134
- private matchGlob(path: string, pattern: string): boolean {
135
- const regex = pattern
136
- .replace(/\*\*/g, '.*')
137
- .replace(/\*/g, '[^/]*')
138
- .replace(/\?/g, '.');
139
- return new RegExp(`^${regex}$`).test(path);
140
- }
141
-
142
- grantPermission(level: PermissionLevel): void {
143
- this._permissions.add(level);
144
- }
145
-
146
- revokePermission(level: PermissionLevel): void {
147
- this._permissions.delete(level);
148
- }
149
-
150
- addAllowedPath(path: string): void {
151
- this._allowedPaths.add(path);
152
- }
153
-
154
- addBlockedPath(path: string): void {
155
- this._blockedPaths.add(path);
156
- }
157
-
158
- toPersistence(): Record<string, unknown> {
159
- return {
160
- id: this._id,
161
- principalId: this._principalId,
162
- principalType: this._principalType,
163
- permissions: Array.from(this._permissions),
164
- allowedPaths: Array.from(this._allowedPaths),
165
- blockedPaths: Array.from(this._blockedPaths),
166
- allowedCommands: Array.from(this._allowedCommands),
167
- blockedCommands: Array.from(this._blockedCommands),
168
- metadata: this._metadata,
169
- expiresAt: this._expiresAt?.toISOString(),
170
- createdAt: this._createdAt.toISOString(),
171
- };
172
- }
173
- }
1
+ /**
2
+ * Security Context Entity - Domain Layer
3
+ *
4
+ * Represents security context for operations with validation and policy enforcement.
5
+ *
6
+ * @module v3/security/domain/entities
7
+ */
8
+
9
+ import { randomUUID } from 'crypto';
10
+
11
+ /**
12
+ * Permission levels
13
+ */
14
+ export type PermissionLevel = 'read' | 'write' | 'execute' | 'admin';
15
+
16
+ /**
17
+ * Security context properties
18
+ */
19
+ export interface SecurityContextProps {
20
+ id?: string;
21
+ principalId: string;
22
+ principalType: 'agent' | 'user' | 'system';
23
+ permissions: PermissionLevel[];
24
+ allowedPaths?: string[];
25
+ blockedPaths?: string[];
26
+ allowedCommands?: string[];
27
+ blockedCommands?: string[];
28
+ metadata?: Record<string, unknown>;
29
+ expiresAt?: Date;
30
+ createdAt?: Date;
31
+ }
32
+
33
+ /**
34
+ * Security Context - Entity
35
+ */
36
+ export class SecurityContext {
37
+ private _id: string;
38
+ private _principalId: string;
39
+ private _principalType: 'agent' | 'user' | 'system';
40
+ private _permissions: Set<PermissionLevel>;
41
+ private _allowedPaths: Set<string>;
42
+ private _blockedPaths: Set<string>;
43
+ private _allowedCommands: Set<string>;
44
+ private _blockedCommands: Set<string>;
45
+ private _metadata: Record<string, unknown>;
46
+ private _expiresAt?: Date;
47
+ private _createdAt: Date;
48
+
49
+ private constructor(props: SecurityContextProps) {
50
+ this._id = props.id ?? randomUUID();
51
+ this._principalId = props.principalId;
52
+ this._principalType = props.principalType;
53
+ this._permissions = new Set(props.permissions);
54
+ this._allowedPaths = new Set(props.allowedPaths ?? []);
55
+ this._blockedPaths = new Set(props.blockedPaths ?? []);
56
+ this._allowedCommands = new Set(props.allowedCommands ?? []);
57
+ this._blockedCommands = new Set(props.blockedCommands ?? []);
58
+ this._metadata = props.metadata ?? {};
59
+ this._expiresAt = props.expiresAt;
60
+ this._createdAt = props.createdAt ?? new Date();
61
+ }
62
+
63
+ static create(props: SecurityContextProps): SecurityContext {
64
+ return new SecurityContext(props);
65
+ }
66
+
67
+ static fromPersistence(props: SecurityContextProps): SecurityContext {
68
+ return new SecurityContext(props);
69
+ }
70
+
71
+ get id(): string { return this._id; }
72
+ get principalId(): string { return this._principalId; }
73
+ get principalType(): string { return this._principalType; }
74
+ get permissions(): PermissionLevel[] { return Array.from(this._permissions); }
75
+ get allowedPaths(): string[] { return Array.from(this._allowedPaths); }
76
+ get blockedPaths(): string[] { return Array.from(this._blockedPaths); }
77
+ get allowedCommands(): string[] { return Array.from(this._allowedCommands); }
78
+ get blockedCommands(): string[] { return Array.from(this._blockedCommands); }
79
+ get metadata(): Record<string, unknown> { return { ...this._metadata }; }
80
+ get expiresAt(): Date | undefined { return this._expiresAt; }
81
+ get createdAt(): Date { return new Date(this._createdAt); }
82
+
83
+ // Business Logic
84
+
85
+ hasPermission(level: PermissionLevel): boolean {
86
+ return this._permissions.has(level) || this._permissions.has('admin');
87
+ }
88
+
89
+ isExpired(): boolean {
90
+ if (!this._expiresAt) return false;
91
+ return Date.now() > this._expiresAt.getTime();
92
+ }
93
+
94
+ canAccessPath(path: string): boolean {
95
+ if (this.isExpired()) return false;
96
+
97
+ // Check blocked paths first
98
+ for (const blocked of this._blockedPaths) {
99
+ if (path.startsWith(blocked) || this.matchGlob(path, blocked)) {
100
+ return false;
101
+ }
102
+ }
103
+
104
+ // If no allowed paths specified, allow all non-blocked
105
+ if (this._allowedPaths.size === 0) return true;
106
+
107
+ // Check allowed paths
108
+ for (const allowed of this._allowedPaths) {
109
+ if (path.startsWith(allowed) || this.matchGlob(path, allowed)) {
110
+ return true;
111
+ }
112
+ }
113
+
114
+ return false;
115
+ }
116
+
117
+ canExecuteCommand(command: string): boolean {
118
+ if (this.isExpired()) return false;
119
+
120
+ const cmdBase = command.split(' ')[0];
121
+
122
+ // Check blocked commands first
123
+ if (this._blockedCommands.has(cmdBase) || this._blockedCommands.has(command)) {
124
+ return false;
125
+ }
126
+
127
+ // If no allowed commands specified, allow all non-blocked
128
+ if (this._allowedCommands.size === 0) return true;
129
+
130
+ // Check allowed commands
131
+ return this._allowedCommands.has(cmdBase) || this._allowedCommands.has(command);
132
+ }
133
+
134
+ private matchGlob(path: string, pattern: string): boolean {
135
+ const regex = pattern
136
+ .replace(/\*\*/g, '.*')
137
+ .replace(/\*/g, '[^/]*')
138
+ .replace(/\?/g, '.');
139
+ return new RegExp(`^${regex}$`).test(path);
140
+ }
141
+
142
+ grantPermission(level: PermissionLevel): void {
143
+ this._permissions.add(level);
144
+ }
145
+
146
+ revokePermission(level: PermissionLevel): void {
147
+ this._permissions.delete(level);
148
+ }
149
+
150
+ addAllowedPath(path: string): void {
151
+ this._allowedPaths.add(path);
152
+ }
153
+
154
+ addBlockedPath(path: string): void {
155
+ this._blockedPaths.add(path);
156
+ }
157
+
158
+ toPersistence(): Record<string, unknown> {
159
+ return {
160
+ id: this._id,
161
+ principalId: this._principalId,
162
+ principalType: this._principalType,
163
+ permissions: Array.from(this._permissions),
164
+ allowedPaths: Array.from(this._allowedPaths),
165
+ blockedPaths: Array.from(this._blockedPaths),
166
+ allowedCommands: Array.from(this._allowedCommands),
167
+ blockedCommands: Array.from(this._blockedCommands),
168
+ metadata: this._metadata,
169
+ expiresAt: this._expiresAt?.toISOString(),
170
+ createdAt: this._createdAt.toISOString(),
171
+ };
172
+ }
173
+ }
@@ -1,17 +1,17 @@
1
- /**
2
- * Security Domain Layer - Public Exports
3
- *
4
- * @module v3/security/domain
5
- */
6
-
7
- export {
8
- SecurityContext,
9
- type PermissionLevel,
10
- type SecurityContextProps,
11
- } from './entities/security-context.js';
12
-
13
- export {
14
- SecurityDomainService,
15
- type ValidationResult,
16
- type ThreatDetectionResult,
17
- } from './services/security-domain-service.js';
1
+ /**
2
+ * Security Domain Layer - Public Exports
3
+ *
4
+ * @module v3/security/domain
5
+ */
6
+
7
+ export {
8
+ SecurityContext,
9
+ type PermissionLevel,
10
+ type SecurityContextProps,
11
+ } from './entities/security-context.js';
12
+
13
+ export {
14
+ SecurityDomainService,
15
+ type ValidationResult,
16
+ type ThreatDetectionResult,
17
+ } from './services/security-domain-service.js';