@claude-flow/security 3.0.0-alpha.9 → 3.0.1

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 (116) hide show
  1. package/dist/CVE-REMEDIATION.d.ts +17 -6
  2. package/dist/CVE-REMEDIATION.d.ts.map +1 -1
  3. package/dist/CVE-REMEDIATION.js +328 -12
  4. package/dist/CVE-REMEDIATION.js.map +1 -1
  5. package/dist/index.d.ts +8 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +26 -0
  8. package/dist/index.js.map +1 -1
  9. package/dist/keychain-adapter.d.ts +48 -0
  10. package/dist/keychain-adapter.d.ts.map +1 -0
  11. package/dist/keychain-adapter.js +0 -0
  12. package/dist/keychain-adapter.js.map +1 -0
  13. package/dist/mcp-caller-identity.d.ts +101 -0
  14. package/dist/mcp-caller-identity.d.ts.map +1 -0
  15. package/dist/mcp-caller-identity.js +0 -0
  16. package/dist/mcp-caller-identity.js.map +1 -0
  17. package/dist/mcp-composition-inspector.d.ts +133 -0
  18. package/dist/mcp-composition-inspector.d.ts.map +1 -0
  19. package/dist/mcp-composition-inspector.js +254 -0
  20. package/dist/mcp-composition-inspector.js.map +1 -0
  21. package/dist/oauth/browser.d.ts +31 -0
  22. package/dist/oauth/browser.d.ts.map +1 -0
  23. package/dist/oauth/browser.js +55 -0
  24. package/dist/oauth/browser.js.map +1 -0
  25. package/dist/oauth/callback-server.d.ts +37 -0
  26. package/dist/oauth/callback-server.d.ts.map +1 -0
  27. package/dist/oauth/callback-server.js +86 -0
  28. package/dist/oauth/callback-server.js.map +1 -0
  29. package/dist/oauth/client.d.ts +57 -0
  30. package/dist/oauth/client.d.ts.map +1 -0
  31. package/dist/oauth/client.js +120 -0
  32. package/dist/oauth/client.js.map +1 -0
  33. package/dist/oauth/pkce.d.ts +25 -0
  34. package/dist/oauth/pkce.d.ts.map +1 -0
  35. package/dist/oauth/pkce.js +36 -0
  36. package/dist/oauth/pkce.js.map +1 -0
  37. package/dist/path-validator.d.ts +23 -0
  38. package/dist/path-validator.d.ts.map +1 -1
  39. package/dist/path-validator.js +128 -5
  40. package/dist/path-validator.js.map +1 -1
  41. package/dist/policy/canonical.d.ts +5 -0
  42. package/dist/policy/canonical.d.ts.map +1 -0
  43. package/dist/policy/canonical.js +30 -0
  44. package/dist/policy/canonical.js.map +1 -0
  45. package/dist/policy/engine.d.ts +30 -0
  46. package/dist/policy/engine.d.ts.map +1 -0
  47. package/dist/policy/engine.js +319 -0
  48. package/dist/policy/engine.js.map +1 -0
  49. package/dist/policy/envelope.d.ts +9 -0
  50. package/dist/policy/envelope.d.ts.map +1 -0
  51. package/dist/policy/envelope.js +90 -0
  52. package/dist/policy/envelope.js.map +1 -0
  53. package/dist/policy/evaluator.d.ts +4 -0
  54. package/dist/policy/evaluator.d.ts.map +1 -0
  55. package/dist/policy/evaluator.js +119 -0
  56. package/dist/policy/evaluator.js.map +1 -0
  57. package/dist/policy/index.d.ts +7 -0
  58. package/dist/policy/index.d.ts.map +1 -0
  59. package/dist/policy/index.js +7 -0
  60. package/dist/policy/index.js.map +1 -0
  61. package/dist/policy/product-plane.d.ts +238 -0
  62. package/dist/policy/product-plane.d.ts.map +1 -0
  63. package/dist/policy/product-plane.js +1022 -0
  64. package/dist/policy/product-plane.js.map +1 -0
  65. package/dist/policy/types.d.ts +187 -0
  66. package/dist/policy/types.d.ts.map +1 -0
  67. package/dist/policy/types.js +2 -0
  68. package/dist/policy/types.js.map +1 -0
  69. package/dist/safe-git.d.ts +22 -0
  70. package/dist/safe-git.d.ts.map +1 -0
  71. package/dist/safe-git.js +63 -0
  72. package/dist/safe-git.js.map +1 -0
  73. package/package.json +17 -5
  74. package/.claude-flow/data/pending-insights.jsonl +0 -6
  75. package/.claude-flow/neural/stats.json +0 -6
  76. package/__tests__/acceptance/security-compliance.test.ts +0 -674
  77. package/__tests__/authorization-propagator.test.ts +0 -155
  78. package/__tests__/credential-generator.test.ts +0 -310
  79. package/__tests__/fixtures/configurations.ts +0 -425
  80. package/__tests__/fixtures/index.ts +0 -21
  81. package/__tests__/helpers/create-mock.ts +0 -469
  82. package/__tests__/helpers/index.ts +0 -32
  83. package/__tests__/input-validator.test.ts +0 -382
  84. package/__tests__/integration/security-flow.test.ts +0 -606
  85. package/__tests__/password-hasher.test.ts +0 -239
  86. package/__tests__/path-validator.test.ts +0 -302
  87. package/__tests__/plugin-integrity-verifier.test.ts +0 -199
  88. package/__tests__/safe-executor.test.ts +0 -292
  89. package/__tests__/token-generator.test.ts +0 -371
  90. package/__tests__/tool-output-guardrail.test.ts +0 -256
  91. package/__tests__/unit/credential-generator.test.ts +0 -182
  92. package/__tests__/unit/password-hasher.test.ts +0 -359
  93. package/__tests__/unit/path-validator.test.ts +0 -509
  94. package/__tests__/unit/safe-executor.test.ts +0 -667
  95. package/__tests__/unit/token-generator.test.ts +0 -310
  96. package/ruvector.db +0 -0
  97. package/src/CVE-REMEDIATION.ts +0 -251
  98. package/src/application/index.ts +0 -10
  99. package/src/application/services/security-application-service.ts +0 -193
  100. package/src/authorization/propagator.ts +0 -279
  101. package/src/credential-generator.ts +0 -368
  102. package/src/domain/entities/security-context.ts +0 -173
  103. package/src/domain/index.ts +0 -17
  104. package/src/domain/services/security-domain-service.ts +0 -296
  105. package/src/index.ts +0 -314
  106. package/src/input-validator.ts +0 -466
  107. package/src/password-hasher.ts +0 -277
  108. package/src/path-validator.ts +0 -525
  109. package/src/plugins/integrity-verifier.ts +0 -265
  110. package/src/safe-executor.ts +0 -546
  111. package/src/token-generator.ts +0 -463
  112. package/src/tool-output-guardrail.ts +0 -360
  113. package/tmp.json +0 -0
  114. package/tsconfig.json +0 -9
  115. package/tsconfig.tsbuildinfo +0 -1
  116. package/vitest.config.ts +0 -20
@@ -1,265 +0,0 @@
1
- /**
2
- * PluginIntegrityVerifier — install-layer security for plugin supply chain.
3
- *
4
- * Implements P1 of ADR-145 (ruvnet/ruflo#2254): Stage-1 Ed25519 signature
5
- * verification at `plugins install`. Stage-2 (semantic-intent scan against
6
- * SCH attacks) lands in P2; per-namespace write ACLs land in P3-P4.
7
- *
8
- * Threat model
9
- * ------------
10
- * Ruflo's plugin install path fetches manifests from IPFS via Pinata with
11
- * NO signature verification and NO intent analysis. Two attacks land today:
12
- *
13
- * - DDIPE (arXiv:2604.03081): malicious logic embedded in plugin docs and
14
- * config templates. 11.6-33.5% bypass rate across 4 frameworks/5 models;
15
- * 2.5% evade both detection and alignment. Stage-1 signing blocks the
16
- * static-payload variants.
17
- *
18
- * - SCH (arXiv:2605.14460): malicious intent wrapped as natural-language
19
- * "compliance rules" in plugin descriptions. The agent generates the
20
- * harmful code at runtime — no static payload exists. 77.67% breach
21
- * success, 0.00% scanner detection. Stage-2 (P2) catches this; Stage-1
22
- * does not.
23
- *
24
- * Scope (P1)
25
- * ----------
26
- * - Ed25519 signature verification of a detached signature over the manifest.
27
- * - Trust-anchor allowlist: the publisher's signing key fingerprint must be
28
- * in `trust-anchors.json`, gated on CODEOWNERS review.
29
- * - Backwards compatible: default mode is warn-only. `CLAUDE_FLOW_STRICT_PLUGINS=true`
30
- * makes verification a hard gate.
31
- *
32
- * Non-goals (P1)
33
- * --------------
34
- * - Semantic intent scan (SCH defence). Lands in P2 with a pattern-rule
35
- * fallback for environments without LLM credentials.
36
- * - Sandboxing the plugin runtime. Orthogonal blast-radius concern.
37
- *
38
- * Reference: ADR-145, arXiv:2605.14460 (SCH), arXiv:2604.03081 (DDIPE),
39
- * arXiv:2604.16548 (Mnemonic Sovereignty survey).
40
- */
41
-
42
- import { createHash } from 'node:crypto';
43
- import * as nodeCrypto from 'node:crypto';
44
-
45
- export interface PluginManifest {
46
- readonly id: string;
47
- readonly version: string;
48
- /** Anything else; only `id` + `version` matter for the integrity hash. */
49
- readonly [extra: string]: unknown;
50
- }
51
-
52
- export interface SignedPluginManifest {
53
- readonly manifest: PluginManifest;
54
- /** Hex-encoded SHA-256 of the canonical JSON serialisation of manifest. */
55
- readonly manifestHash: string;
56
- /** Hex-encoded detached Ed25519 signature over `manifestHash` bytes. */
57
- readonly signature: string;
58
- /** Hex-encoded Ed25519 public key of the signer. */
59
- readonly publicKey: string;
60
- }
61
-
62
- export interface TrustAnchor {
63
- /** Hex-encoded Ed25519 public key the publisher signs with. */
64
- readonly publicKey: string;
65
- /** Human-readable owner — for audit, not for trust decisions. */
66
- readonly owner: string;
67
- /** Optional ISO 8601 date after which this anchor is no longer trusted. */
68
- readonly expiresAt?: string;
69
- /** Optional plugin id glob this anchor is authoritative for (e.g. `@claude-flow/*`). */
70
- readonly scope?: string;
71
- }
72
-
73
- export interface TrustAnchors {
74
- readonly version: 1;
75
- readonly anchors: ReadonlyArray<TrustAnchor>;
76
- }
77
-
78
- export type VerificationStatus =
79
- | 'pass'
80
- | 'signature-missing'
81
- | 'signature-invalid'
82
- | 'manifest-hash-mismatch'
83
- | 'unknown-signer'
84
- | 'signer-expired'
85
- | 'signer-out-of-scope';
86
-
87
- export interface VerificationResult {
88
- readonly status: VerificationStatus;
89
- readonly pluginId: string;
90
- readonly signerFingerprint?: string;
91
- /** Verification timestamp — useful for telemetry correlation. */
92
- readonly ts: number;
93
- /** Operator-facing detail; do not parse — log only. */
94
- readonly detail?: string;
95
- }
96
-
97
- export interface VerifierConfig {
98
- readonly trustAnchors: TrustAnchors;
99
- /**
100
- * When true, `verify` returns the actual failure status. When false (legacy
101
- * mode), `verify` returns the failure status BUT callers may choose to
102
- * proceed with a warning — the strictness gate lives at the caller, not
103
- * here, so the verifier itself is always pure.
104
- */
105
- readonly strict?: boolean;
106
- /** Optional now-provider for tests. */
107
- readonly now?: () => number;
108
- }
109
-
110
- /**
111
- * Canonical JSON serialisation for hashing. Deterministic key ordering at
112
- * every nesting level. Pure; identical input → identical output bytes.
113
- */
114
- export function canonicalize(value: unknown): string {
115
- if (value === null || typeof value !== 'object') return JSON.stringify(value);
116
- if (Array.isArray(value)) return '[' + value.map(canonicalize).join(',') + ']';
117
- const obj = value as Record<string, unknown>;
118
- const keys = Object.keys(obj).sort();
119
- return '{' + keys.map(k => JSON.stringify(k) + ':' + canonicalize(obj[k])).join(',') + '}';
120
- }
121
-
122
- /** Hex-encoded SHA-256 of the canonical-JSON manifest. */
123
- export function hashManifest(manifest: PluginManifest): string {
124
- return createHash('sha256').update(canonicalize(manifest)).digest('hex');
125
- }
126
-
127
- /** Short fingerprint for telemetry — first 16 hex chars of the key. */
128
- export function fingerprint(publicKey: string): string {
129
- return publicKey.slice(0, 16);
130
- }
131
-
132
- /**
133
- * Find the trust anchor that vouches for a manifest. Returns the matched
134
- * anchor (with anchor.publicKey === signer.publicKey) or null.
135
- *
136
- * Scope-matching uses a minimal glob: `*` at the end of the scope string
137
- * matches any suffix. Empty/missing scope matches every plugin id.
138
- */
139
- export function findAnchor(
140
- anchors: ReadonlyArray<TrustAnchor>,
141
- pluginId: string,
142
- signerPublicKey: string,
143
- now: number,
144
- ): TrustAnchor | null {
145
- for (const a of anchors) {
146
- if (a.publicKey !== signerPublicKey) continue;
147
- if (a.expiresAt && new Date(a.expiresAt).getTime() <= now) continue;
148
- if (!a.scope || a.scope === '*' || a.scope === pluginId) return a;
149
- if (a.scope.endsWith('*') && pluginId.startsWith(a.scope.slice(0, -1))) return a;
150
- }
151
- return null;
152
- }
153
-
154
- /**
155
- * `PluginIntegrityVerifier` — Stage-1 verifier (signature + trust anchor).
156
- *
157
- * Pure-ish: holds the trust-anchor list and clock, no other state. Safe to
158
- * construct per-invocation or share.
159
- */
160
- export class PluginIntegrityVerifier {
161
- constructor(private readonly config: VerifierConfig) {}
162
-
163
- /**
164
- * Verify a signed manifest. Returns the verification status; the caller
165
- * decides what to do with `signature-missing` / `manifest-hash-mismatch`
166
- * etc. based on its strict-mode policy.
167
- */
168
- async verify(signed: SignedPluginManifest): Promise<VerificationResult> {
169
- const now = (this.config.now ?? Date.now)();
170
- const pluginId = signed.manifest?.id ?? '<unknown>';
171
-
172
- if (!signed.signature || !signed.publicKey) {
173
- return { status: 'signature-missing', pluginId, ts: now };
174
- }
175
-
176
- // Re-hash the manifest and compare to the signed hash.
177
- const recomputed = hashManifest(signed.manifest);
178
- if (recomputed !== signed.manifestHash) {
179
- return {
180
- status: 'manifest-hash-mismatch',
181
- pluginId,
182
- signerFingerprint: fingerprint(signed.publicKey),
183
- ts: now,
184
- detail: `expected ${signed.manifestHash}, got ${recomputed}`,
185
- };
186
- }
187
-
188
- // Find a trust anchor that vouches for this signer + plugin.
189
- const anchor = findAnchor(this.config.trustAnchors.anchors, pluginId, signed.publicKey, now);
190
- if (!anchor) {
191
- return {
192
- status: 'unknown-signer',
193
- pluginId,
194
- signerFingerprint: fingerprint(signed.publicKey),
195
- ts: now,
196
- };
197
- }
198
-
199
- // Ed25519 verify. Probe @noble/ed25519 (already a workspace dep); fall
200
- // back to the failure status if it isn't resolvable in this environment
201
- // (mirrors verify.mjs's #1880 precondition pattern).
202
- const ed = await loadEd25519();
203
- if (!ed) {
204
- return {
205
- status: 'signature-invalid',
206
- pluginId,
207
- signerFingerprint: fingerprint(signed.publicKey),
208
- ts: now,
209
- detail: '@noble/ed25519 not available — cannot verify',
210
- };
211
- }
212
-
213
- // Required by @noble/ed25519 v2 for sync sha512.
214
- if (!ed.etc.sha512Sync) {
215
- ed.etc.sha512Sync = (...m: Uint8Array[]): Uint8Array => {
216
- const h = nodeCrypto.createHash('sha512');
217
- for (const x of m) h.update(x);
218
- return h.digest();
219
- };
220
- }
221
-
222
- let ok = false;
223
- try {
224
- const sigBytes = hexToBytes(signed.signature);
225
- const msgBytes = hexToBytes(signed.manifestHash);
226
- const pubBytes = hexToBytes(signed.publicKey);
227
- ok = await ed.verify(sigBytes, msgBytes, pubBytes);
228
- } catch {
229
- ok = false;
230
- }
231
-
232
- if (!ok) {
233
- return {
234
- status: 'signature-invalid',
235
- pluginId,
236
- signerFingerprint: fingerprint(signed.publicKey),
237
- ts: now,
238
- };
239
- }
240
-
241
- return { status: 'pass', pluginId, signerFingerprint: fingerprint(signed.publicKey), ts: now };
242
- }
243
- }
244
-
245
- // ─── helpers ────────────────────────────────────────────────────────────
246
-
247
- function hexToBytes(hex: string): Uint8Array {
248
- const out = new Uint8Array(hex.length >>> 1);
249
- for (let i = 0; i < out.length; i++) out[i] = parseInt(hex.substr(i * 2, 2), 16);
250
- return out;
251
- }
252
-
253
- interface NobleEd25519 {
254
- verify(sig: Uint8Array, msg: Uint8Array, pub: Uint8Array): Promise<boolean>;
255
- etc: { sha512Sync?: (...m: Uint8Array[]) => Uint8Array };
256
- }
257
-
258
- async function loadEd25519(): Promise<NobleEd25519 | null> {
259
- try {
260
- const mod = await import('@noble/ed25519');
261
- return mod as unknown as NobleEd25519;
262
- } catch {
263
- return null;
264
- }
265
- }