@kya-os/mcp-i-cloudflare 1.18.0 → 1.18.2
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/README.md +273 -54
- package/dist/adapter.d.ts +3 -17
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +30 -477
- package/dist/adapter.js.map +1 -1
- package/dist/agent.d.ts +59 -35
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +383 -406
- package/dist/agent.js.map +1 -1
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +150 -94
- package/dist/app.js.map +1 -1
- package/dist/audit/deployment-binding.d.ts +16 -16
- package/dist/authority-outcome.d.ts +110 -0
- package/dist/authority-outcome.d.ts.map +1 -0
- package/dist/authority-outcome.js +154 -0
- package/dist/authority-outcome.js.map +1 -0
- package/dist/config.d.ts +8 -77
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +0 -83
- package/dist/config.js.map +1 -1
- package/dist/delegation-http/bearer-retry.d.ts +84 -32
- package/dist/delegation-http/bearer-retry.d.ts.map +1 -1
- package/dist/delegation-http/bearer-retry.js +124 -139
- package/dist/delegation-http/bearer-retry.js.map +1 -1
- package/dist/delegation-http/connect-gate.d.ts +47 -0
- package/dist/delegation-http/connect-gate.d.ts.map +1 -0
- package/dist/delegation-http/connect-gate.js +104 -0
- package/dist/delegation-http/connect-gate.js.map +1 -0
- package/dist/delegation-http/constants.d.ts +4 -49
- package/dist/delegation-http/constants.d.ts.map +1 -1
- package/dist/delegation-http/constants.js +4 -58
- package/dist/delegation-http/constants.js.map +1 -1
- package/dist/delegation-http/issuer-binding.d.ts +26 -0
- package/dist/delegation-http/issuer-binding.d.ts.map +1 -0
- package/dist/delegation-http/issuer-binding.js +51 -0
- package/dist/delegation-http/issuer-binding.js.map +1 -0
- package/dist/delegation-http/lazy-auth-gate.d.ts +88 -0
- package/dist/delegation-http/lazy-auth-gate.d.ts.map +1 -0
- package/dist/delegation-http/lazy-auth-gate.js +203 -0
- package/dist/delegation-http/lazy-auth-gate.js.map +1 -0
- package/dist/delegation-http/native-challenge.d.ts +52 -0
- package/dist/delegation-http/native-challenge.d.ts.map +1 -0
- package/dist/delegation-http/native-challenge.js +124 -0
- package/dist/delegation-http/native-challenge.js.map +1 -0
- package/dist/delegation-http/native-consent-redirect.d.ts +21 -0
- package/dist/delegation-http/native-consent-redirect.d.ts.map +1 -0
- package/dist/delegation-http/native-consent-redirect.js +43 -0
- package/dist/delegation-http/native-consent-redirect.js.map +1 -0
- package/dist/delegation-http/native-http.d.ts +1 -86
- package/dist/delegation-http/native-http.d.ts.map +1 -1
- package/dist/delegation-http/native-http.js +2 -130
- package/dist/delegation-http/native-http.js.map +1 -1
- package/dist/delegation-http/native-oauth-state-do.d.ts +13 -35
- package/dist/delegation-http/native-oauth-state-do.d.ts.map +1 -1
- package/dist/delegation-http/native-oauth-state-do.js +10 -165
- package/dist/delegation-http/native-oauth-state-do.js.map +1 -1
- package/dist/delegation-http/protected-resource.d.ts +37 -0
- package/dist/delegation-http/protected-resource.d.ts.map +1 -0
- package/dist/delegation-http/protected-resource.js +43 -0
- package/dist/delegation-http/protected-resource.js.map +1 -0
- package/dist/delegation-http/request-proof.d.ts +20 -0
- package/dist/delegation-http/request-proof.d.ts.map +1 -0
- package/dist/delegation-http/request-proof.js +29 -0
- package/dist/delegation-http/request-proof.js.map +1 -0
- package/dist/delegation-http/sid.d.ts +4 -12
- package/dist/delegation-http/sid.d.ts.map +1 -1
- package/dist/delegation-http/sid.js +4 -19
- package/dist/delegation-http/sid.js.map +1 -1
- package/dist/delegation-http/well-known-capability.d.ts +8 -12
- package/dist/delegation-http/well-known-capability.d.ts.map +1 -1
- package/dist/delegation-http/well-known-capability.js +9 -18
- package/dist/delegation-http/well-known-capability.js.map +1 -1
- package/dist/helpers/env-mapper.d.ts.map +1 -1
- package/dist/helpers/env-mapper.js +7 -29
- package/dist/helpers/env-mapper.js.map +1 -1
- package/dist/index.d.ts +2 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -8
- package/dist/index.js.map +1 -1
- package/dist/proof-generator.d.ts +24 -17
- package/dist/proof-generator.d.ts.map +1 -1
- package/dist/proof-generator.js +42 -56
- package/dist/proof-generator.js.map +1 -1
- package/dist/runtime/oauth-handler.d.ts +1 -1
- package/dist/runtime/oauth-handler.d.ts.map +1 -1
- package/dist/runtime/oauth-handler.js +15 -30
- package/dist/runtime/oauth-handler.js.map +1 -1
- package/dist/runtime.d.ts +34 -10
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +54 -12
- package/dist/runtime.js.map +1 -1
- package/dist/security/admission-refusal.d.ts +3 -3
- package/dist/security/admission-refusal.d.ts.map +1 -1
- package/dist/security/admission-refusal.js +14 -6
- package/dist/security/admission-refusal.js.map +1 -1
- package/dist/security/holder-binding.d.ts +34 -0
- package/dist/security/holder-binding.d.ts.map +1 -0
- package/dist/security/holder-binding.js +75 -0
- package/dist/security/holder-binding.js.map +1 -0
- package/dist/security/mcp-admission.d.ts +29 -1
- package/dist/security/mcp-admission.d.ts.map +1 -1
- package/dist/security/mcp-admission.js +78 -12
- package/dist/security/mcp-admission.js.map +1 -1
- package/dist/security/native-holder-admission.d.ts +39 -0
- package/dist/security/native-holder-admission.d.ts.map +1 -0
- package/dist/security/native-holder-admission.js +65 -0
- package/dist/security/native-holder-admission.js.map +1 -0
- package/dist/security/outcome-proof.d.ts +39 -0
- package/dist/security/outcome-proof.d.ts.map +1 -0
- package/dist/security/outcome-proof.js +54 -0
- package/dist/security/outcome-proof.js.map +1 -0
- package/dist/security/request-nonce-store.d.ts +43 -0
- package/dist/security/request-nonce-store.d.ts.map +1 -0
- package/dist/security/request-nonce-store.js +129 -0
- package/dist/security/request-nonce-store.js.map +1 -0
- package/dist/security/routed-request.d.ts +41 -0
- package/dist/security/routed-request.d.ts.map +1 -0
- package/dist/security/routed-request.js +86 -0
- package/dist/security/routed-request.js.map +1 -0
- package/dist/security/sign-in-amr.d.ts +23 -0
- package/dist/security/sign-in-amr.d.ts.map +1 -0
- package/dist/security/sign-in-amr.js +44 -0
- package/dist/security/sign-in-amr.js.map +1 -0
- package/dist/services/approval-route.d.ts +3 -2
- package/dist/services/approval-route.d.ts.map +1 -1
- package/dist/services/approval-route.js.map +1 -1
- package/dist/services/checkpoint-decision.d.ts +56 -0
- package/dist/services/checkpoint-decision.d.ts.map +1 -0
- package/dist/services/checkpoint-decision.js +109 -0
- package/dist/services/checkpoint-decision.js.map +1 -0
- package/dist/services/consent-page-renderer.d.ts.map +1 -1
- package/dist/services/consent-page-renderer.js +2 -3
- package/dist/services/consent-page-renderer.js.map +1 -1
- package/dist/services/consent.service.d.ts +11 -49
- package/dist/services/consent.service.d.ts.map +1 -1
- package/dist/services/consent.service.js +81 -307
- package/dist/services/consent.service.js.map +1 -1
- package/dist/services/credential-auth.handler.d.ts.map +1 -1
- package/dist/services/credential-auth.handler.js +2 -8
- package/dist/services/credential-auth.handler.js.map +1 -1
- package/dist/services/delegation-authority.d.ts +53 -0
- package/dist/services/delegation-authority.d.ts.map +1 -0
- package/dist/services/delegation-authority.js +130 -0
- package/dist/services/delegation-authority.js.map +1 -0
- package/dist/services/delegation-trust.d.ts +35 -64
- package/dist/services/delegation-trust.d.ts.map +1 -1
- package/dist/services/delegation-trust.js +98 -279
- package/dist/services/delegation-trust.js.map +1 -1
- package/dist/services/delegation.service.d.ts +83 -105
- package/dist/services/delegation.service.d.ts.map +1 -1
- package/dist/services/delegation.service.js +166 -518
- package/dist/services/delegation.service.js.map +1 -1
- package/dist/services/idp-token-storage.d.ts +32 -12
- package/dist/services/idp-token-storage.d.ts.map +1 -1
- package/dist/services/idp-token-storage.js +79 -36
- package/dist/services/idp-token-storage.js.map +1 -1
- package/dist/services/issuer-keys.d.ts +55 -0
- package/dist/services/issuer-keys.d.ts.map +1 -0
- package/dist/services/issuer-keys.js +184 -0
- package/dist/services/issuer-keys.js.map +1 -0
- package/dist/services/oauth-security.service.d.ts +17 -1
- package/dist/services/oauth-security.service.d.ts.map +1 -1
- package/dist/services/oauth-security.service.js +29 -10
- package/dist/services/oauth-security.service.js.map +1 -1
- package/dist/services/resource-audience.d.ts +12 -9
- package/dist/services/resource-audience.d.ts.map +1 -1
- package/dist/services/resource-audience.js +12 -9
- package/dist/services/resource-audience.js.map +1 -1
- package/dist/services/unenforceable-tool-protection.d.ts +32 -0
- package/dist/services/unenforceable-tool-protection.d.ts.map +1 -0
- package/dist/services/unenforceable-tool-protection.js +90 -0
- package/dist/services/unenforceable-tool-protection.js.map +1 -0
- package/dist/services/upstream-fetch.d.ts +14 -0
- package/dist/services/upstream-fetch.d.ts.map +1 -0
- package/dist/services/upstream-fetch.js +56 -0
- package/dist/services/upstream-fetch.js.map +1 -0
- package/dist/types.d.ts +5 -18
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/tool-security-schemes.d.ts +65 -0
- package/dist/utils/tool-security-schemes.d.ts.map +1 -0
- package/dist/utils/tool-security-schemes.js +168 -0
- package/dist/utils/tool-security-schemes.js.map +1 -0
- package/package.json +4 -5
- package/dist/delegation-http/anchor-do.d.ts +0 -84
- package/dist/delegation-http/anchor-do.d.ts.map +0 -1
- package/dist/delegation-http/anchor-do.js +0 -412
- package/dist/delegation-http/anchor-do.js.map +0 -1
- package/dist/delegation-http/anchor-registration-validate.d.ts +0 -61
- package/dist/delegation-http/anchor-registration-validate.d.ts.map +0 -1
- package/dist/delegation-http/anchor-registration-validate.js +0 -191
- package/dist/delegation-http/anchor-registration-validate.js.map +0 -1
- package/dist/delegation-http/anchor-registration.d.ts +0 -62
- package/dist/delegation-http/anchor-registration.d.ts.map +0 -1
- package/dist/delegation-http/anchor-registration.js +0 -337
- package/dist/delegation-http/anchor-registration.js.map +0 -1
- package/dist/delegation-http/anchor-routing.d.ts +0 -20
- package/dist/delegation-http/anchor-routing.d.ts.map +0 -1
- package/dist/delegation-http/anchor-routing.js +0 -27
- package/dist/delegation-http/anchor-routing.js.map +0 -1
- package/dist/delegation-http/challenge-middleware.d.ts +0 -28
- package/dist/delegation-http/challenge-middleware.d.ts.map +0 -1
- package/dist/delegation-http/challenge-middleware.js +0 -190
- package/dist/delegation-http/challenge-middleware.js.map +0 -1
- package/dist/delegation-http/challenge.d.ts +0 -102
- package/dist/delegation-http/challenge.d.ts.map +0 -1
- package/dist/delegation-http/challenge.js +0 -223
- package/dist/delegation-http/challenge.js.map +0 -1
- package/dist/delegation-http/consent-anchor-bridge.d.ts +0 -70
- package/dist/delegation-http/consent-anchor-bridge.d.ts.map +0 -1
- package/dist/delegation-http/consent-anchor-bridge.js +0 -1130
- package/dist/delegation-http/consent-anchor-bridge.js.map +0 -1
- package/dist/delegation-http/consent-preparation-page.d.ts +0 -18
- package/dist/delegation-http/consent-preparation-page.d.ts.map +0 -1
- package/dist/delegation-http/consent-preparation-page.js +0 -172
- package/dist/delegation-http/consent-preparation-page.js.map +0 -1
- package/dist/delegation-http/credential-consent.d.ts +0 -149
- package/dist/delegation-http/credential-consent.d.ts.map +0 -1
- package/dist/delegation-http/credential-consent.js +0 -338
- package/dist/delegation-http/credential-consent.js.map +0 -1
- package/dist/delegation-http/native-capabilities.d.ts +0 -4
- package/dist/delegation-http/native-capabilities.d.ts.map +0 -1
- package/dist/delegation-http/native-capabilities.js +0 -53
- package/dist/delegation-http/native-capabilities.js.map +0 -1
- package/dist/delegation-http/native-oauth-state.d.ts +0 -28
- package/dist/delegation-http/native-oauth-state.d.ts.map +0 -1
- package/dist/delegation-http/native-oauth-state.js +0 -146
- package/dist/delegation-http/native-oauth-state.js.map +0 -1
- package/dist/delegation-http/native-oauth.d.ts +0 -26
- package/dist/delegation-http/native-oauth.d.ts.map +0 -1
- package/dist/delegation-http/native-oauth.js +0 -401
- package/dist/delegation-http/native-oauth.js.map +0 -1
- package/dist/delegation-http/native-pickup.d.ts +0 -20
- package/dist/delegation-http/native-pickup.d.ts.map +0 -1
- package/dist/delegation-http/native-pickup.js +0 -227
- package/dist/delegation-http/native-pickup.js.map +0 -1
- package/dist/delegation-http/pickup-routes.d.ts +0 -43
- package/dist/delegation-http/pickup-routes.d.ts.map +0 -1
- package/dist/delegation-http/pickup-routes.js +0 -166
- package/dist/delegation-http/pickup-routes.js.map +0 -1
- package/dist/delegation-http/register.d.ts +0 -26
- package/dist/delegation-http/register.d.ts.map +0 -1
- package/dist/delegation-http/register.js +0 -95
- package/dist/delegation-http/register.js.map +0 -1
- package/dist/delegation-http/registrar-auth.d.ts +0 -24
- package/dist/delegation-http/registrar-auth.d.ts.map +0 -1
- package/dist/delegation-http/registrar-auth.js +0 -61
- package/dist/delegation-http/registrar-auth.js.map +0 -1
- package/dist/delegation-http/remote-issuer.d.ts +0 -52
- package/dist/delegation-http/remote-issuer.d.ts.map +0 -1
- package/dist/delegation-http/remote-issuer.js +0 -324
- package/dist/delegation-http/remote-issuer.js.map +0 -1
- package/dist/delegation-http/types.d.ts +0 -116
- package/dist/delegation-http/types.d.ts.map +0 -1
- package/dist/delegation-http/types.js +0 -11
- package/dist/delegation-http/types.js.map +0 -1
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Holder binding: a credential bound to a holder key is used with proof of
|
|
3
|
+
* possession, never as a bearer token.
|
|
4
|
+
*
|
|
5
|
+
* HTTP binding revision 13 §8(6): a credential carrying `cnf`, or an
|
|
6
|
+
* `assurance` of `key-bound`, `registered` or `delegated`, is usable only by a
|
|
7
|
+
* caller who proves it holds the bound key. The KYA-OS engine applies the
|
|
8
|
+
* same rule (its bearer lane refuses such a credential; its signed lane binds
|
|
9
|
+
* it to the request key), and so do Checkpoint's decision endpoints.
|
|
10
|
+
*
|
|
11
|
+
* In this worker the proof is the request proof that admission verified for
|
|
12
|
+
* the call (./mcp-admission). Both claims are read from the credential's
|
|
13
|
+
* top-level claims, where the org authorization service writes them, and only
|
|
14
|
+
* once the credential has verified.
|
|
15
|
+
*
|
|
16
|
+
* @module @kya-os/mcp-i-cloudflare/security/holder-binding
|
|
17
|
+
*/
|
|
18
|
+
import { nativeHolderBinding } from "../delegation-http/native-http";
|
|
19
|
+
const HOLDER_BOUND_ASSURANCES = new Set([
|
|
20
|
+
"key-bound",
|
|
21
|
+
"registered",
|
|
22
|
+
"delegated",
|
|
23
|
+
]);
|
|
24
|
+
/**
|
|
25
|
+
* Whether a credential is bound to a holder key. `cnf` counts whatever its
|
|
26
|
+
* value: null, empty or malformed, none of them proves possession.
|
|
27
|
+
*/
|
|
28
|
+
export function isHolderBound(claims) {
|
|
29
|
+
return (Object.prototype.hasOwnProperty.call(claims, "cnf") ||
|
|
30
|
+
(typeof claims.assurance === "string" &&
|
|
31
|
+
HOLDER_BOUND_ASSURANCES.has(claims.assurance)));
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Whether the holder proved for this call is the one a holder-bound
|
|
35
|
+
* credential names: the credential subject, and `sub` when present, is that
|
|
36
|
+
* DID, and a `cnf` names that DID's key by its RFC 7638 thumbprint (`jkt`).
|
|
37
|
+
*
|
|
38
|
+
* @param claims - The verified credential's top-level claims
|
|
39
|
+
* @param subjectId - Its `credentialSubject.id`
|
|
40
|
+
* @param holderDid - The DID request admission proved for this call
|
|
41
|
+
*/
|
|
42
|
+
export async function holderBindingVerdict(claims, subjectId, holderDid) {
|
|
43
|
+
if (!holderDid)
|
|
44
|
+
return "holder_proof_required";
|
|
45
|
+
if (subjectId !== holderDid)
|
|
46
|
+
return "holder_mismatch";
|
|
47
|
+
if (claims.sub !== undefined && claims.sub !== holderDid)
|
|
48
|
+
return "holder_mismatch";
|
|
49
|
+
if (!Object.prototype.hasOwnProperty.call(claims, "cnf"))
|
|
50
|
+
return "bound";
|
|
51
|
+
const cnf = claims.cnf;
|
|
52
|
+
const jkt = cnf && typeof cnf === "object" && !Array.isArray(cnf)
|
|
53
|
+
? cnf.jkt
|
|
54
|
+
: undefined;
|
|
55
|
+
if (typeof jkt !== "string" || !jkt)
|
|
56
|
+
return "holder_mismatch";
|
|
57
|
+
return (await holderKeyThumbprint(holderDid)) === jkt
|
|
58
|
+
? "bound"
|
|
59
|
+
: "holder_mismatch";
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The RFC 7638 thumbprint of a did:key holder's key (Ed25519 or P-256), the
|
|
63
|
+
* same derivation the native issuer uses for the `cnf` it requests. Any other
|
|
64
|
+
* DID has no key to compare here, so it never matches.
|
|
65
|
+
*/
|
|
66
|
+
async function holderKeyThumbprint(did) {
|
|
67
|
+
try {
|
|
68
|
+
return (await nativeHolderBinding(`${did}#${did.slice("did:key:".length)}`))
|
|
69
|
+
.jkt;
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=holder-binding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"holder-binding.js","sourceRoot":"","sources":["../../src/security/holder-binding.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAErE,MAAM,uBAAuB,GAAwB,IAAI,GAAG,CAAC;IAC3D,WAAW;IACX,YAAY;IACZ,WAAW;CACZ,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,MAA+B;IAC3D,OAAO,CACL,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC;QACnD,CAAC,OAAO,MAAM,CAAC,SAAS,KAAK,QAAQ;YACnC,uBAAuB,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CACjD,CAAC;AACJ,CAAC;AAOD;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,MAA+B,EAC/B,SAAkB,EAClB,SAA6B;IAE7B,IAAI,CAAC,SAAS;QAAE,OAAO,uBAAuB,CAAC;IAC/C,IAAI,SAAS,KAAK,SAAS;QAAE,OAAO,iBAAiB,CAAC;IACtD,IAAI,MAAM,CAAC,GAAG,KAAK,SAAS,IAAI,MAAM,CAAC,GAAG,KAAK,SAAS;QACtD,OAAO,iBAAiB,CAAC;IAC3B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC;QAAE,OAAO,OAAO,CAAC;IACzE,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;IACvB,MAAM,GAAG,GACP,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;QACnD,CAAC,CAAE,GAA+B,CAAC,GAAG;QACtC,CAAC,CAAC,SAAS,CAAC;IAChB,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,GAAG;QAAE,OAAO,iBAAiB,CAAC;IAC9D,OAAO,CAAC,MAAM,mBAAmB,CAAC,SAAS,CAAC,CAAC,KAAK,GAAG;QACnD,CAAC,CAAC,OAAO;QACT,CAAC,CAAC,iBAAiB,CAAC;AACxB,CAAC;AAED;;;;GAIG;AACH,KAAK,UAAU,mBAAmB,CAAC,GAAW;IAC5C,IAAI,CAAC;QACH,OAAO,CAAC,MAAM,mBAAmB,CAAC,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;aACzE,GAAG,CAAC;IACT,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -34,6 +34,29 @@ export type McpAdmissionRefusalReport = {
|
|
|
34
34
|
* ADMISSION_REFUSAL_REPORT_BUDGET_MS; its failures never reach the caller.
|
|
35
35
|
*/
|
|
36
36
|
export type McpAdmissionRefusalReporter = (report: McpAdmissionRefusalReport) => Promise<void>;
|
|
37
|
+
/** One refused tools/call, handed to the outcome hook before the reply. */
|
|
38
|
+
export interface McpAdmissionRefusalOutcome {
|
|
39
|
+
toolName: string;
|
|
40
|
+
sessionId?: string;
|
|
41
|
+
/**
|
|
42
|
+
* The refused request's params without `_meta`: unproven input, usable only
|
|
43
|
+
* as the material a request hash covers.
|
|
44
|
+
*/
|
|
45
|
+
params: Readonly<Record<string, unknown>>;
|
|
46
|
+
/** The code the reply carries on the wire (`proof_invalid`, ...). */
|
|
47
|
+
code: string;
|
|
48
|
+
/** The classified refusal, for the audit trail only; never sent. */
|
|
49
|
+
refusal?: AdmissionRefusal;
|
|
50
|
+
/** The reply as it would be sent. */
|
|
51
|
+
result: CallToolResult;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Called once per refused tools/call, before the reply, even when the caller
|
|
55
|
+
* has stopped waiting. Records the refusal and may return the reply to send
|
|
56
|
+
* instead (the signed one); returning nothing, throwing, or exceeding
|
|
57
|
+
* ADMISSION_REFUSAL_REPORT_BUDGET_MS sends the original reply.
|
|
58
|
+
*/
|
|
59
|
+
export type McpAdmissionRefusalOutcomeHook = (outcome: McpAdmissionRefusalOutcome) => Promise<CallToolResult | undefined>;
|
|
37
60
|
export interface McpRequestHolder {
|
|
38
61
|
readonly did: string;
|
|
39
62
|
readonly level: "L3" | "L3-minus";
|
|
@@ -52,12 +75,17 @@ export type McpRequestAdmission = (request: JSONRPCRequest, context: McpAdmissio
|
|
|
52
75
|
* the public Transport contract, so it works with both DO and ordinary MCP
|
|
53
76
|
* transports without patching private SDK handlers.
|
|
54
77
|
*/
|
|
55
|
-
export declare function withMcpAdmission(transport: Transport, admit: McpRequestAdmission, reportRefusal?: McpAdmissionRefusalReporter): Transport;
|
|
78
|
+
export declare function withMcpAdmission(transport: Transport, admit: McpRequestAdmission, reportRefusal?: McpAdmissionRefusalReporter, onRefusal?: McpAdmissionRefusalOutcomeHook): Transport;
|
|
56
79
|
/** How long a refused call waits for its Checkpoint report before replying. */
|
|
57
80
|
export declare const ADMISSION_REFUSAL_REPORT_BUDGET_MS = 2000;
|
|
58
81
|
export interface AdmissionMcpServerOptions {
|
|
59
82
|
/** Called once per refused tools/call of a registered tool, before the reply. */
|
|
60
83
|
reportRefusal?: McpAdmissionRefusalReporter;
|
|
84
|
+
/**
|
|
85
|
+
* Called once per refused tools/call of a registered tool, before the
|
|
86
|
+
* reply: records the refusal and may return the signed reply.
|
|
87
|
+
*/
|
|
88
|
+
onRefusal?: McpAdmissionRefusalOutcomeHook;
|
|
61
89
|
}
|
|
62
90
|
/** McpAgent calls this public connect method when attaching its DO transport. */
|
|
63
91
|
export declare class AdmissionMcpServer extends McpServer {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-admission.d.ts","sourceRoot":"","sources":["../../src/security/mcp-admission.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+CAA+C,CAAC;AAC/E,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,gBAAgB,EACjB,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EAG1B,MAAM,qBAAqB,CAAC;AAM7B,MAAM,WAAW,mBAAmB;IAClC,6EAA6E;IAC7E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAC;IACxC,WAAW,CAAC,EAAE,gBAAgB,CAAC,aAAa,CAAC,CAAC;CAC/C;AAED,MAAM,MAAM,kBAAkB,GAC1B;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,MAAM,CAAC,EAAE,gBAAgB,CAAA;CAAE,GAC5C;IACE,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE,cAAc,CAAC;IACvB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,gBAAgB,CAAC;CAC5B,CAAC;AAEN,qFAAqF;AACrF,MAAM,MAAM,yBAAyB,GAAG;IACtC,QAAQ,EAA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ElE;AAED,kFAAkF;AAClF,wBAAgB,yBAAyB,IAAI,MAAM,GAAG,SAAS,CAE9D;AAED;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAChC,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE,mBAAmB,KACzB,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAEjC;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,mBAAmB,EAC1B,aAAa,CAAC,EAAE,2BAA2B,EAC3C,SAAS,CAAC,EAAE,8BAA8B,GACzC,SAAS,CAuJX;AAyED,+EAA+E;AAC/E,eAAO,MAAM,kCAAkC,OAAQ,CAAC;AAoGxD,MAAM,WAAW,yBAAyB;IACxC,iFAAiF;IACjF,aAAa,CAAC,EAAE,2BAA2B,CAAC;IAC5C;;;OAGG;IACH,SAAS,CAAC,EAAE,8BAA8B,CAAC;CAC5C;AAiBD,iFAAiF;AACjF,qBAAa,kBAAmB,SAAQ,SAAS;IAG7C,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAFxB,IAAI,EAAE,qBAAqB,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,EAC/B,SAAS,EAAE,mBAAmB,EAC9B,OAAO,GAAE,yBAA8B;IAKjD,OAAO,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;CAyBtD"}
|
|
@@ -17,7 +17,7 @@ export function getMcpPresentedDelegation() {
|
|
|
17
17
|
* the public Transport contract, so it works with both DO and ordinary MCP
|
|
18
18
|
* transports without patching private SDK handlers.
|
|
19
19
|
*/
|
|
20
|
-
export function withMcpAdmission(transport, admit, reportRefusal) {
|
|
20
|
+
export function withMcpAdmission(transport, admit, reportRefusal, onRefusal) {
|
|
21
21
|
let closed = false;
|
|
22
22
|
const pending = new Map();
|
|
23
23
|
const wrapped = {
|
|
@@ -87,8 +87,22 @@ export function withMcpAdmission(transport, admit, reportRefusal) {
|
|
|
87
87
|
const { verdict, presentedDelegation } = await admitOriginal(original, context, admit);
|
|
88
88
|
// Before the cancelled check: a refused call is still an attempt
|
|
89
89
|
// worth recording, even when its caller has stopped waiting.
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
const refused = verdict?.allowed === true
|
|
91
|
+
? undefined
|
|
92
|
+
: verdict?.allowed === false
|
|
93
|
+
? verdict.result
|
|
94
|
+
: {
|
|
95
|
+
isError: true,
|
|
96
|
+
content: [{ type: "text", text: "Authorization denied" }],
|
|
97
|
+
};
|
|
98
|
+
const [, outcomeReply] = await Promise.all([
|
|
99
|
+
reportRefusal
|
|
100
|
+
? reportAdmissionRefusal(reportRefusal, verdict, original.params?.name, sessionId)
|
|
101
|
+
: undefined,
|
|
102
|
+
refused && onRefusal
|
|
103
|
+
? applyRefusalOutcome(onRefusal, verdict, refused, original, sessionId)
|
|
104
|
+
: undefined,
|
|
105
|
+
]);
|
|
92
106
|
if (closed || active.cancelled)
|
|
93
107
|
return;
|
|
94
108
|
if (verdict?.allowed === true) {
|
|
@@ -101,14 +115,7 @@ export function withMcpAdmission(transport, admit, reportRefusal) {
|
|
|
101
115
|
await transport.send({
|
|
102
116
|
jsonrpc: "2.0",
|
|
103
117
|
id: original.id,
|
|
104
|
-
result:
|
|
105
|
-
? verdict.result
|
|
106
|
-
: {
|
|
107
|
-
isError: true,
|
|
108
|
-
content: [
|
|
109
|
-
{ type: "text", text: "Authorization denied" },
|
|
110
|
-
],
|
|
111
|
-
},
|
|
118
|
+
result: outcomeReply ?? refused ?? {},
|
|
112
119
|
}, { relatedRequestId: original.id });
|
|
113
120
|
}
|
|
114
121
|
})()
|
|
@@ -229,6 +236,60 @@ async function reportAdmissionRefusal(reportRefusal, verdict, toolName, sessionI
|
|
|
229
236
|
// the reporter owns its own logging.
|
|
230
237
|
}
|
|
231
238
|
}
|
|
239
|
+
/** The code a refusal's reply carries on the wire, for the signed outcome. */
|
|
240
|
+
function wireCode(result) {
|
|
241
|
+
const first = result.content?.[0];
|
|
242
|
+
if (first?.type === "text") {
|
|
243
|
+
try {
|
|
244
|
+
const code = JSON.parse(first.text).error;
|
|
245
|
+
if (typeof code === "string" && /^[a-z_]{1,48}$/.test(code))
|
|
246
|
+
return code;
|
|
247
|
+
}
|
|
248
|
+
catch {
|
|
249
|
+
// Not the JSON gate reply: fall through to the generic code.
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return "authorization_denied";
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Runs the outcome hook for a refused call under the same budget as the
|
|
256
|
+
* Checkpoint report. Its failures never change or withhold the refusal.
|
|
257
|
+
*/
|
|
258
|
+
async function applyRefusalOutcome(onRefusal, verdict, refused, original, sessionId) {
|
|
259
|
+
try {
|
|
260
|
+
const toolName = original.params?.name;
|
|
261
|
+
if (typeof toolName !== "string")
|
|
262
|
+
return undefined;
|
|
263
|
+
const { _meta: _unproven, ...params } = original.params ?? {};
|
|
264
|
+
const refusal = verdict?.allowed === false ? verdict.refusal : undefined;
|
|
265
|
+
let timer;
|
|
266
|
+
const budget = new Promise((resolve) => {
|
|
267
|
+
timer = setTimeout(() => resolve(undefined), ADMISSION_REFUSAL_REPORT_BUDGET_MS);
|
|
268
|
+
});
|
|
269
|
+
try {
|
|
270
|
+
return await Promise.race([
|
|
271
|
+
onRefusal({
|
|
272
|
+
toolName,
|
|
273
|
+
sessionId,
|
|
274
|
+
params,
|
|
275
|
+
code: wireCode(refused),
|
|
276
|
+
...(isAdmissionRefusalCode(refusal?.code)
|
|
277
|
+
? { refusal: refusal }
|
|
278
|
+
: {}),
|
|
279
|
+
result: refused,
|
|
280
|
+
}),
|
|
281
|
+
budget,
|
|
282
|
+
]);
|
|
283
|
+
}
|
|
284
|
+
finally {
|
|
285
|
+
clearTimeout(timer);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
catch {
|
|
289
|
+
// Signing and recording must never change or withhold the refusal.
|
|
290
|
+
return undefined;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
232
293
|
/**
|
|
233
294
|
* The SDK keeps its tool registry private and offers no lookup, so this is
|
|
234
295
|
* the minimal private read (precedent: utils/hidden-consent-tools.ts). An own
|
|
@@ -259,7 +320,12 @@ export class AdmissionMcpServer extends McpServer {
|
|
|
259
320
|
if (isRegisteredTool(this, refusal.toolName))
|
|
260
321
|
await report(refusal);
|
|
261
322
|
});
|
|
262
|
-
|
|
323
|
+
const onRefusal = this.options.onRefusal;
|
|
324
|
+
const outcomeRegistered = onRefusal &&
|
|
325
|
+
(async (outcome) => isRegisteredTool(this, outcome.toolName)
|
|
326
|
+
? onRefusal(outcome)
|
|
327
|
+
: undefined);
|
|
328
|
+
return super.connect(withMcpAdmission(transport, this.admission, reportRegistered, outcomeRegistered));
|
|
263
329
|
}
|
|
264
330
|
}
|
|
265
331
|
//# sourceMappingURL=mcp-admission.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-admission.js","sourceRoot":"","sources":["../../src/security/mcp-admission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAQpE,OAAO,EAGL,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,6BAA6B,EAC7B,0BAA0B,GAC3B,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"mcp-admission.js","sourceRoot":"","sources":["../../src/security/mcp-admission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAQpE,OAAO,EAGL,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,6BAA6B,EAC7B,0BAA0B,GAC3B,MAA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C;YACtE,CAAC,CAAC,CAAC;QACL,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC;QACzC,MAAM,iBAAiB,GACrB,SAAS;YACT,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CACjB,gBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC;gBACtC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC;gBACpB,CAAC,CAAC,SAAS,CAAC,CAAC;QACnB,OAAO,KAAK,CAAC,OAAO,CAClB,gBAAgB,CACd,SAAS,EACT,IAAI,CAAC,SAAS,EACd,gBAAgB,EAChB,iBAAiB,CAClB,CACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Request admission for deployments on the native rail.
|
|
3
|
+
*
|
|
4
|
+
* A native-rail caller holds a key-bound credential, which the worker accepts
|
|
5
|
+
* only with proof that the caller holds the bound key (./holder-binding).
|
|
6
|
+
* That proof is the request proof admission verifies. A deployment that
|
|
7
|
+
* carries the native issuer binding and configures no admission of its own
|
|
8
|
+
* gets this one:
|
|
9
|
+
*
|
|
10
|
+
* - every tool is `public`: a signed call's proof is always verified (a bad
|
|
11
|
+
* proof is refused), and an unsigned call keeps today's path;
|
|
12
|
+
* - the holder is a did:key, resolved locally with no network;
|
|
13
|
+
* - each proof's nonce is consumed once per deployment (./request-nonce-store);
|
|
14
|
+
* - proofs are addressed to the worker's own DID.
|
|
15
|
+
*
|
|
16
|
+
* Without the worker's DID or an `MCP_OBJECT` binding there is nothing to
|
|
17
|
+
* check proofs against, so no admission is installed, and a holder-bound
|
|
18
|
+
* credential is then refused as before.
|
|
19
|
+
*
|
|
20
|
+
* @module @kya-os/mcp-i-cloudflare/security/native-holder-admission
|
|
21
|
+
*/
|
|
22
|
+
import type { DurableObjectNamespace } from "@cloudflare/workers-types";
|
|
23
|
+
import type { ProofPublicJwk } from "@kya-os/mcp/card";
|
|
24
|
+
import type { CloudflareEnv } from "../types";
|
|
25
|
+
import type { McpRequestAdmission } from "./mcp-admission";
|
|
26
|
+
/**
|
|
27
|
+
* Resolve a did:key verification method with no network. nativeHolderBinding
|
|
28
|
+
* accepts only a canonical did:key with its own multibase fragment, so a kid
|
|
29
|
+
* that merely looks like one never resolves to a key.
|
|
30
|
+
*/
|
|
31
|
+
export declare function resolveDidKeyHolder(kid: string): Promise<ProofPublicJwk>;
|
|
32
|
+
/**
|
|
33
|
+
* The admission a native-rail deployment gets by default, or undefined when
|
|
34
|
+
* the deployment is not on the native rail or cannot check proofs.
|
|
35
|
+
*/
|
|
36
|
+
export declare function nativeRailHolderAdmission(env: CloudflareEnv & {
|
|
37
|
+
MCP_OBJECT?: DurableObjectNamespace;
|
|
38
|
+
}): McpRequestAdmission | undefined;
|
|
39
|
+
//# sourceMappingURL=native-holder-admission.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-holder-admission.d.ts","sourceRoot":"","sources":["../../src/security/native-holder-admission.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAExE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAO3D;;;;GAIG;AACH,wBAAsB,mBAAmB,CACvC,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,cAAc,CAAC,CAKzB;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,GAAG,EAAE,aAAa,GAAG;IAAE,UAAU,CAAC,EAAE,sBAAsB,CAAA;CAAE,GAC3D,mBAAmB,GAAG,SAAS,CAuBjC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Request admission for deployments on the native rail.
|
|
3
|
+
*
|
|
4
|
+
* A native-rail caller holds a key-bound credential, which the worker accepts
|
|
5
|
+
* only with proof that the caller holds the bound key (./holder-binding).
|
|
6
|
+
* That proof is the request proof admission verifies. A deployment that
|
|
7
|
+
* carries the native issuer binding and configures no admission of its own
|
|
8
|
+
* gets this one:
|
|
9
|
+
*
|
|
10
|
+
* - every tool is `public`: a signed call's proof is always verified (a bad
|
|
11
|
+
* proof is refused), and an unsigned call keeps today's path;
|
|
12
|
+
* - the holder is a did:key, resolved locally with no network;
|
|
13
|
+
* - each proof's nonce is consumed once per deployment (./request-nonce-store);
|
|
14
|
+
* - proofs are addressed to the worker's own DID.
|
|
15
|
+
*
|
|
16
|
+
* Without the worker's DID or an `MCP_OBJECT` binding there is nothing to
|
|
17
|
+
* check proofs against, so no admission is installed, and a holder-bound
|
|
18
|
+
* credential is then refused as before.
|
|
19
|
+
*
|
|
20
|
+
* @module @kya-os/mcp-i-cloudflare/security/native-holder-admission
|
|
21
|
+
*/
|
|
22
|
+
import { extractPublicKeyFromDidKey, publicKeyToJwk } from "@kya-os/mcp";
|
|
23
|
+
import { nativeHolderBinding } from "../delegation-http/native-http";
|
|
24
|
+
import { parseNativeIssuerBinding } from "../delegation-http/issuer-binding";
|
|
25
|
+
import { createMcpHolderAdmission } from "./mcp-holder-admission";
|
|
26
|
+
import { REQUEST_PROOF_SKEW_SEC, consumeFromRequestNonceStore, } from "./request-nonce-store";
|
|
27
|
+
/**
|
|
28
|
+
* Resolve a did:key verification method with no network. nativeHolderBinding
|
|
29
|
+
* accepts only a canonical did:key with its own multibase fragment, so a kid
|
|
30
|
+
* that merely looks like one never resolves to a key.
|
|
31
|
+
*/
|
|
32
|
+
export async function resolveDidKeyHolder(kid) {
|
|
33
|
+
const { did } = await nativeHolderBinding(kid);
|
|
34
|
+
const publicKey = extractPublicKeyFromDidKey(did);
|
|
35
|
+
if (!publicKey)
|
|
36
|
+
throw new Error("Only Ed25519 did:key holders are accepted");
|
|
37
|
+
return publicKeyToJwk(publicKey);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The admission a native-rail deployment gets by default, or undefined when
|
|
41
|
+
* the deployment is not on the native rail or cannot check proofs.
|
|
42
|
+
*/
|
|
43
|
+
export function nativeRailHolderAdmission(env) {
|
|
44
|
+
if (!parseNativeIssuerBinding(env.MCPI_NATIVE_HTTP_ISSUER_CONFIG))
|
|
45
|
+
return undefined;
|
|
46
|
+
const workerDid = env.MCP_IDENTITY_AGENT_DID;
|
|
47
|
+
if (!workerDid || !env.MCP_OBJECT) {
|
|
48
|
+
console.warn("[MCP-I] Native rail without MCP_IDENTITY_AGENT_DID or MCP_OBJECT: no request admission, so holder-bound credentials are refused");
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
const consumeNonceIfFresh = consumeFromRequestNonceStore(env.MCP_OBJECT);
|
|
52
|
+
return createMcpHolderAdmission({
|
|
53
|
+
modeForTool: () => "public",
|
|
54
|
+
proof: () => ({
|
|
55
|
+
expectedAudience: workerDid,
|
|
56
|
+
skewSec: REQUEST_PROOF_SKEW_SEC,
|
|
57
|
+
resolveKey: resolveDidKeyHolder,
|
|
58
|
+
resolveDidKeys: async (did) => [
|
|
59
|
+
await resolveDidKeyHolder(`${did}#${did.slice("did:key:".length)}`),
|
|
60
|
+
],
|
|
61
|
+
consumeNonceIfFresh,
|
|
62
|
+
}),
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=native-holder-admission.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-holder-admission.js","sourceRoot":"","sources":["../../src/security/native-holder-admission.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,EAAE,0BAA0B,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAEzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,wBAAwB,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,EAAE,CAAC;aACpE;YACD,mBAAmB;SACpB,CAAC;KACH,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Signing of authority outcomes on a tools/call.
|
|
3
|
+
*
|
|
4
|
+
* A `needs_authorization` or `denied` tool result carries a proof at
|
|
5
|
+
* `_meta.proof`, the key success proofs use. `needs_authorization` binds the
|
|
6
|
+
* result as the client receives it (everything but its top-level `_meta`)
|
|
7
|
+
* and says so with the envelope profile claim (`prf`), so `@kya-os/mcp`'s
|
|
8
|
+
* verifier hashes the same bytes. `denied` binds no response body and names
|
|
9
|
+
* its reason. The request hash covers `{method: toolName, params: args}`, as
|
|
10
|
+
* a success proof's does.
|
|
11
|
+
*
|
|
12
|
+
* This module only calls the generator's public `generateProof`; the claim
|
|
13
|
+
* shape lives in the generator.
|
|
14
|
+
*
|
|
15
|
+
* @module @kya-os/mcp-i-cloudflare/security/outcome-proof
|
|
16
|
+
*/
|
|
17
|
+
import type { CloudflareProofGenerator } from "../proof-generator";
|
|
18
|
+
export type AuthorityOutcome = {
|
|
19
|
+
outcome: "needs_authorization";
|
|
20
|
+
} | {
|
|
21
|
+
outcome: "denied";
|
|
22
|
+
reason: string;
|
|
23
|
+
};
|
|
24
|
+
export interface OutcomeCall {
|
|
25
|
+
toolName: string;
|
|
26
|
+
/** The tool arguments. */
|
|
27
|
+
params: Record<string, unknown>;
|
|
28
|
+
}
|
|
29
|
+
export interface OutcomeSession {
|
|
30
|
+
id: string;
|
|
31
|
+
audience?: string;
|
|
32
|
+
clientDid?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The result with its outcome proof attached. Returns the result unsigned,
|
|
36
|
+
* and logs, when signing fails: a missing proof never fails the call.
|
|
37
|
+
*/
|
|
38
|
+
export declare function attachOutcomeProof<T extends Record<string, unknown>>(generator: CloudflareProofGenerator | undefined, nonce: () => Promise<string>, result: T, outcome: AuthorityOutcome, call: OutcomeCall, session: OutcomeSession): Promise<T>;
|
|
39
|
+
//# sourceMappingURL=outcome-proof.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outcome-proof.d.ts","sourceRoot":"","sources":["../../src/security/outcome-proof.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAEnE,MAAM,MAAM,gBAAgB,GACxB;IAAE,OAAO,EAAE,qBAAqB,CAAA;CAAE,GAClC;IAAE,OAAO,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1C,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,0BAA0B;IAC1B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxE,SAAS,EAAE,wBAAwB,GAAG,SAAS,EAC/C,KAAK,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,EAC5B,MAAM,EAAE,CAAC,EACT,OAAO,EAAE,gBAAgB,EACzB,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,CAAC,CAAC,CAoCZ"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Signing of authority outcomes on a tools/call.
|
|
3
|
+
*
|
|
4
|
+
* A `needs_authorization` or `denied` tool result carries a proof at
|
|
5
|
+
* `_meta.proof`, the key success proofs use. `needs_authorization` binds the
|
|
6
|
+
* result as the client receives it (everything but its top-level `_meta`)
|
|
7
|
+
* and says so with the envelope profile claim (`prf`), so `@kya-os/mcp`'s
|
|
8
|
+
* verifier hashes the same bytes. `denied` binds no response body and names
|
|
9
|
+
* its reason. The request hash covers `{method: toolName, params: args}`, as
|
|
10
|
+
* a success proof's does.
|
|
11
|
+
*
|
|
12
|
+
* This module only calls the generator's public `generateProof`; the claim
|
|
13
|
+
* shape lives in the generator.
|
|
14
|
+
*
|
|
15
|
+
* @module @kya-os/mcp-i-cloudflare/security/outcome-proof
|
|
16
|
+
*/
|
|
17
|
+
import { RESPONSE_PROOF_PROFILE_ENVELOPE } from "@kya-os/mcp";
|
|
18
|
+
/**
|
|
19
|
+
* The result with its outcome proof attached. Returns the result unsigned,
|
|
20
|
+
* and logs, when signing fails: a missing proof never fails the call.
|
|
21
|
+
*/
|
|
22
|
+
export async function attachOutcomeProof(generator, nonce, result, outcome, call, session) {
|
|
23
|
+
try {
|
|
24
|
+
if (!generator) {
|
|
25
|
+
console.error("[outcome-proof] Skipped: no proof generator");
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
const { _meta, ...envelope } = result;
|
|
29
|
+
const proof = await generator.generateProof({ method: call.toolName, params: call.params }, { data: outcome.outcome === "denied" ? {} : envelope }, {
|
|
30
|
+
nonce: await nonce(),
|
|
31
|
+
audience: session.audience || "mcp-client",
|
|
32
|
+
sessionId: session.id,
|
|
33
|
+
}, {
|
|
34
|
+
outcome: outcome.outcome,
|
|
35
|
+
...(outcome.outcome === "denied"
|
|
36
|
+
? { reason: outcome.reason }
|
|
37
|
+
: { prf: RESPONSE_PROOF_PROFILE_ENVELOPE }),
|
|
38
|
+
toolName: call.toolName,
|
|
39
|
+
...(session.clientDid ? { clientDid: session.clientDid } : {}),
|
|
40
|
+
});
|
|
41
|
+
const meta = _meta !== null && typeof _meta === "object"
|
|
42
|
+
? _meta
|
|
43
|
+
: {};
|
|
44
|
+
return {
|
|
45
|
+
...result,
|
|
46
|
+
_meta: { ...meta, proof: { jws: proof.jws, meta: proof.meta } },
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
console.error("[outcome-proof] Failed to sign:", error);
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=outcome-proof.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outcome-proof.js","sourceRoot":"","sources":["../../src/security/outcome-proof.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,+BAA+B,EAAE,MAAM,aAAa,CAAC;AAmB9D;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,SAA+C,EAC/C,KAA4B,EAC5B,MAAS,EACT,OAAyB,EACzB,IAAiB,EACjB,OAAuB;IAEvB,IAAI,CAAC;QACH,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,6CAA6C,CAAC,CAAC;YAC7D,OAAO,MAAM,CAAC;QAChB,CAAC;QACD,MAAM,EAAE,KAAK,EAAE,GAAG,QAAQ,EAAE,GAAG,MAAM,CAAC;QACtC,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,aAAa,CACzC,EAAE,MAAM,EAAE,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,EAC9C,EAAE,IAAI,EAAE,OAAO,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,EACtD;YACE,KAAK,EAAE,MAAM,KAAK,EAAE;YACpB,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,YAAY;YAC1C,SAAS,EAAE,OAAO,CAAC,EAAE;SACtB,EACD;YACE,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,GAAG,CAAC,OAAO,CAAC,OAAO,KAAK,QAAQ;gBAC9B,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE;gBAC5B,CAAC,CAAC,EAAE,GAAG,EAAE,+BAA+B,EAAE,CAAC;YAC7C,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC/D,CACF,CAAC;QACF,MAAM,IAAI,GACR,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;YACzC,CAAC,CAAE,KAAiC;YACpC,CAAC,CAAC,EAAE,CAAC;QACT,OAAO;YACL,GAAG,MAAM;YACT,KAAK,EAAE,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,EAAE;SAChE,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAC;QACxD,OAAO,MAAM,CAAC;IAChB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The request-proof nonce store: one named `MCP_OBJECT` instance that every
|
|
3
|
+
* holder-admission check in a deployment consumes nonces from, so a signed
|
|
4
|
+
* call accepted once is refused everywhere after.
|
|
5
|
+
*
|
|
6
|
+
* One Durable Object instance serialises every consume, and the
|
|
7
|
+
* test-and-set runs inside a storage transaction, so two requests carrying
|
|
8
|
+
* the same nonce can never both be accepted. Any failure throws in the
|
|
9
|
+
* consumer, and the proof verifier turns a throw into a refusal.
|
|
10
|
+
*
|
|
11
|
+
* The card constants the retention depends on are read through the
|
|
12
|
+
* package's validated accessor on each consume, never at module load: in a
|
|
13
|
+
* bundle that holds the agent, esbuild initialises `@kya-os/mcp/card`
|
|
14
|
+
* lazily, so a value read at load can be undefined.
|
|
15
|
+
*
|
|
16
|
+
* @module @kya-os/mcp-i-cloudflare/security/request-nonce-store
|
|
17
|
+
*/
|
|
18
|
+
import type { DurableObjectNamespace, DurableObjectStorage } from "@cloudflare/workers-types";
|
|
19
|
+
import type { ConsumeNonceIfFresh } from "@kya-os/mcp/card";
|
|
20
|
+
/** The one `MCP_OBJECT` instance that holds every nonce, across all sessions. */
|
|
21
|
+
export declare const REQUEST_NONCE_INSTANCE = "request-nonces";
|
|
22
|
+
export declare const REQUEST_NONCE_CONSUME_PATH = "/_internal/request-nonce/consume";
|
|
23
|
+
/**
|
|
24
|
+
* Accepted clock skew for request proofs. The card default is 5 s. The nonce
|
|
25
|
+
* retention follows from it: the proof lifetime, this skew on both sides and
|
|
26
|
+
* one second of rounding.
|
|
27
|
+
*/
|
|
28
|
+
export declare const REQUEST_PROOF_SKEW_SEC = 30;
|
|
29
|
+
/** A consumer for the proof verifier, backed by the deployment's nonce instance. */
|
|
30
|
+
export declare function consumeFromRequestNonceStore(namespace: DurableObjectNamespace | undefined): ConsumeNonceIfFresh;
|
|
31
|
+
/**
|
|
32
|
+
* Answer a consume inside the nonce instance: `{ fresh: true }` the first
|
|
33
|
+
* time a holder's nonce is seen within its retention, `{ fresh: false }`
|
|
34
|
+
* after. 400 for a malformed request, 503 when the card constants do not
|
|
35
|
+
* validate (the consumer then throws and the call is refused).
|
|
36
|
+
*/
|
|
37
|
+
export declare function handleRequestNonceConsume(storage: DurableObjectStorage, request: Request, skewSec?: number): Promise<Response>;
|
|
38
|
+
/** Replays refused so far, and the retention the last consume applied. */
|
|
39
|
+
export declare function requestNonceStats(storage: DurableObjectStorage): Promise<{
|
|
40
|
+
replaysRefused: number;
|
|
41
|
+
retentionSec: number | null;
|
|
42
|
+
}>;
|
|
43
|
+
//# sourceMappingURL=request-nonce-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-nonce-store.d.ts","sourceRoot":"","sources":["../../src/security/request-nonce-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EACV,sBAAsB,EACtB,oBAAoB,EACrB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAO5D,iFAAiF;AACjF,eAAO,MAAM,sBAAsB,mBAAmB,CAAC;AACvD,eAAO,MAAM,0BAA0B,qCAAqC,CAAC;AAC7E;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,KAAK,CAAC;AAYzC,oFAAoF;AACpF,wBAAgB,4BAA4B,CAC1C,SAAS,EAAE,sBAAsB,GAAG,SAAS,GAC5C,mBAAmB,CAgBrB;AAYD;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAC7C,OAAO,EAAE,oBAAoB,EAC7B,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE,MAA+B,GACvC,OAAO,CAAC,QAAQ,CAAC,CAiCnB;AA4BD,0EAA0E;AAC1E,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC;IAAE,cAAc,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC,CAKlE"}
|