@wildo-ai/platform-config-lib 1.1.10 → 1.1.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.
- package/dist/esm/_unimplemented/unimplemented-field-warning.d.ts +1 -1
- package/dist/esm/_unimplemented/unimplemented-field-warning.js +1 -1
- package/dist/esm/_unimplemented/unimplemented-field-warning.js.map +1 -1
- package/dist/esm/blueprint/anchored-region.d.ts +83 -0
- package/dist/esm/blueprint/anchored-region.d.ts.map +1 -0
- package/dist/esm/blueprint/anchored-region.js +263 -0
- package/dist/esm/blueprint/anchored-region.js.map +1 -0
- package/dist/esm/blueprint/blueprint.schemas.d.ts +689 -0
- package/dist/esm/blueprint/blueprint.schemas.d.ts.map +1 -0
- package/dist/esm/blueprint/blueprint.schemas.js +638 -0
- package/dist/esm/blueprint/blueprint.schemas.js.map +1 -0
- package/dist/esm/bootstrap/application-backend-env.contracts.d.ts.map +1 -1
- package/dist/esm/bootstrap/bootstrap-planner.d.ts.map +1 -1
- package/dist/esm/bootstrap/bootstrap.contracts.d.ts +13 -1
- package/dist/esm/bootstrap/bootstrap.contracts.d.ts.map +1 -1
- package/dist/esm/bootstrap/bootstrap.contracts.js +6 -0
- package/dist/esm/bootstrap/bootstrap.contracts.js.map +1 -1
- package/dist/esm/bootstrap/bootstrap.schemas.d.ts +21 -3
- package/dist/esm/bootstrap/bootstrap.schemas.d.ts.map +1 -1
- package/dist/esm/bootstrap/bootstrap.schemas.js +14 -3
- package/dist/esm/bootstrap/bootstrap.schemas.js.map +1 -1
- package/dist/esm/bootstrap/platform-runtime-env.contracts.d.ts +121 -0
- package/dist/esm/bootstrap/platform-runtime-env.contracts.d.ts.map +1 -1
- package/dist/esm/bootstrap/platform-runtime-env.contracts.js +129 -0
- package/dist/esm/bootstrap/platform-runtime-env.contracts.js.map +1 -1
- package/dist/esm/bootstrap/platform-store-preconnect.d.ts.map +1 -1
- package/dist/esm/bootstrap/runtime-backing-service-access.d.ts.map +1 -1
- package/dist/esm/bootstrap/runtime-network-policy.d.ts.map +1 -1
- package/dist/esm/bootstrap/runtime-network-topology.d.ts.map +1 -1
- package/dist/esm/bootstrap/runtime-platform-access.d.ts.map +1 -1
- package/dist/esm/bootstrap/runtime-principal.contracts.d.ts.map +1 -1
- package/dist/esm/bootstrap/runtime-response-integrity.d.ts +249 -0
- package/dist/esm/bootstrap/runtime-response-integrity.d.ts.map +1 -0
- package/dist/esm/bootstrap/runtime-response-integrity.js +353 -0
- package/dist/esm/bootstrap/runtime-response-integrity.js.map +1 -0
- package/dist/esm/bootstrap/runtime-secret-env.contracts.d.ts +32 -0
- package/dist/esm/bootstrap/runtime-secret-env.contracts.d.ts.map +1 -0
- package/dist/esm/bootstrap/runtime-secret-env.contracts.js +43 -0
- package/dist/esm/bootstrap/runtime-secret-env.contracts.js.map +1 -0
- package/dist/esm/bootstrap/runtime-topology.contracts.d.ts.map +1 -1
- package/dist/esm/bootstrap/wildo-owner-organization.contracts.d.ts.map +1 -1
- package/dist/esm/canonical-json/rfc8785-canonical-json.d.ts +51 -0
- package/dist/esm/canonical-json/rfc8785-canonical-json.d.ts.map +1 -0
- package/dist/esm/canonical-json/rfc8785-canonical-json.js +231 -0
- package/dist/esm/canonical-json/rfc8785-canonical-json.js.map +1 -0
- package/dist/esm/config-authoring.entry.d.ts.map +1 -1
- package/dist/esm/index.d.ts +15 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +15 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/key-management/approval-seal-verifier.d.ts +216 -0
- package/dist/esm/key-management/approval-seal-verifier.d.ts.map +1 -0
- package/dist/esm/key-management/approval-seal-verifier.js +233 -0
- package/dist/esm/key-management/approval-seal-verifier.js.map +1 -0
- package/dist/esm/key-management/approval-seal.contracts.d.ts +131 -0
- package/dist/esm/key-management/approval-seal.contracts.d.ts.map +1 -0
- package/dist/esm/key-management/approval-seal.contracts.js +115 -0
- package/dist/esm/key-management/approval-seal.contracts.js.map +1 -0
- package/dist/esm/key-management/data-key.contracts.d.ts +108 -0
- package/dist/esm/key-management/data-key.contracts.d.ts.map +1 -0
- package/dist/esm/key-management/data-key.contracts.js +54 -0
- package/dist/esm/key-management/data-key.contracts.js.map +1 -0
- package/dist/esm/key-management/es256-jws.d.ts +60 -0
- package/dist/esm/key-management/es256-jws.d.ts.map +1 -0
- package/dist/esm/key-management/es256-jws.js +135 -0
- package/dist/esm/key-management/es256-jws.js.map +1 -0
- package/dist/esm/key-management/key-provider.spi.d.ts +151 -0
- package/dist/esm/key-management/key-provider.spi.d.ts.map +1 -0
- package/dist/esm/key-management/key-provider.spi.js +38 -0
- package/dist/esm/key-management/key-provider.spi.js.map +1 -0
- package/dist/esm/key-management/keyring-rotation.contracts.d.ts +93 -0
- package/dist/esm/key-management/keyring-rotation.contracts.d.ts.map +1 -0
- package/dist/esm/key-management/keyring-rotation.contracts.js +101 -0
- package/dist/esm/key-management/keyring-rotation.contracts.js.map +1 -0
- package/dist/esm/key-management/keyring-status.contracts.d.ts +66 -0
- package/dist/esm/key-management/keyring-status.contracts.d.ts.map +1 -0
- package/dist/esm/key-management/keyring-status.contracts.js +45 -0
- package/dist/esm/key-management/keyring-status.contracts.js.map +1 -0
- package/dist/esm/key-management/signature-request.contracts.d.ts +95 -0
- package/dist/esm/key-management/signature-request.contracts.d.ts.map +1 -0
- package/dist/esm/key-management/signature-request.contracts.js +96 -0
- package/dist/esm/key-management/signature-request.contracts.js.map +1 -0
- package/dist/esm/key-management/signing-log-export.contracts.d.ts +216 -0
- package/dist/esm/key-management/signing-log-export.contracts.d.ts.map +1 -0
- package/dist/esm/key-management/signing-log-export.contracts.js +268 -0
- package/dist/esm/key-management/signing-log-export.contracts.js.map +1 -0
- package/dist/esm/key-management/vault-custody.contracts.d.ts +55 -0
- package/dist/esm/key-management/vault-custody.contracts.d.ts.map +1 -0
- package/dist/esm/key-management/vault-custody.contracts.js +88 -0
- package/dist/esm/key-management/vault-custody.contracts.js.map +1 -0
- package/dist/esm/lockfile/file-lock-hold.d.ts.map +1 -1
- package/dist/esm/lockfile/lockfile-io.d.ts +7 -9
- package/dist/esm/lockfile/lockfile-io.d.ts.map +1 -1
- package/dist/esm/lockfile/lockfile-io.js +23 -22
- package/dist/esm/lockfile/lockfile-io.js.map +1 -1
- package/dist/esm/lockfile/materialize-infra-section.d.ts +17 -14
- package/dist/esm/lockfile/materialize-infra-section.d.ts.map +1 -1
- package/dist/esm/lockfile/materialize-infra-section.js +9 -9
- package/dist/esm/lockfile/materialize-infra-section.js.map +1 -1
- package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.d.ts +26 -2
- package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.d.ts.map +1 -1
- package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.js +27 -2
- package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.js.map +1 -1
- package/dist/esm/project-config/application-public-pricing-catalog.loader.d.ts.map +1 -1
- package/dist/esm/project-config/application-public-pricing-catalog.loader.js +9 -2
- package/dist/esm/project-config/application-public-pricing-catalog.loader.js.map +1 -1
- package/dist/esm/project-config/application-served-public-documents.loader.d.ts +26 -0
- package/dist/esm/project-config/application-served-public-documents.loader.d.ts.map +1 -0
- package/dist/esm/project-config/application-served-public-documents.loader.js +78 -0
- package/dist/esm/project-config/application-served-public-documents.loader.js.map +1 -0
- package/dist/esm/project-config/define-framework-config.d.ts.map +1 -1
- package/dist/esm/project-config/define-infra-env-config.d.ts +236 -15
- package/dist/esm/project-config/define-infra-env-config.d.ts.map +1 -1
- package/dist/esm/project-config/define-infra-env-config.js +104 -91
- package/dist/esm/project-config/define-infra-env-config.js.map +1 -1
- package/dist/esm/project-config/define-minion-config.d.ts.map +1 -1
- package/dist/esm/project-config/define-saas-config.d.ts +133 -3
- package/dist/esm/project-config/define-saas-config.d.ts.map +1 -1
- package/dist/esm/project-config/define-saas-config.js +170 -19
- package/dist/esm/project-config/define-saas-config.js.map +1 -1
- package/dist/esm/project-config/define-worker-config.d.ts.map +1 -1
- package/dist/esm/project-config/hosted-infra-env-config.d.ts.map +1 -1
- package/dist/esm/project-config/hosted-infra-env-config.js +3 -0
- package/dist/esm/project-config/hosted-infra-env-config.js.map +1 -1
- package/dist/esm/project-config/index.d.ts +3 -0
- package/dist/esm/project-config/index.d.ts.map +1 -1
- package/dist/esm/project-config/index.js +3 -0
- package/dist/esm/project-config/index.js.map +1 -1
- package/dist/esm/project-config/loader.d.ts.map +1 -1
- package/dist/esm/project-config/npm-version-range.d.ts.map +1 -1
- package/dist/esm/project-config/npm-version-range.js +39 -16
- package/dist/esm/project-config/npm-version-range.js.map +1 -1
- package/dist/esm/project-config/owning-package-tsconfig.d.ts +15 -0
- package/dist/esm/project-config/owning-package-tsconfig.d.ts.map +1 -0
- package/dist/esm/project-config/owning-package-tsconfig.js +29 -0
- package/dist/esm/project-config/owning-package-tsconfig.js.map +1 -0
- package/dist/esm/project-config/provider-catalog-types.d.ts.map +1 -1
- package/dist/esm/project-config/provider-companion-discovery.d.ts +4 -4
- package/dist/esm/project-config/provider-companion-discovery.d.ts.map +1 -1
- package/dist/esm/project-config/provider-companion-discovery.js +13 -9
- package/dist/esm/project-config/provider-companion-discovery.js.map +1 -1
- package/dist/esm/project-config/provider-runtime-artifacts.d.ts +32 -3
- package/dist/esm/project-config/provider-runtime-artifacts.d.ts.map +1 -1
- package/dist/esm/project-config/provider-runtime-artifacts.js +67 -13
- package/dist/esm/project-config/provider-runtime-artifacts.js.map +1 -1
- package/dist/esm/project-config/shared/application-creation-verification.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/application-modules.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/application-modules.utils.d.ts.map +1 -1
- package/dist/esm/project-config/shared/auth.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/backing-service-servability.d.ts.map +1 -1
- package/dist/esm/project-config/shared/backing-services.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/cdn.example.d.ts.map +1 -1
- package/dist/esm/project-config/shared/cdn.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/csp-defaults.d.ts +4 -5
- package/dist/esm/project-config/shared/csp-defaults.d.ts.map +1 -1
- package/dist/esm/project-config/shared/csp-defaults.js +4 -5
- package/dist/esm/project-config/shared/csp-defaults.js.map +1 -1
- package/dist/esm/project-config/shared/csp-emit.d.ts.map +1 -1
- package/dist/esm/project-config/shared/csp.schemas.d.ts +1 -2
- package/dist/esm/project-config/shared/csp.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/csp.schemas.js +1 -2
- package/dist/esm/project-config/shared/csp.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/data-services.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/environment.schemas.d.ts +6 -0
- package/dist/esm/project-config/shared/environment.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/environment.schemas.js +8 -1
- package/dist/esm/project-config/shared/environment.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/infra-providers.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/infra-service.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/infrastructure-defaults.schemas.d.ts +1 -0
- package/dist/esm/project-config/shared/infrastructure-defaults.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/infrastructure-defaults.schemas.js +3 -0
- package/dist/esm/project-config/shared/infrastructure-defaults.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/minion-resource-access.validation.d.ts +4 -0
- package/dist/esm/project-config/shared/minion-resource-access.validation.d.ts.map +1 -1
- package/dist/esm/project-config/shared/minion-resource-access.validation.js +6 -2
- package/dist/esm/project-config/shared/minion-resource-access.validation.js.map +1 -1
- package/dist/esm/project-config/shared/platform-key-management.schemas.d.ts +250 -0
- package/dist/esm/project-config/shared/platform-key-management.schemas.d.ts.map +1 -0
- package/dist/esm/project-config/shared/platform-key-management.schemas.js +194 -0
- package/dist/esm/project-config/shared/platform-key-management.schemas.js.map +1 -0
- package/dist/esm/project-config/shared/platform-services.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/platform-storage.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/schema-version.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/service-definitions.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/systems-of-record-env.schemas.d.ts.map +1 -1
- package/dist/esm/registry/artifact-domain.schemas.d.ts.map +1 -1
- package/dist/esm/registry/digest.schemas.d.ts.map +1 -1
- package/dist/esm/registry/index.d.ts +1 -0
- package/dist/esm/registry/index.d.ts.map +1 -1
- package/dist/esm/registry/index.js +1 -0
- package/dist/esm/registry/index.js.map +1 -1
- package/dist/esm/registry/local-checkout-source.d.ts +22 -2
- package/dist/esm/registry/local-checkout-source.d.ts.map +1 -1
- package/dist/esm/registry/local-checkout-source.js +66 -3
- package/dist/esm/registry/local-checkout-source.js.map +1 -1
- package/dist/esm/registry/lockfile-modules-section.schemas.d.ts +10 -0
- package/dist/esm/registry/lockfile-modules-section.schemas.d.ts.map +1 -1
- package/dist/esm/registry/module-artifact.schemas.d.ts +23 -0
- package/dist/esm/registry/module-artifact.schemas.d.ts.map +1 -1
- package/dist/esm/registry/module-manifest.schemas.d.ts +336 -18
- package/dist/esm/registry/module-manifest.schemas.d.ts.map +1 -1
- package/dist/esm/registry/module-manifest.schemas.js +245 -19
- package/dist/esm/registry/module-manifest.schemas.js.map +1 -1
- package/dist/esm/registry/module-search.schemas.d.ts +2 -0
- package/dist/esm/registry/module-search.schemas.d.ts.map +1 -1
- package/dist/esm/registry/module-search.schemas.js +14 -1
- package/dist/esm/registry/module-search.schemas.js.map +1 -1
- package/dist/esm/registry/registry-config.schemas.d.ts.map +1 -1
- package/dist/esm/registry/registry-errors.d.ts +22 -2
- package/dist/esm/registry/registry-errors.d.ts.map +1 -1
- package/dist/esm/registry/registry-errors.js +28 -2
- package/dist/esm/registry/registry-errors.js.map +1 -1
- package/dist/esm/registry/registry-keys.schemas.d.ts.map +1 -1
- package/dist/esm/registry/registry-section-schemas.constants.d.ts +5 -0
- package/dist/esm/registry/registry-section-schemas.constants.d.ts.map +1 -1
- package/dist/esm/registry/registry-url-resolution.d.ts +72 -0
- package/dist/esm/registry/registry-url-resolution.d.ts.map +1 -0
- package/dist/esm/registry/registry-url-resolution.js +157 -0
- package/dist/esm/registry/registry-url-resolution.js.map +1 -0
- package/dist/esm/schemas/framework-info.schemas.d.ts.map +1 -1
- package/dist/esm/schemas/framework-secrets.schemas.d.ts +55 -0
- package/dist/esm/schemas/framework-secrets.schemas.d.ts.map +1 -1
- package/dist/esm/schemas/framework-secrets.schemas.js +53 -0
- package/dist/esm/schemas/framework-secrets.schemas.js.map +1 -1
- package/dist/esm/schemas/platform-application-config.schemas.d.ts.map +1 -1
- package/dist/esm/schemas/platform-application-secrets.schemas.d.ts.map +1 -1
- package/dist/esm/schemas/platform-config.schemas.d.ts.map +1 -1
- package/dist/esm/workspace-scope/application-subject-manifest.d.ts.map +1 -1
- package/dist/esm/workspace-scope/index.d.ts.map +1 -1
- package/package.json +7 -7
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import { createHash, createPrivateKey, createPublicKey, randomBytes, sign as signWithKey, verify as verifyWithKey, } from 'node:crypto';
|
|
2
|
+
import { PlatformApplicationType } from '@wildo-ai/platform-core-shared';
|
|
3
|
+
import { singleJwsTypeOf, CryptoKey_Purpose } from '@wildo-ai/saas-models';
|
|
4
|
+
import { canonicalizeJson } from '../canonical-json/rfc8785-canonical-json.js';
|
|
5
|
+
import { base64url, ES256_JWS_ALGORITHM, isP256PublicJwk, p256JwkThumbprint, p256PublicJwkOf } from '../key-management/es256-jws.js';
|
|
6
|
+
import { buildRuntimePrincipalKey } from './runtime-principal.contracts.js';
|
|
7
|
+
/**
|
|
8
|
+
* Integrity of what apps-manager tells an application runtime (#2921) and a platform service (#2898).
|
|
9
|
+
*
|
|
10
|
+
* A platform service (crontabs, module-registry) is held to the same contract with the same key: its audience is its
|
|
11
|
+
* own platform application (`SERVICE_NAME`, the record the request authenticated against) and the backend principal,
|
|
12
|
+
* and the route binding keeps an answer on one plane (`platform-services-to-manager`) from standing in for the other
|
|
13
|
+
* (`apps-to-manager`).
|
|
14
|
+
*
|
|
15
|
+
* An application runtime (backend, minion, worker, development companion) learns its configuration, its secrets, its
|
|
16
|
+
* worker bootstrap, its storage session and its runtime-principal tokens from apps-manager, over HTTP. Before this
|
|
17
|
+
* contract it verified none of it: anything that could answer on `PLATFORM_APPS_MANAGER_URL` (a wrong DNS answer, a
|
|
18
|
+
* plain-HTTP hop, an impostor service) could hand a runtime a configuration and secrets of its choosing.
|
|
19
|
+
*
|
|
20
|
+
* ## The contract
|
|
21
|
+
*
|
|
22
|
+
* - **apps-manager signs every successful response** on the runtime-facing routes with its RESPONSE key, a key used for
|
|
23
|
+
* nothing else (not the key that signs runtime-principal tokens or crontabs requests: one key per purpose, NIST SP
|
|
24
|
+
* 800-57 Part 1 Rev 5 §5.2). The signature travels in {@link RUNTIME_RESPONSE_SIGNATURE_HEADER}.
|
|
25
|
+
* - **The signature is a compact JWS** (RFC 7515) with `alg: ES256`, `typ: wildo-runtime-response+jws` and a `kid`
|
|
26
|
+
* that is the RFC 7638 thumbprint of the signing key. Its claims bind:
|
|
27
|
+
* - `bodyDigest`: SHA-256 over the RFC 8785 (JCS) serialization of the body as sent (`canonicalizeJson`). The signer
|
|
28
|
+
* digests the exact text it sends, parsed back, so a `Date` or an `undefined` in the handler's object cannot make
|
|
29
|
+
* the two sides digest different values. RFC 8785 rather than a sorted `JSON.stringify`: the latter drops a
|
|
30
|
+
* `"__proto__"` member (so one could be added to a signed body undetected) and orders integer-like keys the
|
|
31
|
+
* JavaScript way, which no verifier in another language reproduces;
|
|
32
|
+
* - `aud`: the application id and the runtime principal the request authenticated as;
|
|
33
|
+
* - `nonce`: echoed from {@link RUNTIME_RESPONSE_NONCE_HEADER}, which the runtime generates fresh for every request.
|
|
34
|
+
* Replay protection rests on this nonce and on a short lifetime, never on a version a freshly booted runtime
|
|
35
|
+
* cannot remember;
|
|
36
|
+
* - `htm` / `htu`: the request's method and its apps-to-manager route (the DPoP pattern, RFC 9449 §4.2), so a
|
|
37
|
+
* genuine answer from one route cannot stand in for another under the same nonce;
|
|
38
|
+
* - `iat` / `exp`: a {@link RUNTIME_RESPONSE_SIGNATURE_LIFETIME_SECONDS}-second window.
|
|
39
|
+
* - **Runtimes verify, fail-closed**, against up to {@link RUNTIME_RESPONSE_MAX_VERIFICATION_KEYS} public keys (current
|
|
40
|
+
* and next) carried in their environment as a one-line JWKS, so the response key can rotate without a flag day.
|
|
41
|
+
*
|
|
42
|
+
* ## Its key purpose (#2891)
|
|
43
|
+
*
|
|
44
|
+
* The response key is the {@link RUNTIME_RESPONSE_KEY_PURPOSE} key: platform-scoped, held by apps-manager alone, used for
|
|
45
|
+
* nothing else, and requested by nobody (its descriptor's `heldBy` and `mayRequestSignature` are empty). Its `typ`,
|
|
46
|
+
* algorithm and cryptoperiod are the purpose's. Its versions are the two the runtimes accept, current and next, which
|
|
47
|
+
* is the purpose's ACTIVE and NEXT.
|
|
48
|
+
*
|
|
49
|
+
* It stays in apps-manager's environment rather than in the platform keyring, deliberately: a runtime has to hold the
|
|
50
|
+
* verification keys BEFORE it can trust anything apps-manager says, so they reach it out of band, in its environment,
|
|
51
|
+
* and so does the signing half. A keyring version would be announced over the very channel the key authenticates.
|
|
52
|
+
*
|
|
53
|
+
* ## What this protects, stated
|
|
54
|
+
*
|
|
55
|
+
* The network path and an impostor apps-manager. NOT the host: the host supplies each runtime's environment, so it
|
|
56
|
+
* supplies the verification keys too.
|
|
57
|
+
*
|
|
58
|
+
* ## Why not a library
|
|
59
|
+
*
|
|
60
|
+
* ES256 over a compact JWS is a few lines of `node:crypto` (`dsaEncoding: 'ieee-p1363'` gives the raw r‖s form RFC 7518
|
|
61
|
+
* §3.4 requires). Every party here already runs Node, and the verifier must load in the dependency-light worker
|
|
62
|
+
* runtime, so taking no JOSE dependency keeps one implementation on both sides.
|
|
63
|
+
*/
|
|
64
|
+
/** The key purpose that signs runtime responses (#2891): the response key is used for nothing else. */
|
|
65
|
+
export const RUNTIME_RESPONSE_KEY_PURPOSE = CryptoKey_Purpose.PLATFORM_RESPONSE_INTEGRITY;
|
|
66
|
+
/**
|
|
67
|
+
* The JWS `typ`, so a response signature can never be mistaken for any other JWS the platform issues (RFC 8725 §3.11):
|
|
68
|
+
* the response purpose's, from its descriptor, distinct from every other purpose's.
|
|
69
|
+
*/
|
|
70
|
+
export const RUNTIME_RESPONSE_JWS_TYPE = singleJwsTypeOf(RUNTIME_RESPONSE_KEY_PURPOSE);
|
|
71
|
+
/** The only algorithm accepted, pinned rather than read from the header (RFC 8725 §3.1): the purpose's ES256. */
|
|
72
|
+
export const RUNTIME_RESPONSE_JWS_ALGORITHM = ES256_JWS_ALGORITHM;
|
|
73
|
+
/** The issuer every response signature carries: apps-manager. */
|
|
74
|
+
export const RUNTIME_RESPONSE_ISSUER = PlatformApplicationType.PLATFORM_APPS_MANAGER;
|
|
75
|
+
/** Response header carrying the compact JWS. */
|
|
76
|
+
export const RUNTIME_RESPONSE_SIGNATURE_HEADER = 'x-wildo-response-signature';
|
|
77
|
+
/** Request header carrying the runtime's fresh nonce, echoed into the signature's `nonce` claim. */
|
|
78
|
+
export const RUNTIME_RESPONSE_NONCE_HEADER = 'x-wildo-response-nonce';
|
|
79
|
+
/**
|
|
80
|
+
* How long a response signature is valid. It only needs to cover one round trip plus clock skew: the nonce is what
|
|
81
|
+
* stops a replay, and the window bounds how long a captured response is worth anything at all.
|
|
82
|
+
*/
|
|
83
|
+
export const RUNTIME_RESPONSE_SIGNATURE_LIFETIME_SECONDS = 60;
|
|
84
|
+
/** Tolerated clock difference between apps-manager and a runtime, in both directions. */
|
|
85
|
+
export const RUNTIME_RESPONSE_CLOCK_SKEW_SECONDS = 30;
|
|
86
|
+
/** Random bytes in a nonce (256 bits, base64url-encoded). */
|
|
87
|
+
export const RUNTIME_RESPONSE_NONCE_BYTES = 32;
|
|
88
|
+
/** Current and next: a runtime accepts at most two response keys, so the key can rotate without a flag day. */
|
|
89
|
+
export const RUNTIME_RESPONSE_MAX_VERIFICATION_KEYS = 2;
|
|
90
|
+
/**
|
|
91
|
+
* Why a response was refused. A closed vocabulary so a log, a test or an alert can branch on the reason rather than on
|
|
92
|
+
* an English message.
|
|
93
|
+
*/
|
|
94
|
+
export var RuntimeResponseVerificationFailure;
|
|
95
|
+
(function (RuntimeResponseVerificationFailure) {
|
|
96
|
+
/** No signature header on a successful response. */
|
|
97
|
+
RuntimeResponseVerificationFailure["MISSING_SIGNATURE"] = "missing_signature";
|
|
98
|
+
/** The header is not a three-part compact JWS, or a part does not decode. */
|
|
99
|
+
RuntimeResponseVerificationFailure["MALFORMED_SIGNATURE"] = "malformed_signature";
|
|
100
|
+
/** The JWS `typ` is not {@link RUNTIME_RESPONSE_JWS_TYPE}. */
|
|
101
|
+
RuntimeResponseVerificationFailure["WRONG_TYPE"] = "wrong_type";
|
|
102
|
+
/** The JWS `alg` is not {@link RUNTIME_RESPONSE_JWS_ALGORITHM}. */
|
|
103
|
+
RuntimeResponseVerificationFailure["UNSUPPORTED_ALGORITHM"] = "unsupported_algorithm";
|
|
104
|
+
/** The `kid` names no key the runtime holds. */
|
|
105
|
+
RuntimeResponseVerificationFailure["UNKNOWN_KEY"] = "unknown_key";
|
|
106
|
+
/** The signature does not verify under the named key. */
|
|
107
|
+
RuntimeResponseVerificationFailure["BAD_SIGNATURE"] = "bad_signature";
|
|
108
|
+
/** The issuer is not apps-manager. */
|
|
109
|
+
RuntimeResponseVerificationFailure["WRONG_ISSUER"] = "wrong_issuer";
|
|
110
|
+
/** The audience names another application or another runtime principal. */
|
|
111
|
+
RuntimeResponseVerificationFailure["WRONG_AUDIENCE"] = "wrong_audience";
|
|
112
|
+
/** The echoed nonce is not the one this request sent. */
|
|
113
|
+
RuntimeResponseVerificationFailure["NONCE_MISMATCH"] = "nonce_mismatch";
|
|
114
|
+
/** The response answers another method or route than the one this request used. */
|
|
115
|
+
RuntimeResponseVerificationFailure["WRONG_REQUEST"] = "wrong_request";
|
|
116
|
+
/** Past `exp` (beyond the skew tolerance). */
|
|
117
|
+
RuntimeResponseVerificationFailure["EXPIRED"] = "expired";
|
|
118
|
+
/** `iat` is in the future (beyond the skew tolerance). */
|
|
119
|
+
RuntimeResponseVerificationFailure["NOT_YET_VALID"] = "not_yet_valid";
|
|
120
|
+
/** The body received is not the body that was signed. */
|
|
121
|
+
RuntimeResponseVerificationFailure["BODY_MISMATCH"] = "body_mismatch";
|
|
122
|
+
})(RuntimeResponseVerificationFailure || (RuntimeResponseVerificationFailure = {}));
|
|
123
|
+
/** Thrown by {@link verifyRuntimeResponse}; `failure` is the branchable reason. */
|
|
124
|
+
export class RuntimeResponseVerificationError extends Error {
|
|
125
|
+
failure;
|
|
126
|
+
constructor(failure, message) {
|
|
127
|
+
super(`apps-manager response refused (${failure}): ${message}`);
|
|
128
|
+
this.name = 'RuntimeResponseVerificationError';
|
|
129
|
+
this.failure = failure;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Whether a caught value is a {@link RuntimeResponseVerificationError}. Decided by name and reason rather than
|
|
134
|
+
* `instanceof`, because a runtime can load two copies of this package (an application's injected snapshot beside the
|
|
135
|
+
* engine's), and a refusal thrown by one copy must still be recognised by code holding the other.
|
|
136
|
+
*/
|
|
137
|
+
export function isRuntimeResponseVerificationError(value) {
|
|
138
|
+
if (value instanceof RuntimeResponseVerificationError)
|
|
139
|
+
return true;
|
|
140
|
+
if (!(value instanceof Error) || value.name !== 'RuntimeResponseVerificationError')
|
|
141
|
+
return false;
|
|
142
|
+
const failure = value.failure;
|
|
143
|
+
return Object.values(RuntimeResponseVerificationFailure).includes(failure);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* The route a request is bound to: its path without query and without a leading API mount prefix (`/api/v1`). apps-manager
|
|
147
|
+
* serves its runtime-facing and platform-facing routes both at the root and under that prefix, and a caller may use
|
|
148
|
+
* either, so both sides derive the route from the URL they actually used and drop the prefix before comparing.
|
|
149
|
+
*
|
|
150
|
+
* Only that prefix is dropped, so `PLATFORM_APPS_MANAGER_URL` must name the service's ROOT (`http(s)://host[:port]`, as
|
|
151
|
+
* every generated address does). A URL carrying a path prefix that a reverse proxy strips would bind a different route
|
|
152
|
+
* on each side and be refused as `wrong_request`.
|
|
153
|
+
*/
|
|
154
|
+
export function runtimeResponseRouteOf(urlOrPath) {
|
|
155
|
+
const pathname = urlOrPath.includes('://') ? new URL(urlOrPath).pathname : (urlOrPath.split('?')[0] ?? '');
|
|
156
|
+
return pathname.replace(/^\/api\/v\d+(?=\/)/, '');
|
|
157
|
+
}
|
|
158
|
+
/** RFC 7638 thumbprint of a P-256 public key (the shared implementation, `p256JwkThumbprint`). */
|
|
159
|
+
export function runtimeResponseKeyThumbprint(jwk) {
|
|
160
|
+
return p256JwkThumbprint(jwk);
|
|
161
|
+
}
|
|
162
|
+
function publicJwkOf(key) {
|
|
163
|
+
try {
|
|
164
|
+
return p256PublicJwkOf(key);
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
throw new Error('The apps-manager response key must be an EC P-256 key.');
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Digest of a JSON value as it travels: SHA-256 over its canonical serialization, base64url-encoded.
|
|
172
|
+
*
|
|
173
|
+
* Takes the PARSED value. The signer passes `JSON.parse` of the exact text it sends; the verifier passes the body it
|
|
174
|
+
* parsed. Both therefore digest the same JSON value, whatever the handler's object held before serialization.
|
|
175
|
+
*/
|
|
176
|
+
export function runtimeResponseBodyDigest(body) {
|
|
177
|
+
return base64url(createHash('sha256').update(canonicalizeJson(body)).digest());
|
|
178
|
+
}
|
|
179
|
+
/** A fresh nonce for one request. */
|
|
180
|
+
export function createRuntimeResponseNonce() {
|
|
181
|
+
return base64url(randomBytes(RUNTIME_RESPONSE_NONCE_BYTES));
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Build the environment value that carries a runtime's verification keys: a one-line JWKS of up to two public keys
|
|
185
|
+
* (current first, then next).
|
|
186
|
+
*
|
|
187
|
+
* A JWKS rather than PEM because a PEM is multi-line, and multi-line values are where `.env` files and orchestrators
|
|
188
|
+
* disagree. Used by every lane's environment builder, so the format has one producer.
|
|
189
|
+
*/
|
|
190
|
+
export function buildRuntimeResponseVerificationKeySet(publicKeyPems) {
|
|
191
|
+
const keys = publicKeyPems.filter((pem) => pem.trim().length > 0);
|
|
192
|
+
if (keys.length === 0 || keys.length > RUNTIME_RESPONSE_MAX_VERIFICATION_KEYS) {
|
|
193
|
+
throw new Error(`A runtime takes one or ${RUNTIME_RESPONSE_MAX_VERIFICATION_KEYS} apps-manager response keys (current, then next); got ${keys.length}.`);
|
|
194
|
+
}
|
|
195
|
+
return JSON.stringify({
|
|
196
|
+
keys: keys.map((pem) => {
|
|
197
|
+
const jwk = publicJwkOf(createPublicKey(pem));
|
|
198
|
+
return { ...jwk, kid: runtimeResponseKeyThumbprint(jwk), alg: RUNTIME_RESPONSE_JWS_ALGORITHM, use: 'sig' };
|
|
199
|
+
}),
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Parse the environment value {@link buildRuntimeResponseVerificationKeySet} produced.
|
|
204
|
+
*
|
|
205
|
+
* Throws on anything other than one or two EC P-256 public keys, and on a `kid` that is not the key's own thumbprint:
|
|
206
|
+
* the thumbprint is recomputed, never trusted, so a key cannot be filed under another key's id.
|
|
207
|
+
*/
|
|
208
|
+
export function parseRuntimeResponseVerificationKeySet(value) {
|
|
209
|
+
let parsed;
|
|
210
|
+
try {
|
|
211
|
+
parsed = JSON.parse(value);
|
|
212
|
+
}
|
|
213
|
+
catch {
|
|
214
|
+
throw new Error('The apps-manager response verification keys are not valid JSON.');
|
|
215
|
+
}
|
|
216
|
+
const keys = parsed?.keys;
|
|
217
|
+
if (!Array.isArray(keys) || keys.length === 0 || keys.length > RUNTIME_RESPONSE_MAX_VERIFICATION_KEYS) {
|
|
218
|
+
throw new Error(`The apps-manager response verification keys must be a JWKS of one or ${RUNTIME_RESPONSE_MAX_VERIFICATION_KEYS} keys.`);
|
|
219
|
+
}
|
|
220
|
+
return keys.map((candidate) => {
|
|
221
|
+
if (!isP256PublicJwk(candidate)) {
|
|
222
|
+
throw new Error('Every apps-manager response verification key must be an EC P-256 public key.');
|
|
223
|
+
}
|
|
224
|
+
const kid = runtimeResponseKeyThumbprint(candidate);
|
|
225
|
+
const declaredKid = candidate.kid;
|
|
226
|
+
if (declaredKid !== undefined && declaredKid !== kid) {
|
|
227
|
+
throw new Error('An apps-manager response verification key is filed under a kid that is not its own thumbprint.');
|
|
228
|
+
}
|
|
229
|
+
const key = createPublicKey({ key: { kty: 'EC', crv: 'P-256', x: candidate.x, y: candidate.y }, format: 'jwk' });
|
|
230
|
+
return { kid, key };
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Why a response signing key cannot be used with a published key set, or `null` when it can.
|
|
235
|
+
*
|
|
236
|
+
* apps-manager calls this at startup: a signing key that runtimes do not hold makes every runtime refuse every answer,
|
|
237
|
+
* and that is far cheaper to refuse once, at apps-manager's boot, naming the remedy, than in every runtime.
|
|
238
|
+
*/
|
|
239
|
+
export function describeRuntimeResponseSigningKeyMismatch(privateKeyPem, verificationKeySet) {
|
|
240
|
+
let kid;
|
|
241
|
+
try {
|
|
242
|
+
kid = runtimeResponseKeyThumbprint(publicJwkOf(createPublicKey(createPrivateKey(privateKeyPem.trim()))));
|
|
243
|
+
}
|
|
244
|
+
catch (error) {
|
|
245
|
+
return `the response signing key does not parse as an EC P-256 private key (${error instanceof Error ? error.message : String(error)})`;
|
|
246
|
+
}
|
|
247
|
+
let published;
|
|
248
|
+
try {
|
|
249
|
+
published = parseRuntimeResponseVerificationKeySet(verificationKeySet);
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
return error instanceof Error ? error.message : String(error);
|
|
253
|
+
}
|
|
254
|
+
return published.some((key) => key.kid === kid)
|
|
255
|
+
? null
|
|
256
|
+
: 'the response signing key is not in the published verification key set, so every application runtime would refuse every answer';
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Sign one response. Throws rather than returning nothing: a response that cannot be signed must not be sent.
|
|
260
|
+
*/
|
|
261
|
+
export function signRuntimeResponse(input) {
|
|
262
|
+
const privateKey = createPrivateKey(input.privateKeyPem.trim());
|
|
263
|
+
const publicJwk = publicJwkOf(createPublicKey(privateKey));
|
|
264
|
+
const iat = input.nowSeconds ?? Math.floor(Date.now() / 1000);
|
|
265
|
+
const header = { alg: RUNTIME_RESPONSE_JWS_ALGORITHM, typ: RUNTIME_RESPONSE_JWS_TYPE, kid: runtimeResponseKeyThumbprint(publicJwk) };
|
|
266
|
+
const claims = {
|
|
267
|
+
iss: RUNTIME_RESPONSE_ISSUER,
|
|
268
|
+
aud: { application: input.application, principal: buildRuntimePrincipalKey(input.principal) },
|
|
269
|
+
nonce: input.nonce,
|
|
270
|
+
bodyDigest: runtimeResponseBodyDigest(JSON.parse(input.bodyText)),
|
|
271
|
+
htm: input.request.method.toUpperCase(),
|
|
272
|
+
htu: runtimeResponseRouteOf(input.request.url),
|
|
273
|
+
iat,
|
|
274
|
+
exp: iat + RUNTIME_RESPONSE_SIGNATURE_LIFETIME_SECONDS,
|
|
275
|
+
};
|
|
276
|
+
const signingInput = `${base64url(JSON.stringify(header))}.${base64url(JSON.stringify(claims))}`;
|
|
277
|
+
const signature = signWithKey('sha256', Buffer.from(signingInput), { key: privateKey, dsaEncoding: 'ieee-p1363' });
|
|
278
|
+
return `${signingInput}.${base64url(signature)}`;
|
|
279
|
+
}
|
|
280
|
+
function decodeSegment(segment) {
|
|
281
|
+
try {
|
|
282
|
+
const value = JSON.parse(Buffer.from(segment, 'base64url').toString('utf8'));
|
|
283
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
284
|
+
throw new Error('not an object');
|
|
285
|
+
return value;
|
|
286
|
+
}
|
|
287
|
+
catch {
|
|
288
|
+
throw new RuntimeResponseVerificationError(RuntimeResponseVerificationFailure.MALFORMED_SIGNATURE, 'a JWS segment does not decode to a JSON object');
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Verify one response, fail-closed. Returns the verified claims; throws {@link RuntimeResponseVerificationError}
|
|
293
|
+
* otherwise. The header's `alg` and `typ` are checked against pinned values and never used to choose an algorithm.
|
|
294
|
+
*/
|
|
295
|
+
// assurance-control: WILDO.SECRETS.CONTRACT_INTEGRITY — a runtime trusts no configuration or secret apps-manager did not sign for it, for this request (#2921)
|
|
296
|
+
export function verifyRuntimeResponse(input) {
|
|
297
|
+
const { signature } = input;
|
|
298
|
+
if (!signature) {
|
|
299
|
+
throw new RuntimeResponseVerificationError(RuntimeResponseVerificationFailure.MISSING_SIGNATURE, 'the response carries no signature');
|
|
300
|
+
}
|
|
301
|
+
const parts = signature.split('.');
|
|
302
|
+
if (parts.length !== 3 || parts.some((part) => part.length === 0)) {
|
|
303
|
+
throw new RuntimeResponseVerificationError(RuntimeResponseVerificationFailure.MALFORMED_SIGNATURE, 'not a compact JWS');
|
|
304
|
+
}
|
|
305
|
+
const [encodedHeader, encodedClaims, encodedSignature] = parts;
|
|
306
|
+
const header = decodeSegment(encodedHeader);
|
|
307
|
+
if (header.typ !== RUNTIME_RESPONSE_JWS_TYPE) {
|
|
308
|
+
throw new RuntimeResponseVerificationError(RuntimeResponseVerificationFailure.WRONG_TYPE, `typ is ${String(header.typ)}`);
|
|
309
|
+
}
|
|
310
|
+
if (header.alg !== RUNTIME_RESPONSE_JWS_ALGORITHM) {
|
|
311
|
+
throw new RuntimeResponseVerificationError(RuntimeResponseVerificationFailure.UNSUPPORTED_ALGORITHM, `alg is ${String(header.alg)}`);
|
|
312
|
+
}
|
|
313
|
+
const verificationKey = input.keys.find((candidate) => candidate.kid === header.kid);
|
|
314
|
+
if (!verificationKey) {
|
|
315
|
+
throw new RuntimeResponseVerificationError(RuntimeResponseVerificationFailure.UNKNOWN_KEY, `no verification key has kid ${String(header.kid)}`);
|
|
316
|
+
}
|
|
317
|
+
const verified = verifyWithKey('sha256', Buffer.from(`${encodedHeader}.${encodedClaims}`), { key: verificationKey.key, dsaEncoding: 'ieee-p1363' }, Buffer.from(encodedSignature, 'base64url'));
|
|
318
|
+
if (!verified) {
|
|
319
|
+
throw new RuntimeResponseVerificationError(RuntimeResponseVerificationFailure.BAD_SIGNATURE, 'the signature does not verify');
|
|
320
|
+
}
|
|
321
|
+
const claims = decodeSegment(encodedClaims);
|
|
322
|
+
if (claims.iss !== RUNTIME_RESPONSE_ISSUER) {
|
|
323
|
+
throw new RuntimeResponseVerificationError(RuntimeResponseVerificationFailure.WRONG_ISSUER, `iss is ${String(claims.iss)}`);
|
|
324
|
+
}
|
|
325
|
+
const audience = claims.aud;
|
|
326
|
+
if (!audience || audience.application !== input.application) {
|
|
327
|
+
throw new RuntimeResponseVerificationError(RuntimeResponseVerificationFailure.WRONG_AUDIENCE, 'the response is for another application');
|
|
328
|
+
}
|
|
329
|
+
if (input.principal && audience.principal !== buildRuntimePrincipalKey(input.principal)) {
|
|
330
|
+
throw new RuntimeResponseVerificationError(RuntimeResponseVerificationFailure.WRONG_AUDIENCE, 'the response is for another runtime principal');
|
|
331
|
+
}
|
|
332
|
+
if (claims.nonce !== input.nonce) {
|
|
333
|
+
throw new RuntimeResponseVerificationError(RuntimeResponseVerificationFailure.NONCE_MISMATCH, 'the response does not echo this request\'s nonce');
|
|
334
|
+
}
|
|
335
|
+
if (claims.htm !== input.request.method.toUpperCase() || claims.htu !== runtimeResponseRouteOf(input.request.url)) {
|
|
336
|
+
throw new RuntimeResponseVerificationError(RuntimeResponseVerificationFailure.WRONG_REQUEST, 'the response answers another request');
|
|
337
|
+
}
|
|
338
|
+
const now = input.nowSeconds ?? Math.floor(Date.now() / 1000);
|
|
339
|
+
if (typeof claims.iat !== 'number' || typeof claims.exp !== 'number') {
|
|
340
|
+
throw new RuntimeResponseVerificationError(RuntimeResponseVerificationFailure.MALFORMED_SIGNATURE, 'iat and exp must be numbers');
|
|
341
|
+
}
|
|
342
|
+
if (claims.iat > now + RUNTIME_RESPONSE_CLOCK_SKEW_SECONDS) {
|
|
343
|
+
throw new RuntimeResponseVerificationError(RuntimeResponseVerificationFailure.NOT_YET_VALID, 'iat is in the future');
|
|
344
|
+
}
|
|
345
|
+
if (claims.exp < now - RUNTIME_RESPONSE_CLOCK_SKEW_SECONDS) {
|
|
346
|
+
throw new RuntimeResponseVerificationError(RuntimeResponseVerificationFailure.EXPIRED, 'the signature has expired');
|
|
347
|
+
}
|
|
348
|
+
if (claims.bodyDigest !== runtimeResponseBodyDigest(input.body)) {
|
|
349
|
+
throw new RuntimeResponseVerificationError(RuntimeResponseVerificationFailure.BODY_MISMATCH, 'the body is not the one that was signed');
|
|
350
|
+
}
|
|
351
|
+
return claims;
|
|
352
|
+
}
|
|
353
|
+
//# sourceMappingURL=runtime-response-integrity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-response-integrity.js","sourceRoot":"","sources":["../../../../src/bootstrap/runtime-response-integrity.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,IAAI,IAAI,WAAW,EACnB,MAAM,IAAI,aAAa,GAExB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,eAAe,EAAE,iBAAiB,EAAE,eAAe,EAAsB,MAAM,6BAA6B,CAAC;AACtJ,OAAO,EAAE,wBAAwB,EAAoC,MAAM,+BAA+B,CAAC;AAE3G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3D,MAAM,IAAI,gCAAgC,CAAC,kCAAkC,CAAC,OAAO,EAAE,2BAA2B,CAAC,CAAC;IACtH,CAAC;IACD,IAAI,MAAM,CAAC,UAAU,KAAK,yBAAyB,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QAChE,MAAM,IAAI,gCAAgC,CAAC,kCAAkC,CAAC,aAAa,EAAE,yCAAyC,CAAC,CAAC;IAC1I,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import {\n createHash,\n createPrivateKey,\n createPublicKey,\n randomBytes,\n sign as signWithKey,\n verify as verifyWithKey,\n type KeyObject,\n} from 'node:crypto';\nimport { PlatformApplicationType } from '@wildo-ai/platform-core-shared';\nimport { singleJwsTypeOf, CryptoKey_Purpose } from '@wildo-ai/saas-models';\nimport { canonicalizeJson } from '../canonical-json/rfc8785-canonical-json';\nimport { base64url, ES256_JWS_ALGORITHM, isP256PublicJwk, p256JwkThumbprint, p256PublicJwkOf, type P256PublicJwk } from '../key-management/es256-jws';\nimport { buildRuntimePrincipalKey, type ApplicationRuntimePrincipal } from './runtime-principal.contracts';\n\n/**\n * Integrity of what apps-manager tells an application runtime (#2921) and a platform service (#2898).\n *\n * A platform service (crontabs, module-registry) is held to the same contract with the same key: its audience is its\n * own platform application (`SERVICE_NAME`, the record the request authenticated against) and the backend principal,\n * and the route binding keeps an answer on one plane (`platform-services-to-manager`) from standing in for the other\n * (`apps-to-manager`).\n *\n * An application runtime (backend, minion, worker, development companion) learns its configuration, its secrets, its\n * worker bootstrap, its storage session and its runtime-principal tokens from apps-manager, over HTTP. Before this\n * contract it verified none of it: anything that could answer on `PLATFORM_APPS_MANAGER_URL` (a wrong DNS answer, a\n * plain-HTTP hop, an impostor service) could hand a runtime a configuration and secrets of its choosing.\n *\n * ## The contract\n *\n * - **apps-manager signs every successful response** on the runtime-facing routes with its RESPONSE key, a key used for\n * nothing else (not the key that signs runtime-principal tokens or crontabs requests: one key per purpose, NIST SP\n * 800-57 Part 1 Rev 5 §5.2). The signature travels in {@link RUNTIME_RESPONSE_SIGNATURE_HEADER}.\n * - **The signature is a compact JWS** (RFC 7515) with `alg: ES256`, `typ: wildo-runtime-response+jws` and a `kid`\n * that is the RFC 7638 thumbprint of the signing key. Its claims bind:\n * - `bodyDigest`: SHA-256 over the RFC 8785 (JCS) serialization of the body as sent (`canonicalizeJson`). The signer\n * digests the exact text it sends, parsed back, so a `Date` or an `undefined` in the handler's object cannot make\n * the two sides digest different values. RFC 8785 rather than a sorted `JSON.stringify`: the latter drops a\n * `\"__proto__\"` member (so one could be added to a signed body undetected) and orders integer-like keys the\n * JavaScript way, which no verifier in another language reproduces;\n * - `aud`: the application id and the runtime principal the request authenticated as;\n * - `nonce`: echoed from {@link RUNTIME_RESPONSE_NONCE_HEADER}, which the runtime generates fresh for every request.\n * Replay protection rests on this nonce and on a short lifetime, never on a version a freshly booted runtime\n * cannot remember;\n * - `htm` / `htu`: the request's method and its apps-to-manager route (the DPoP pattern, RFC 9449 §4.2), so a\n * genuine answer from one route cannot stand in for another under the same nonce;\n * - `iat` / `exp`: a {@link RUNTIME_RESPONSE_SIGNATURE_LIFETIME_SECONDS}-second window.\n * - **Runtimes verify, fail-closed**, against up to {@link RUNTIME_RESPONSE_MAX_VERIFICATION_KEYS} public keys (current\n * and next) carried in their environment as a one-line JWKS, so the response key can rotate without a flag day.\n *\n * ## Its key purpose (#2891)\n *\n * The response key is the {@link RUNTIME_RESPONSE_KEY_PURPOSE} key: platform-scoped, held by apps-manager alone, used for\n * nothing else, and requested by nobody (its descriptor's `heldBy` and `mayRequestSignature` are empty). Its `typ`,\n * algorithm and cryptoperiod are the purpose's. Its versions are the two the runtimes accept, current and next, which\n * is the purpose's ACTIVE and NEXT.\n *\n * It stays in apps-manager's environment rather than in the platform keyring, deliberately: a runtime has to hold the\n * verification keys BEFORE it can trust anything apps-manager says, so they reach it out of band, in its environment,\n * and so does the signing half. A keyring version would be announced over the very channel the key authenticates.\n *\n * ## What this protects, stated\n *\n * The network path and an impostor apps-manager. NOT the host: the host supplies each runtime's environment, so it\n * supplies the verification keys too.\n *\n * ## Why not a library\n *\n * ES256 over a compact JWS is a few lines of `node:crypto` (`dsaEncoding: 'ieee-p1363'` gives the raw r‖s form RFC 7518\n * §3.4 requires). Every party here already runs Node, and the verifier must load in the dependency-light worker\n * runtime, so taking no JOSE dependency keeps one implementation on both sides.\n */\n\n/** The key purpose that signs runtime responses (#2891): the response key is used for nothing else. */\nexport const RUNTIME_RESPONSE_KEY_PURPOSE = CryptoKey_Purpose.PLATFORM_RESPONSE_INTEGRITY;\n\n/**\n * The JWS `typ`, so a response signature can never be mistaken for any other JWS the platform issues (RFC 8725 §3.11):\n * the response purpose's, from its descriptor, distinct from every other purpose's.\n */\nexport const RUNTIME_RESPONSE_JWS_TYPE: string = singleJwsTypeOf(RUNTIME_RESPONSE_KEY_PURPOSE);\n\n/** The only algorithm accepted, pinned rather than read from the header (RFC 8725 §3.1): the purpose's ES256. */\nexport const RUNTIME_RESPONSE_JWS_ALGORITHM = ES256_JWS_ALGORITHM;\n\n/** The issuer every response signature carries: apps-manager. */\nexport const RUNTIME_RESPONSE_ISSUER: string = PlatformApplicationType.PLATFORM_APPS_MANAGER;\n\n/** Response header carrying the compact JWS. */\nexport const RUNTIME_RESPONSE_SIGNATURE_HEADER = 'x-wildo-response-signature';\n\n/** Request header carrying the runtime's fresh nonce, echoed into the signature's `nonce` claim. */\nexport const RUNTIME_RESPONSE_NONCE_HEADER = 'x-wildo-response-nonce';\n\n/**\n * How long a response signature is valid. It only needs to cover one round trip plus clock skew: the nonce is what\n * stops a replay, and the window bounds how long a captured response is worth anything at all.\n */\nexport const RUNTIME_RESPONSE_SIGNATURE_LIFETIME_SECONDS = 60;\n\n/** Tolerated clock difference between apps-manager and a runtime, in both directions. */\nexport const RUNTIME_RESPONSE_CLOCK_SKEW_SECONDS = 30;\n\n/** Random bytes in a nonce (256 bits, base64url-encoded). */\nexport const RUNTIME_RESPONSE_NONCE_BYTES = 32;\n\n/** Current and next: a runtime accepts at most two response keys, so the key can rotate without a flag day. */\nexport const RUNTIME_RESPONSE_MAX_VERIFICATION_KEYS = 2;\n\n/**\n * Why a response was refused. A closed vocabulary so a log, a test or an alert can branch on the reason rather than on\n * an English message.\n */\nexport enum RuntimeResponseVerificationFailure {\n /** No signature header on a successful response. */\n MISSING_SIGNATURE = 'missing_signature',\n /** The header is not a three-part compact JWS, or a part does not decode. */\n MALFORMED_SIGNATURE = 'malformed_signature',\n /** The JWS `typ` is not {@link RUNTIME_RESPONSE_JWS_TYPE}. */\n WRONG_TYPE = 'wrong_type',\n /** The JWS `alg` is not {@link RUNTIME_RESPONSE_JWS_ALGORITHM}. */\n UNSUPPORTED_ALGORITHM = 'unsupported_algorithm',\n /** The `kid` names no key the runtime holds. */\n UNKNOWN_KEY = 'unknown_key',\n /** The signature does not verify under the named key. */\n BAD_SIGNATURE = 'bad_signature',\n /** The issuer is not apps-manager. */\n WRONG_ISSUER = 'wrong_issuer',\n /** The audience names another application or another runtime principal. */\n WRONG_AUDIENCE = 'wrong_audience',\n /** The echoed nonce is not the one this request sent. */\n NONCE_MISMATCH = 'nonce_mismatch',\n /** The response answers another method or route than the one this request used. */\n WRONG_REQUEST = 'wrong_request',\n /** Past `exp` (beyond the skew tolerance). */\n EXPIRED = 'expired',\n /** `iat` is in the future (beyond the skew tolerance). */\n NOT_YET_VALID = 'not_yet_valid',\n /** The body received is not the body that was signed. */\n BODY_MISMATCH = 'body_mismatch',\n}\n\n/** Thrown by {@link verifyRuntimeResponse}; `failure` is the branchable reason. */\nexport class RuntimeResponseVerificationError extends Error {\n readonly failure: RuntimeResponseVerificationFailure;\n\n constructor(failure: RuntimeResponseVerificationFailure, message: string) {\n super(`apps-manager response refused (${failure}): ${message}`);\n this.name = 'RuntimeResponseVerificationError';\n this.failure = failure;\n }\n}\n\n/**\n * Whether a caught value is a {@link RuntimeResponseVerificationError}. Decided by name and reason rather than\n * `instanceof`, because a runtime can load two copies of this package (an application's injected snapshot beside the\n * engine's), and a refusal thrown by one copy must still be recognised by code holding the other.\n */\nexport function isRuntimeResponseVerificationError(value: unknown): value is RuntimeResponseVerificationError {\n if (value instanceof RuntimeResponseVerificationError) return true;\n if (!(value instanceof Error) || value.name !== 'RuntimeResponseVerificationError') return false;\n const failure = (value as { failure?: unknown }).failure;\n return Object.values(RuntimeResponseVerificationFailure).includes(failure as RuntimeResponseVerificationFailure);\n}\n\n/** The audience of a response: which application, and which of its runtime principals, the answer is for. */\nexport interface RuntimeResponseAudience {\n application: string;\n /** {@link buildRuntimePrincipalKey} of the principal the request authenticated as. */\n principal: string;\n}\n\n/**\n * The route a request is bound to: its path without query and without a leading API mount prefix (`/api/v1`). apps-manager\n * serves its runtime-facing and platform-facing routes both at the root and under that prefix, and a caller may use\n * either, so both sides derive the route from the URL they actually used and drop the prefix before comparing.\n *\n * Only that prefix is dropped, so `PLATFORM_APPS_MANAGER_URL` must name the service's ROOT (`http(s)://host[:port]`, as\n * every generated address does). A URL carrying a path prefix that a reverse proxy strips would bind a different route\n * on each side and be refused as `wrong_request`.\n */\nexport function runtimeResponseRouteOf(urlOrPath: string): string {\n const pathname = urlOrPath.includes('://') ? new URL(urlOrPath).pathname : (urlOrPath.split('?')[0] ?? '');\n return pathname.replace(/^\\/api\\/v\\d+(?=\\/)/, '');\n}\n\n/** The request a response answers: its method and its URL (absolute, or a path). */\nexport interface RuntimeResponseRequestBinding {\n method: string;\n url: string;\n}\n\n/** The claims a response signature carries. */\nexport interface RuntimeResponseClaims {\n iss: string;\n aud: RuntimeResponseAudience;\n /** The request's nonce, or `null` when the caller sent none. Every verifying caller sends one, so a verifier always demands it. */\n nonce: string | null;\n /** base64url(SHA-256(canonical body)). */\n bodyDigest: string;\n /** The request's method, upper-cased. */\n htm: string;\n /** The request's route, per {@link runtimeResponseRouteOf}. */\n htu: string;\n iat: number;\n exp: number;\n}\n\n/** One verification key, ready to use. */\nexport interface RuntimeResponseVerificationKey {\n kid: string;\n key: KeyObject;\n}\n\n/** RFC 7638 thumbprint of a P-256 public key (the shared implementation, `p256JwkThumbprint`). */\nexport function runtimeResponseKeyThumbprint(jwk: P256PublicJwk): string {\n return p256JwkThumbprint(jwk);\n}\n\nfunction publicJwkOf(key: KeyObject): P256PublicJwk {\n try {\n return p256PublicJwkOf(key);\n } catch {\n throw new Error('The apps-manager response key must be an EC P-256 key.');\n }\n}\n\n/**\n * Digest of a JSON value as it travels: SHA-256 over its canonical serialization, base64url-encoded.\n *\n * Takes the PARSED value. The signer passes `JSON.parse` of the exact text it sends; the verifier passes the body it\n * parsed. Both therefore digest the same JSON value, whatever the handler's object held before serialization.\n */\nexport function runtimeResponseBodyDigest(body: unknown): string {\n return base64url(createHash('sha256').update(canonicalizeJson(body)).digest());\n}\n\n/** A fresh nonce for one request. */\nexport function createRuntimeResponseNonce(): string {\n return base64url(randomBytes(RUNTIME_RESPONSE_NONCE_BYTES));\n}\n\n/**\n * Build the environment value that carries a runtime's verification keys: a one-line JWKS of up to two public keys\n * (current first, then next).\n *\n * A JWKS rather than PEM because a PEM is multi-line, and multi-line values are where `.env` files and orchestrators\n * disagree. Used by every lane's environment builder, so the format has one producer.\n */\nexport function buildRuntimeResponseVerificationKeySet(publicKeyPems: readonly string[]): string {\n const keys = publicKeyPems.filter((pem) => pem.trim().length > 0);\n if (keys.length === 0 || keys.length > RUNTIME_RESPONSE_MAX_VERIFICATION_KEYS) {\n throw new Error(\n `A runtime takes one or ${RUNTIME_RESPONSE_MAX_VERIFICATION_KEYS} apps-manager response keys (current, then next); got ${keys.length}.`,\n );\n }\n return JSON.stringify({\n keys: keys.map((pem) => {\n const jwk = publicJwkOf(createPublicKey(pem));\n return { ...jwk, kid: runtimeResponseKeyThumbprint(jwk), alg: RUNTIME_RESPONSE_JWS_ALGORITHM, use: 'sig' };\n }),\n });\n}\n\n/**\n * Parse the environment value {@link buildRuntimeResponseVerificationKeySet} produced.\n *\n * Throws on anything other than one or two EC P-256 public keys, and on a `kid` that is not the key's own thumbprint:\n * the thumbprint is recomputed, never trusted, so a key cannot be filed under another key's id.\n */\nexport function parseRuntimeResponseVerificationKeySet(value: string): RuntimeResponseVerificationKey[] {\n let parsed: unknown;\n try {\n parsed = JSON.parse(value);\n } catch {\n throw new Error('The apps-manager response verification keys are not valid JSON.');\n }\n const keys = (parsed as { keys?: unknown } | null)?.keys;\n if (!Array.isArray(keys) || keys.length === 0 || keys.length > RUNTIME_RESPONSE_MAX_VERIFICATION_KEYS) {\n throw new Error(\n `The apps-manager response verification keys must be a JWKS of one or ${RUNTIME_RESPONSE_MAX_VERIFICATION_KEYS} keys.`,\n );\n }\n return keys.map((candidate: unknown) => {\n if (!isP256PublicJwk(candidate)) {\n throw new Error('Every apps-manager response verification key must be an EC P-256 public key.');\n }\n const kid = runtimeResponseKeyThumbprint(candidate);\n const declaredKid = (candidate as { kid?: unknown }).kid;\n if (declaredKid !== undefined && declaredKid !== kid) {\n throw new Error('An apps-manager response verification key is filed under a kid that is not its own thumbprint.');\n }\n const key = createPublicKey({ key: { kty: 'EC', crv: 'P-256', x: candidate.x, y: candidate.y }, format: 'jwk' });\n return { kid, key };\n });\n}\n\n/**\n * Why a response signing key cannot be used with a published key set, or `null` when it can.\n *\n * apps-manager calls this at startup: a signing key that runtimes do not hold makes every runtime refuse every answer,\n * and that is far cheaper to refuse once, at apps-manager's boot, naming the remedy, than in every runtime.\n */\nexport function describeRuntimeResponseSigningKeyMismatch(privateKeyPem: string, verificationKeySet: string): string | null {\n let kid: string;\n try {\n kid = runtimeResponseKeyThumbprint(publicJwkOf(createPublicKey(createPrivateKey(privateKeyPem.trim()))));\n } catch (error) {\n return `the response signing key does not parse as an EC P-256 private key (${error instanceof Error ? error.message : String(error)})`;\n }\n let published: RuntimeResponseVerificationKey[];\n try {\n published = parseRuntimeResponseVerificationKeySet(verificationKeySet);\n } catch (error) {\n return error instanceof Error ? error.message : String(error);\n }\n return published.some((key) => key.kid === kid)\n ? null\n : 'the response signing key is not in the published verification key set, so every application runtime would refuse every answer';\n}\n\n/** What apps-manager needs to sign one response. */\nexport interface SignRuntimeResponseInput {\n /** The response key's private half (PEM, SEC1 or PKCS#8). */\n privateKeyPem: string;\n /** The exact text that will be sent as the body. */\n bodyText: string;\n application: string;\n principal: ApplicationRuntimePrincipal;\n /** The request's {@link RUNTIME_RESPONSE_NONCE_HEADER}, or `null` if it sent none. */\n nonce: string | null;\n /** The request being answered. */\n request: RuntimeResponseRequestBinding;\n /** Seconds since the epoch; injectable for tests. */\n nowSeconds?: number;\n}\n\n/**\n * Sign one response. Throws rather than returning nothing: a response that cannot be signed must not be sent.\n */\nexport function signRuntimeResponse(input: SignRuntimeResponseInput): string {\n const privateKey = createPrivateKey(input.privateKeyPem.trim());\n const publicJwk = publicJwkOf(createPublicKey(privateKey));\n const iat = input.nowSeconds ?? Math.floor(Date.now() / 1000);\n const header = { alg: RUNTIME_RESPONSE_JWS_ALGORITHM, typ: RUNTIME_RESPONSE_JWS_TYPE, kid: runtimeResponseKeyThumbprint(publicJwk) };\n const claims: RuntimeResponseClaims = {\n iss: RUNTIME_RESPONSE_ISSUER,\n aud: { application: input.application, principal: buildRuntimePrincipalKey(input.principal) },\n nonce: input.nonce,\n bodyDigest: runtimeResponseBodyDigest(JSON.parse(input.bodyText)),\n htm: input.request.method.toUpperCase(),\n htu: runtimeResponseRouteOf(input.request.url),\n iat,\n exp: iat + RUNTIME_RESPONSE_SIGNATURE_LIFETIME_SECONDS,\n };\n const signingInput = `${base64url(JSON.stringify(header))}.${base64url(JSON.stringify(claims))}`;\n const signature = signWithKey('sha256', Buffer.from(signingInput), { key: privateKey, dsaEncoding: 'ieee-p1363' });\n return `${signingInput}.${base64url(signature)}`;\n}\n\n/** What a runtime needs to verify one response. */\nexport interface VerifyRuntimeResponseInput {\n /** The {@link RUNTIME_RESPONSE_SIGNATURE_HEADER} value, as received (absent when missing). */\n signature: string | null | undefined;\n /** The body, parsed from JSON. */\n body: unknown;\n keys: readonly RuntimeResponseVerificationKey[];\n /** The runtime's own `APPLICATION_ID`. */\n application: string;\n /**\n * The principal the runtime authenticates as, when it knows it. Omitted only by a caller that cannot know it at that\n * point; the nonce still binds the response to this one request, so a response meant for a sibling cannot be replayed.\n */\n principal?: ApplicationRuntimePrincipal;\n /** The nonce this request sent. */\n nonce: string;\n /** The request this runtime sent. */\n request: RuntimeResponseRequestBinding;\n nowSeconds?: number;\n}\n\nfunction decodeSegment(segment: string): Record<string, unknown> {\n try {\n const value: unknown = JSON.parse(Buffer.from(segment, 'base64url').toString('utf8'));\n if (!value || typeof value !== 'object' || Array.isArray(value)) throw new Error('not an object');\n return value as Record<string, unknown>;\n } catch {\n throw new RuntimeResponseVerificationError(RuntimeResponseVerificationFailure.MALFORMED_SIGNATURE, 'a JWS segment does not decode to a JSON object');\n }\n}\n\n/**\n * Verify one response, fail-closed. Returns the verified claims; throws {@link RuntimeResponseVerificationError}\n * otherwise. The header's `alg` and `typ` are checked against pinned values and never used to choose an algorithm.\n */\n// assurance-control: WILDO.SECRETS.CONTRACT_INTEGRITY — a runtime trusts no configuration or secret apps-manager did not sign for it, for this request (#2921)\nexport function verifyRuntimeResponse(input: VerifyRuntimeResponseInput): RuntimeResponseClaims {\n const { signature } = input;\n if (!signature) {\n throw new RuntimeResponseVerificationError(RuntimeResponseVerificationFailure.MISSING_SIGNATURE, 'the response carries no signature');\n }\n const parts = signature.split('.');\n if (parts.length !== 3 || parts.some((part) => part.length === 0)) {\n throw new RuntimeResponseVerificationError(RuntimeResponseVerificationFailure.MALFORMED_SIGNATURE, 'not a compact JWS');\n }\n const [encodedHeader, encodedClaims, encodedSignature] = parts as [string, string, string];\n const header = decodeSegment(encodedHeader);\n if (header.typ !== RUNTIME_RESPONSE_JWS_TYPE) {\n throw new RuntimeResponseVerificationError(RuntimeResponseVerificationFailure.WRONG_TYPE, `typ is ${String(header.typ)}`);\n }\n if (header.alg !== RUNTIME_RESPONSE_JWS_ALGORITHM) {\n throw new RuntimeResponseVerificationError(RuntimeResponseVerificationFailure.UNSUPPORTED_ALGORITHM, `alg is ${String(header.alg)}`);\n }\n const verificationKey = input.keys.find((candidate) => candidate.kid === header.kid);\n if (!verificationKey) {\n throw new RuntimeResponseVerificationError(RuntimeResponseVerificationFailure.UNKNOWN_KEY, `no verification key has kid ${String(header.kid)}`);\n }\n const verified = verifyWithKey(\n 'sha256',\n Buffer.from(`${encodedHeader}.${encodedClaims}`),\n { key: verificationKey.key, dsaEncoding: 'ieee-p1363' },\n Buffer.from(encodedSignature, 'base64url'),\n );\n if (!verified) {\n throw new RuntimeResponseVerificationError(RuntimeResponseVerificationFailure.BAD_SIGNATURE, 'the signature does not verify');\n }\n\n const claims = decodeSegment(encodedClaims) as unknown as RuntimeResponseClaims;\n if (claims.iss !== RUNTIME_RESPONSE_ISSUER) {\n throw new RuntimeResponseVerificationError(RuntimeResponseVerificationFailure.WRONG_ISSUER, `iss is ${String(claims.iss)}`);\n }\n const audience = claims.aud as RuntimeResponseAudience | undefined;\n if (!audience || audience.application !== input.application) {\n throw new RuntimeResponseVerificationError(RuntimeResponseVerificationFailure.WRONG_AUDIENCE, 'the response is for another application');\n }\n if (input.principal && audience.principal !== buildRuntimePrincipalKey(input.principal)) {\n throw new RuntimeResponseVerificationError(RuntimeResponseVerificationFailure.WRONG_AUDIENCE, 'the response is for another runtime principal');\n }\n if (claims.nonce !== input.nonce) {\n throw new RuntimeResponseVerificationError(RuntimeResponseVerificationFailure.NONCE_MISMATCH, 'the response does not echo this request\\'s nonce');\n }\n if (claims.htm !== input.request.method.toUpperCase() || claims.htu !== runtimeResponseRouteOf(input.request.url)) {\n throw new RuntimeResponseVerificationError(RuntimeResponseVerificationFailure.WRONG_REQUEST, 'the response answers another request');\n }\n const now = input.nowSeconds ?? Math.floor(Date.now() / 1000);\n if (typeof claims.iat !== 'number' || typeof claims.exp !== 'number') {\n throw new RuntimeResponseVerificationError(RuntimeResponseVerificationFailure.MALFORMED_SIGNATURE, 'iat and exp must be numbers');\n }\n if (claims.iat > now + RUNTIME_RESPONSE_CLOCK_SKEW_SECONDS) {\n throw new RuntimeResponseVerificationError(RuntimeResponseVerificationFailure.NOT_YET_VALID, 'iat is in the future');\n }\n if (claims.exp < now - RUNTIME_RESPONSE_CLOCK_SKEW_SECONDS) {\n throw new RuntimeResponseVerificationError(RuntimeResponseVerificationFailure.EXPIRED, 'the signature has expired');\n }\n if (claims.bodyDigest !== runtimeResponseBodyDigest(input.body)) {\n throw new RuntimeResponseVerificationError(RuntimeResponseVerificationFailure.BODY_MISMATCH, 'the body is not the one that was signed');\n }\n return claims;\n}\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every environment variable a Wildo runtime env contract declares secret: the platform services', the application
|
|
3
|
+
* backend's (minions included, which run on its env) and the application workers'.
|
|
4
|
+
*
|
|
5
|
+
* DERIVED from the three declared sets, never listed here, so a secret a contract adds is in it the day it is added.
|
|
6
|
+
* Its first reader is the coding-agent boundary (#3018), through {@link isRuntimeSecretEnvVarName}: a variable in this
|
|
7
|
+
* set may never be forwarded into an agent's subprocess (`inheritedEnvironmentVariables`), because the process that
|
|
8
|
+
* spawns the agent holds it.
|
|
9
|
+
*
|
|
10
|
+
* What it does NOT hold, and why that is not a gap: the variables a backing-service CONTAINER reads its credentials
|
|
11
|
+
* from (`MONGO_INITDB_ROOT_PASSWORD`, `RABBITMQ_ERLANG_COOKIE`, ...). They exist only in those containers' own env,
|
|
12
|
+
* and the CLI's env builders refuse any framework-managed material's VALUE in an application-tier env, under any
|
|
13
|
+
* name (`assertNoPlatformCredentialInGeneratedEnv`). Which materials do reach an agent-spawning runtime, and under
|
|
14
|
+
* which names, is measured by the CLI's `runtime-secret-env-keys.material-coverage.test.ts`, which holds them to
|
|
15
|
+
* this set.
|
|
16
|
+
*/
|
|
17
|
+
export declare const RUNTIME_SECRET_ENV_KEYS: ReadonlySet<string>;
|
|
18
|
+
/**
|
|
19
|
+
* Whether `envVarName` is a secret a Wildo runtime env carries by the framework's own declaration (#3018): a member of
|
|
20
|
+
* {@link RUNTIME_SECRET_ENV_KEYS}, or a variable the framework DERIVES per application, whose name it recognises from
|
|
21
|
+
* its own derivation:
|
|
22
|
+
* - an inbound endpoint's verification secret (`WILDO_INBOUND_<KEY>__SECRET`, `parseInboundEndpointSecretEnvVarName`);
|
|
23
|
+
* - any slot of a declared system of record (`WILDO_SOR_<NAME>__<SLOT>`, `parseSystemOfRecordEnvVarName`). The WHOLE
|
|
24
|
+
* family, address slots included: which slot is a secret is the facet's declaration, which a name cannot carry, and
|
|
25
|
+
* no consumer of this predicate needs a system of record's address (an agent reaches one through the application,
|
|
26
|
+
* never through its own environment).
|
|
27
|
+
*
|
|
28
|
+
* A provider's secrets are not here: they are known where the provider registry is (the backend registry, the CLI's
|
|
29
|
+
* composed catalogue), and each caller adds them.
|
|
30
|
+
*/
|
|
31
|
+
export declare function isRuntimeSecretEnvVarName(envVarName: string): boolean;
|
|
32
|
+
//# sourceMappingURL=runtime-secret-env.contracts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-secret-env.contracts.d.ts","sourceRoot":"","sources":["../../../../src/bootstrap/runtime-secret-env.contracts.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,uBAAuB,EAAE,WAAW,CAAC,MAAM,CAItD,CAAC;AAEH;;;;;;;;;;;;GAYG;AACH,wBAAgB,yBAAyB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAIrE"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { APPLICATION_BACKEND_SENSITIVE_ENV_KEYS, APPLICATION_WORKER_SENSITIVE_ENV_KEYS } from '@wildo-ai/platform-core-shared';
|
|
2
|
+
import { parseInboundEndpointSecretEnvVarName, parseSystemOfRecordEnvVarName } from '@wildo-ai/saas-models';
|
|
3
|
+
import { PLATFORM_RUNTIME_SENSITIVE_ENV_KEYS } from './platform-runtime-env.contracts.js';
|
|
4
|
+
/**
|
|
5
|
+
* Every environment variable a Wildo runtime env contract declares secret: the platform services', the application
|
|
6
|
+
* backend's (minions included, which run on its env) and the application workers'.
|
|
7
|
+
*
|
|
8
|
+
* DERIVED from the three declared sets, never listed here, so a secret a contract adds is in it the day it is added.
|
|
9
|
+
* Its first reader is the coding-agent boundary (#3018), through {@link isRuntimeSecretEnvVarName}: a variable in this
|
|
10
|
+
* set may never be forwarded into an agent's subprocess (`inheritedEnvironmentVariables`), because the process that
|
|
11
|
+
* spawns the agent holds it.
|
|
12
|
+
*
|
|
13
|
+
* What it does NOT hold, and why that is not a gap: the variables a backing-service CONTAINER reads its credentials
|
|
14
|
+
* from (`MONGO_INITDB_ROOT_PASSWORD`, `RABBITMQ_ERLANG_COOKIE`, ...). They exist only in those containers' own env,
|
|
15
|
+
* and the CLI's env builders refuse any framework-managed material's VALUE in an application-tier env, under any
|
|
16
|
+
* name (`assertNoPlatformCredentialInGeneratedEnv`). Which materials do reach an agent-spawning runtime, and under
|
|
17
|
+
* which names, is measured by the CLI's `runtime-secret-env-keys.material-coverage.test.ts`, which holds them to
|
|
18
|
+
* this set.
|
|
19
|
+
*/
|
|
20
|
+
export const RUNTIME_SECRET_ENV_KEYS = new Set([
|
|
21
|
+
...PLATFORM_RUNTIME_SENSITIVE_ENV_KEYS,
|
|
22
|
+
...APPLICATION_BACKEND_SENSITIVE_ENV_KEYS,
|
|
23
|
+
...APPLICATION_WORKER_SENSITIVE_ENV_KEYS,
|
|
24
|
+
]);
|
|
25
|
+
/**
|
|
26
|
+
* Whether `envVarName` is a secret a Wildo runtime env carries by the framework's own declaration (#3018): a member of
|
|
27
|
+
* {@link RUNTIME_SECRET_ENV_KEYS}, or a variable the framework DERIVES per application, whose name it recognises from
|
|
28
|
+
* its own derivation:
|
|
29
|
+
* - an inbound endpoint's verification secret (`WILDO_INBOUND_<KEY>__SECRET`, `parseInboundEndpointSecretEnvVarName`);
|
|
30
|
+
* - any slot of a declared system of record (`WILDO_SOR_<NAME>__<SLOT>`, `parseSystemOfRecordEnvVarName`). The WHOLE
|
|
31
|
+
* family, address slots included: which slot is a secret is the facet's declaration, which a name cannot carry, and
|
|
32
|
+
* no consumer of this predicate needs a system of record's address (an agent reaches one through the application,
|
|
33
|
+
* never through its own environment).
|
|
34
|
+
*
|
|
35
|
+
* A provider's secrets are not here: they are known where the provider registry is (the backend registry, the CLI's
|
|
36
|
+
* composed catalogue), and each caller adds them.
|
|
37
|
+
*/
|
|
38
|
+
export function isRuntimeSecretEnvVarName(envVarName) {
|
|
39
|
+
return RUNTIME_SECRET_ENV_KEYS.has(envVarName)
|
|
40
|
+
|| parseInboundEndpointSecretEnvVarName(envVarName) !== null
|
|
41
|
+
|| parseSystemOfRecordEnvVarName(envVarName) !== null;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=runtime-secret-env.contracts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-secret-env.contracts.js","sourceRoot":"","sources":["../../../../src/bootstrap/runtime-secret-env.contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sCAAsC,EAAE,qCAAqC,EAAE,MAAM,gCAAgC,CAAC;AAC/H,OAAO,EAAE,oCAAoC,EAAE,6BAA6B,EAAE,MAAM,uBAAuB,CAAC;AAE5G,OAAO,EAAE,mCAAmC,EAAE,MAAM,kCAAkC,CAAC;AAEvF;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAwB,IAAI,GAAG,CAAS;IAC1E,GAAG,mCAAmC;IACtC,GAAG,sCAAsC;IACzC,GAAG,qCAAqC;CACzC,CAAC,CAAC;AAEH;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,yBAAyB,CAAC,UAAkB;IAC1D,OAAO,uBAAuB,CAAC,GAAG,CAAC,UAAU,CAAC;WACzC,oCAAoC,CAAC,UAAU,CAAC,KAAK,IAAI;WACzD,6BAA6B,CAAC,UAAU,CAAC,KAAK,IAAI,CAAC;AAC1D,CAAC","sourcesContent":["import { APPLICATION_BACKEND_SENSITIVE_ENV_KEYS, APPLICATION_WORKER_SENSITIVE_ENV_KEYS } from '@wildo-ai/platform-core-shared';\nimport { parseInboundEndpointSecretEnvVarName, parseSystemOfRecordEnvVarName } from '@wildo-ai/saas-models';\n\nimport { PLATFORM_RUNTIME_SENSITIVE_ENV_KEYS } from './platform-runtime-env.contracts';\n\n/**\n * Every environment variable a Wildo runtime env contract declares secret: the platform services', the application\n * backend's (minions included, which run on its env) and the application workers'.\n *\n * DERIVED from the three declared sets, never listed here, so a secret a contract adds is in it the day it is added.\n * Its first reader is the coding-agent boundary (#3018), through {@link isRuntimeSecretEnvVarName}: a variable in this\n * set may never be forwarded into an agent's subprocess (`inheritedEnvironmentVariables`), because the process that\n * spawns the agent holds it.\n *\n * What it does NOT hold, and why that is not a gap: the variables a backing-service CONTAINER reads its credentials\n * from (`MONGO_INITDB_ROOT_PASSWORD`, `RABBITMQ_ERLANG_COOKIE`, ...). They exist only in those containers' own env,\n * and the CLI's env builders refuse any framework-managed material's VALUE in an application-tier env, under any\n * name (`assertNoPlatformCredentialInGeneratedEnv`). Which materials do reach an agent-spawning runtime, and under\n * which names, is measured by the CLI's `runtime-secret-env-keys.material-coverage.test.ts`, which holds them to\n * this set.\n */\nexport const RUNTIME_SECRET_ENV_KEYS: ReadonlySet<string> = new Set<string>([\n ...PLATFORM_RUNTIME_SENSITIVE_ENV_KEYS,\n ...APPLICATION_BACKEND_SENSITIVE_ENV_KEYS,\n ...APPLICATION_WORKER_SENSITIVE_ENV_KEYS,\n]);\n\n/**\n * Whether `envVarName` is a secret a Wildo runtime env carries by the framework's own declaration (#3018): a member of\n * {@link RUNTIME_SECRET_ENV_KEYS}, or a variable the framework DERIVES per application, whose name it recognises from\n * its own derivation:\n * - an inbound endpoint's verification secret (`WILDO_INBOUND_<KEY>__SECRET`, `parseInboundEndpointSecretEnvVarName`);\n * - any slot of a declared system of record (`WILDO_SOR_<NAME>__<SLOT>`, `parseSystemOfRecordEnvVarName`). The WHOLE\n * family, address slots included: which slot is a secret is the facet's declaration, which a name cannot carry, and\n * no consumer of this predicate needs a system of record's address (an agent reaches one through the application,\n * never through its own environment).\n *\n * A provider's secrets are not here: they are known where the provider registry is (the backend registry, the CLI's\n * composed catalogue), and each caller adds them.\n */\nexport function isRuntimeSecretEnvVarName(envVarName: string): boolean {\n return RUNTIME_SECRET_ENV_KEYS.has(envVarName)\n || parseInboundEndpointSecretEnvVarName(envVarName) !== null\n || parseSystemOfRecordEnvVarName(envVarName) !== null;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-topology.contracts.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"runtime-topology.contracts.d.ts","sourceRoot":"","sources":["../../../../src/bootstrap/runtime-topology.contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,mBAAmB,EACzB,MAAM,gCAAgC,CAAC;AASxC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sDAAsD,CAAC;AAEjG,OAAO,EACL,gCAAgC,EAChC,6BAA6B,EAC7B,2BAA2B,EAC3B,uBAAuB,EACvB,0BAA0B,EAC1B,+BAA+B,GAChC,MAAM,gCAAgC,CAAC;AAExC,YAAY,EACV,gCAAgC,EAChC,6BAA6B,EAC7B,mBAAmB,GACpB,MAAM,gCAAgC,CAAC;AAExC,wBAAgB,sCAAsC,CACpD,IAAI,GAAE,MAAoB,GACzB,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAWrC;AAED,MAAM,WAAW,yCAAyC;IACxD,kBAAkB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,wBAAwB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IAC9D,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,0BAA0B,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChD,I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jD,KAAK,EAAE,mCAAmC,GACzC,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAIrC;AAED;;;;;;;GAOG;AACH,wBAAgB,uCAAuC,CACrD,KAAK,EAAE,uCAAuC,GAC7C,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAErC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wildo-owner-organization.contracts.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"wildo-owner-organization.contracts.d.ts","sourceRoot":"","sources":["../../../../src/bootstrap/wildo-owner-organization.contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8D,KAAK,uBAAuB,EAAE,KAAK,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAEvJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,MAAM,WAAW,8BAA8B;IAC7C,mFAAmF;IACnF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,wGAAwG;IACxG,QAAQ,CAAC,IAAI,EAAE,OAAO,gCAAgC,CAAC;CACxD;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,+BAA+B,WAAW,CAAC;AAExD,eAAO,MAAM,yBAAyB,EAAE,eAIvC,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gCAAgC,sBAAsB,CAAC;AAEpE,eAAO,MAAM,iCAAiC,EAAE,uBAO/C,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,8BAItC,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC 8785 (JSON Canonicalization Scheme) serialization: the ONE implementation in the repository.
|
|
3
|
+
*
|
|
4
|
+
* Lived in `saas-backend-lib` (`flows-actors/utils/canonical-json.backend.utils.ts`) until 2026-10-19, when the response
|
|
5
|
+
* signatures of #2921 needed it on both sides of the apps-manager boundary. It moved here, to the dependency-light
|
|
6
|
+
* contracts package every runtime and every platform service already depends on, rather than gaining a second copy:
|
|
7
|
+
* a hand-rolled alternative (`stableJsonStringify`) was briefly used for those signatures and was wrong in two ways an
|
|
8
|
+
* RFC 8785 serializer is not. It assigned keys onto an ordinary object, so a `"__proto__"` member set the prototype
|
|
9
|
+
* and vanished from the serialization, letting it be added to a signed body undetected; and it let JavaScript order
|
|
10
|
+
* integer-like keys numerically, which no verifier in another language would reproduce.
|
|
11
|
+
*
|
|
12
|
+
* What this serializer guarantees: object keys compared as raw UTF-16 code units; arrays in authored order; numbers in
|
|
13
|
+
* ECMAScript's finite JSON form; strings preserved without Unicode normalization; no whitespace; and members built on
|
|
14
|
+
* null-prototype objects, so `__proto__` is an ordinary member. Values `JSON.stringify` would silently coerce or omit
|
|
15
|
+
* are refused instead, because such coercion would collapse distinct inputs onto one digest.
|
|
16
|
+
*
|
|
17
|
+
* Consumers: apps-manager response signatures (`runtime-response-integrity.ts`), the framework-knowledge generation
|
|
18
|
+
* pipeline (deterministic output bytes), and the meta-workflow compiler tests.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* The JSON data model accepted by the canonicalization boundary.
|
|
22
|
+
*
|
|
23
|
+
* The runtime functions intentionally accept `unknown` and validate it rather
|
|
24
|
+
* than trusting this compile-time shape. Digest inputs may originate in parsed
|
|
25
|
+
* artifacts or application-owned adapters, so a type assertion must never be
|
|
26
|
+
* enough to admit a non-JSON value into semantic identity.
|
|
27
|
+
*/
|
|
28
|
+
export type JsonValue = null | boolean | number | string | readonly JsonValue[] | {
|
|
29
|
+
readonly [key: string]: JsonValue;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* A fail-closed canonicalization error with the structural location of the
|
|
33
|
+
* invalid value. Error messages intentionally describe shape/type only and do
|
|
34
|
+
* not interpolate the rejected value, which may contain application data.
|
|
35
|
+
*/
|
|
36
|
+
export declare class CanonicalJsonError extends TypeError {
|
|
37
|
+
readonly path: string;
|
|
38
|
+
constructor(path: string, reason: string);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Produce RFC 8785/JCS-compatible JSON text from strict JSON data.
|
|
42
|
+
*
|
|
43
|
+
* Object keys are compared as raw UTF-16 code units, arrays retain their
|
|
44
|
+
* authored order, numbers use ECMAScript's finite-number JSON form, strings
|
|
45
|
+
* are preserved without Unicode normalization, and no whitespace is emitted.
|
|
46
|
+
* Values that JavaScript's ordinary `JSON.stringify` would silently coerce or
|
|
47
|
+
* omit are rejected instead, because such coercion would collapse distinct
|
|
48
|
+
* semantic inputs onto one digest.
|
|
49
|
+
*/
|
|
50
|
+
export declare function canonicalizeJson(value: unknown): string;
|
|
51
|
+
//# sourceMappingURL=rfc8785-canonical-json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rfc8785-canonical-json.d.ts","sourceRoot":"","sources":["../../../../src/canonical-json/rfc8785-canonical-json.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH;;;;;;;GAOG;AACH,MAAM,MAAM,SAAS,GACjB,IAAI,GACJ,OAAO,GACP,MAAM,GACN,MAAM,GACN,SAAS,SAAS,EAAE,GACpB;IAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAE1C;;;;GAIG;AACH,qBAAa,kBAAmB,SAAQ,SAAS;IAC/C,SAAgB,IAAI,EAAE,MAAM,CAAC;gBAEV,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAKhD;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAGvD"}
|