@the-ai-company/cbio-node-runtime 0.32.0 → 0.39.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.
package/docs/REFERENCE.md CHANGED
@@ -39,18 +39,15 @@ import { sealBlob, unsealBlob } from '@the-ai-company/cbio-node-runtime/sealed';
39
39
 
40
40
  `permissions` and `deriveFromIssuedIdentity` are mutually exclusive; do not pass both.
41
41
 
42
+ Secret-use operations on a `CbioAgent` require:
43
+ - `vault:fetch` for remote authenticated use such as `fetchWithAuth(...)`
44
+ - `vault:acquire` for acquisition, ingress, compare, proof, and validation operations
45
+
42
46
  ### 1.5 Recursive Child Identity Management
43
- When a child is registered via `registerChildIdentity(keys)`, its key material is stored in the parent vault. The method returns `{ publicKey }` (domain-level identifier). The record naming scheme is an internal runtime detail; use the protocol subpath for low-level vault access:
47
+ When a child is registered via `registerChildIdentity(keys)`, its key material is stored in the parent vault. The method returns `{ publicKey }` (domain-level identifier). Treat the persisted child record as runtime-managed state rather than application-readable plaintext.
44
48
  ```ts
45
- import { getChildIdentitySecretName } from '@the-ai-company/cbio-node-runtime/protocol';
46
-
47
49
  const { publicKey: childPublicKey } = await identity.registerChildIdentity(keys);
48
- const secretName = getChildIdentitySecretName(childPublicKey);
49
- const stored = identity.admin.vault.getSecret(secretName);
50
- if (stored) {
51
- const { privateKey, publicKey } = JSON.parse(stored);
52
- const childIdentity = await CbioIdentity.load({ privateKey, publicKey });
53
- }
50
+ console.log(childPublicKey);
54
51
  ```
55
52
 
56
53
  ---
@@ -160,6 +157,115 @@ const proxy = await startLocalAuthProxy({
160
157
  });
161
158
  ```
162
159
 
160
+ ### 3.5 Local Secret Ingress
161
+ Use `startLocalSecretIngress(...)` when a trusted local process already has a newly issued secret and should hand it directly into CBIO without printing it to terminal output first.
162
+
163
+ ```ts
164
+ const ingress = await identity.startLocalSecretIngress({
165
+ secretName: 'service-token',
166
+ });
167
+
168
+ await fetch(ingress.url, {
169
+ method: 'POST',
170
+ headers: {
171
+ Authorization: `Bearer ${ingress.authToken}`,
172
+ 'Content-Type': 'text/plain',
173
+ },
174
+ body: 'new-secret-value',
175
+ });
176
+ ```
177
+
178
+ Optional fields:
179
+ - `allowedOrigins`
180
+ - `overwrite`
181
+ - `host`
182
+ - `port`
183
+ - `path`
184
+ - `authToken`
185
+ - `once`
186
+ - `maxBodyBytes`
187
+
188
+ ### 3.6 Local Compare / Proof
189
+ Use `compareSecret(...)` and `proveSecret(...)` when the application needs a local KMS-like operation without exporting the stored secret.
190
+
191
+ ```ts
192
+ const same = await identity.compareSecret('service-token', 'candidate-value');
193
+ const proof = await identity.proveSecret('service-token', 'challenge-123');
194
+ ```
195
+
196
+ Current proof algorithms:
197
+ - `sha256`
198
+ - `sha512`
199
+
200
+ `proveSecret(...)` returns a base64url-encoded HMAC proof for the active secret value and the provided challenge.
201
+
202
+ ### 3.7 Secret Validation
203
+ Use `validateSecret(...)` when the application wants a structured validity result rather than exporting a secret and probing manually.
204
+
205
+ `validateSecret(...)` accepts a `SecretValidator`, whose `validate(handle)` method receives a restricted handle with:
206
+ - `fetchWithAuth(url, options?)`
207
+ - `compare(candidate)`
208
+ - `prove(challenge, options?)`
209
+
210
+ The validator never receives the plaintext secret value.
211
+
212
+ Result shape:
213
+
214
+ ```ts
215
+ type SecretValidationResult = {
216
+ valid: boolean;
217
+ status: 'valid' | 'invalid' | 'indeterminate';
218
+ reason?: string;
219
+ providerSubject?: string;
220
+ expiresAt?: string;
221
+ scopes?: readonly string[];
222
+ metadata?: Record<string, unknown>;
223
+ };
224
+ ```
225
+
226
+ Minimal example:
227
+
228
+ ```ts
229
+ const result = await identity.validateSecret('service-token', {
230
+ async validate(handle) {
231
+ const response = await handle.fetchWithAuth('https://api.example.com/me');
232
+ return {
233
+ valid: response.ok,
234
+ status: response.ok ? 'valid' : 'invalid',
235
+ };
236
+ },
237
+ });
238
+ ```
239
+
240
+ ### 3.8 Generic HTTP Validator
241
+ Use `genericHttpValidator(...)` when a remote service can be probed by a normal authenticated HTTP request and you want a reusable validator without writing custom validator boilerplate.
242
+
243
+ ```ts
244
+ const validator = genericHttpValidator({
245
+ url: 'https://api.example.com/me',
246
+ extractResult: (_response, data: { subject?: string; scopes?: string[] } | undefined) => ({
247
+ providerSubject: data?.subject,
248
+ scopes: data?.scopes,
249
+ }),
250
+ });
251
+
252
+ const result = await identity.validateSecret('service-token', validator);
253
+ ```
254
+
255
+ Supported config fields:
256
+ - `url`
257
+ - `method`
258
+ - `headers`
259
+ - `body`
260
+ - `isValid(response, data)`
261
+ - `classifyStatus(response, data)`
262
+ - `extractResult(response, data)`
263
+
264
+ Default behavior:
265
+ - `2xx` -> `{ valid: true, status: 'valid' }`
266
+ - `401/403` -> `{ valid: false, status: 'invalid', reason: 'http_<status>' }`
267
+ - other non-`2xx` -> `{ valid: false, status: 'indeterminate', reason: 'http_<status>' }`
268
+
163
269
  ---
164
270
 
165
271
  ## 4. Error Code Dictionary
@@ -174,6 +280,7 @@ The SDK uses structured `IdentityError` objects with the following codes:
174
280
  | `SECRET_ALREADY_EXISTS` | `addSecret` used on an existing name. | Use a new name or `update`. |
175
281
  | `SECRET_POLICY_REQUIRED` | Agent rotation attempted without allowed origins. | Set origins in identity code. |
176
282
  | `SECRET_SOURCE_ORIGIN_MISMATCH` | Rotation came from a disallowed origin. | Check secret policy and rotation URL. |
283
+ | `SECRET_OPERATION_RATE_LIMITED` | Local compare/proof/validate operation exceeded the runtime limit window. | Back off, reduce probe frequency, or avoid low-entropy repeated guesses. |
177
284
  | `VAULT_PERSISTENCE_FAILED` | Storage is not writable. | Fix permissions or check storage path. |
178
285
  | `VAULT_FILE_NOT_FOUND` | Expected vault file does not exist. | Initialize identity or check storage key. |
179
286
  | `VAULT_WRITE_INTEGRITY_FAILED` | Save verification failed. | Check disk space/integrity. |
@@ -21,6 +21,23 @@ Do not use this directory for:
21
21
  - [merge-rules.md](./merge-rules.md): vault merge preconditions and conflict behavior
22
22
  - [secret-origin-policy.md](./secret-origin-policy.md): allowed origin policy for acquired and rotated secrets
23
23
  - [activity-log.md](./activity-log.md): local audit event schema and failure semantics
24
+ - [secret-validation.md](./secret-validation.md): local compare/proof semantics and versioning contract for future validator adapters
25
+ - [exposure-surfaces.md](./exposure-surfaces.md): current runtime exposure surfaces, mitigations, and future hardening areas
26
+
27
+ ## Spec Versioning
28
+
29
+ Runtime specs in this directory use:
30
+
31
+ - an integer version number
32
+ - a lifecycle status suffix such as `draft` or `stable`
33
+
34
+ Examples:
35
+
36
+ - `v1-draft`
37
+ - `v1-stable`
38
+ - `v2-draft`
39
+
40
+ This keeps compatibility decisions obvious while the runtime incubates behavior before anything graduates into a broader protocol contract.
24
41
 
25
42
  ## Design Goal
26
43
 
@@ -38,12 +38,16 @@ Current action names:
38
38
  - `fetchWithAuth`
39
39
  - `fetchJsonAndAddSecret`
40
40
  - `fetchJsonAndUpdateSecret`
41
+ - `compareSecret`
42
+ - `proveSecret`
43
+ - `validateSecret`
41
44
 
42
45
  ## Required Semantics
43
46
 
44
47
  1. `fetchWithAuth` success and failure attempts must append an activity entry.
45
48
  2. JSON secret acquisition and rotation success and failure attempts must append an activity entry.
46
49
  3. Direct admin secret mutation such as `addSecret` is not part of this audit stream.
50
+ 4. Local compare/proof/validate attempts should append activity entries without exporting plaintext secret values.
47
51
 
48
52
  ## Failure Semantics
49
53
 
@@ -0,0 +1,99 @@
1
+ # Exposure Surfaces
2
+
3
+ ## Purpose
4
+
5
+ Documents the currently known secret exposure surfaces that still exist even after the runtime removes public plaintext secret export from its supported flows.
6
+
7
+ This document is a runtime security inventory, not a protocol object.
8
+
9
+ ## Current Exposure Surfaces
10
+
11
+ ### 1. Root Initialization Window
12
+
13
+ The root private key may still exist in cleartext during initial generation, import, prompt entry, environment injection, or process startup wiring.
14
+
15
+ This is currently the primary accepted plaintext bootstrap window.
16
+
17
+ ### 2. Runtime Process Memory
18
+
19
+ Secrets still exist in runtime memory while they are being:
20
+
21
+ - acquired
22
+ - used for authenticated requests
23
+ - compared
24
+ - proven
25
+ - validated
26
+
27
+ Memory compromise remains an exposure surface.
28
+
29
+ ### 3. Remote Target Disclosure
30
+
31
+ When the runtime uses a secret against a remote service, that target service necessarily receives the credential or proof material required for the request.
32
+
33
+ Examples:
34
+
35
+ - `fetchWithAuth`
36
+ - `startLocalAuthProxy`
37
+ - provider-backed validation probes
38
+
39
+ ### 4. Local Ingress Channel
40
+
41
+ Local secret ingress reduces terminal exposure, but the local handoff channel still exists.
42
+
43
+ Relevant artifacts include:
44
+
45
+ - loopback listener state
46
+ - one-time ingress token
47
+ - local process boundaries
48
+
49
+ ### 5. Secret Operation Oracles
50
+
51
+ Local KMS-like operations such as compare, proof, and validation are safer than plaintext export, but they still create controlled oracles.
52
+
53
+ Risk examples:
54
+
55
+ - repeated compare attempts against low-entropy values
56
+ - repeated proof generation against attacker-chosen challenges
57
+
58
+ ### 6. Authority-Held Managed Identity Material
59
+
60
+ Authority vaults may still contain managed-agent or child-identity private key material as runtime-internal records.
61
+
62
+ These records are hidden from the public secret namespace, but authority compromise remains a high-impact event.
63
+
64
+ ### 7. Backup and Sealed Export Assets
65
+
66
+ Sealed vault exports are encrypted, but they remain high-value assets. Their security depends on the external key-encryption-key lifecycle.
67
+
68
+ ### 8. User-Supplied Surrounding Code
69
+
70
+ The runtime can avoid plaintext export on its own surfaces, but surrounding application code may still leak:
71
+
72
+ - ingress tokens
73
+ - validation metadata
74
+ - proofs
75
+ - request traces
76
+ - root bootstrap material
77
+
78
+ ## Current Mitigations
79
+
80
+ Implemented mitigations include:
81
+
82
+ - no public plaintext secret retrieval API
83
+ - no public plaintext secret add API
84
+ - direct remote acquisition into vault
85
+ - local secret ingress instead of terminal handoff
86
+ - local compare/proof/validate without plaintext export
87
+ - hidden internal record namespace for managed-agent and revocation records
88
+ - rate limiting for local compare/proof/validate operations
89
+ - audit entries for local compare/proof/validate operations
90
+
91
+ ## Ongoing Hardening Areas
92
+
93
+ Future hardening should focus on:
94
+
95
+ - stronger rate limiting and policy controls for local secret oracles
96
+ - stricter challenge/purpose rules for proof generation
97
+ - tighter handling of authority-held managed identity material
98
+ - guidance and tooling for safer bootstrap of the root private key
99
+ - clearer backup/KDK operational guidance
@@ -0,0 +1,113 @@
1
+ # Secret Validation
2
+
3
+ ## Spec Version
4
+
5
+ - `version`: `1`
6
+ - `status`: `draft`
7
+ - Display form: `v1-draft`
8
+
9
+ This document defines the runtime contract for local secret proof and validation-oriented operations.
10
+
11
+ This is a runtime spec, not a protocol object.
12
+
13
+ ## Purpose
14
+
15
+ Defines how a CBIO runtime may:
16
+
17
+ - prove possession of a secret without exporting it
18
+ - compare a candidate against a stored secret without exporting it
19
+ - evolve toward provider-backed remote validation without changing the core result semantics
20
+
21
+ ## Scope
22
+
23
+ This spec currently covers:
24
+
25
+ - local compare semantics
26
+ - local proof semantics
27
+ - versioning rules for future remote validator adapters
28
+
29
+ This spec does not yet define:
30
+
31
+ - provider-specific validator endpoints
32
+ - cross-network proof exchange formats
33
+ - third-party CBIO-native validation endpoints
34
+
35
+ ## Versioning Rules
36
+
37
+ Runtime secret validation specs use:
38
+
39
+ - an integer `version`
40
+ - a lifecycle `status`
41
+
42
+ Examples:
43
+
44
+ - `v1-draft`
45
+ - `v1-stable`
46
+ - `v2-draft`
47
+
48
+ Rules:
49
+
50
+ 1. Increment the integer version when behavior, required fields, or result semantics change incompatibly.
51
+ 2. Change only the status when the semantics stay the same but implementation confidence changes.
52
+ 3. Do not reuse an older integer version for different semantics.
53
+
54
+ ## Local Compare Semantics
55
+
56
+ `compareSecret(secretName, candidate)` must:
57
+
58
+ 1. return `true` only when the candidate exactly matches the active secret value
59
+ 2. return `false` when the candidate does not match
60
+ 3. fail with `SECRET_NOT_FOUND` when the named secret does not exist
61
+ 4. not return the stored secret value in cleartext
62
+ 5. use a comparison method suitable for secret material
63
+
64
+ ## Local Proof Semantics
65
+
66
+ `proveSecret(secretName, challenge, options?)` must:
67
+
68
+ 1. fail with `SECRET_NOT_FOUND` when the named secret does not exist
69
+ 2. not return the stored secret value in cleartext
70
+ 3. deterministically derive a proof from:
71
+ - the active secret value
72
+ - the provided challenge
73
+ - the selected algorithm
74
+
75
+ ### Defined Algorithms
76
+
77
+ Current algorithm names:
78
+
79
+ - `sha256`
80
+ - `sha512`
81
+
82
+ For `v1-draft`, the proof value is:
83
+
84
+ - `HMAC(algorithm, secretValue, challenge)`
85
+ - encoded as `base64url`
86
+
87
+ ## Permission Semantics
88
+
89
+ Runtime handles must treat local compare/proof operations as secret acquisition-class capabilities.
90
+
91
+ For `v1-draft`:
92
+
93
+ - `CbioIdentity` may invoke these operations
94
+ - `CbioAgent` requires `vault:acquire`
95
+
96
+ ## Forward Compatibility
97
+
98
+ Future versions may add remote validator contracts that return structured validation results such as:
99
+
100
+ - `valid`
101
+ - `reason`
102
+ - `providerSubject`
103
+ - `expiresAt`
104
+ - `scopes`
105
+ - `metadata`
106
+
107
+ Those result objects must be versioned under this spec family rather than silently changing local compare/proof semantics.
108
+
109
+ ## Non-Goals
110
+
111
+ - Defining a cloud KMS protocol
112
+ - Defining provider-specific auth probe behavior
113
+ - Defining how third-party websites must expose validation endpoints
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@the-ai-company/cbio-node-runtime",
3
- "version": "0.32.0",
3
+ "version": "0.39.0",
4
4
  "description": "Node.js runtime for cbio identity and credential vault. Library only, no CLI or TUI.",
5
5
  "type": "module",
6
6
  "main": "./dist/runtime/index.js",
@@ -34,7 +34,7 @@
34
34
  "build": "node ./scripts/clean-dist.mjs && tsc",
35
35
  "prepare": "npm run build",
36
36
  "test": "npm run build && npm run test:acceptance",
37
- "test:acceptance": "node tests/runtime/derivation.js && node tests/runtime/errors.js && node tests/runtime/hardened_vault.js && node tests/runtime/isolation_local.js && node tests/runtime/managed_agent_identity.js && node tests/runtime/merge_security_local.js && node tests/runtime/recursive_cbio.js && node tests/runtime/register_child.js && node tests/runtime/transparency.js && node tests/runtime/vault_resilience.js && node tests/runtime/activity_log.js && node tests/runtime/secret_rotation_policy.js && node tests/runtime/local_auth_proxy.js && node tests/storage/adaptability.js && node tests/runtime/autosave.js"
37
+ "test:acceptance": "node tests/runtime/derivation.js && node tests/runtime/errors.js && node tests/runtime/hardened_vault.js && node tests/runtime/isolation_local.js && node tests/runtime/managed_agent_identity.js && node tests/runtime/merge_security_local.js && node tests/runtime/recursive_cbio.js && node tests/runtime/register_child.js && node tests/runtime/transparency.js && node tests/runtime/vault_resilience.js && node tests/runtime/activity_log.js && node tests/runtime/secret_rotation_policy.js && node tests/runtime/local_auth_proxy.js && node tests/runtime/local_secret_ingress.js && node tests/runtime/local_secret_proof.js && node tests/runtime/local_secret_validate.js && node tests/runtime/generic_secret_validator.js && node tests/runtime/local_secret_guardrails.js && node tests/storage/adaptability.js && node tests/runtime/autosave.js"
38
38
  },
39
39
  "keywords": [
40
40
  "claw-biometric",