@kya-os/mcp-i-runtime 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -3
- package/dist/index.js.map +1 -1
- package/dist/services/auth-type-satisfies.d.ts +93 -0
- package/dist/services/auth-type-satisfies.d.ts.map +1 -0
- package/dist/services/auth-type-satisfies.js +127 -0
- package/dist/services/auth-type-satisfies.js.map +1 -0
- package/dist/services/tool-context-builder.d.ts +6 -1
- package/dist/services/tool-context-builder.d.ts.map +1 -1
- package/dist/services/tool-context-builder.js +35 -3
- package/dist/services/tool-context-builder.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +9 -0
- package/src/services/__tests__/auth-type-satisfies.test.ts +232 -0
- package/src/services/__tests__/tool-context-builder-authtype.test.ts +167 -0
- package/src/services/auth-type-satisfies.ts +134 -0
- package/src/services/tool-context-builder.ts +64 -18
package/.turbo/turbo-build.log
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ export { OAuthService, defaultSecretResolver } from "./services/oauth-service";
|
|
|
31
31
|
export type { OAuthServiceConfig, SecretResolver, } from "./services/oauth-service";
|
|
32
32
|
export { ToolContextBuilder } from "./services/tool-context-builder";
|
|
33
33
|
export type { ToolContextBuilderConfig } from "./services/tool-context-builder";
|
|
34
|
+
export { authTypeSatisfies, normalizeAuthType, } from "./services/auth-type-satisfies";
|
|
34
35
|
export { OAuthProviderRegistry } from "./services/oauth-provider-registry";
|
|
35
36
|
export { ProviderResolver, ConsentOnlyModeError, CredentialAuthModeError, } from "./services/provider-resolver";
|
|
36
37
|
export { ProviderValidator, ProviderValidationError, } from "./services/provider-validator";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts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|
package/dist/index.js
CHANGED
|
@@ -20,9 +20,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
20
20
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.
|
|
24
|
-
exports.
|
|
25
|
-
exports.generateResumeToken = void 0;
|
|
23
|
+
exports.OAuthTokenRetrievalService = exports.ProviderValidationError = exports.ProviderValidator = exports.CredentialAuthModeError = exports.ConsentOnlyModeError = exports.ProviderResolver = exports.OAuthProviderRegistry = exports.normalizeAuthType = exports.authTypeSatisfies = exports.ToolContextBuilder = exports.defaultSecretResolver = exports.OAuthService = exports.OAuthConfigService = exports.createSessionRegistrationService = exports.SessionRegistrationService = exports.authorizationMatches = exports.AccessControlApiService = exports.ProofVerifier = exports.CryptoService = exports.PolicyService = exports.ToolProtectionService = exports.terminalForToolResult = exports.terminalForToolError = exports.recordRuntimeDelegationAudit = exports.recordRuntimeConsentAudit = exports.createHmacRuntimeAuditContextFactory = exports.beginRuntimeToolAudit = exports.attachRuntimeAuditMetadata = exports.RuntimeToolAuditInvocation = exports.toNeedsAuthorization = exports.normalizeInternalToolName = exports.isInternalToolName = exports.recordWireForm = exports.LEGACY_WELL_KNOWN_IDENTITY_PATH = exports.WELL_KNOWN_IDENTITY_PATH = exports.LEGACY_INTERNAL_TOOL_PREFIX = exports.INTERNAL_TOOL_PREFIX = exports.LEGACY_SESSION_ID_PREFIX = exports.SESSION_ID_PREFIX = exports.CONSENT_UI_RESOURCE_URI = exports.MCPIRuntimeBase = exports.MemoryIdentityProvider = exports.MemoryNonceCacheProvider = exports.MemoryStorageProvider = exports.IdentityProvider = exports.NonceCacheProvider = exports.StorageProvider = exports.FetchProvider = exports.ClockProvider = exports.CryptoProvider = void 0;
|
|
24
|
+
exports.verifyOrHints = exports.validateHandshakeFormat = exports.createHandshakeRequest = exports.SessionManager = exports.extractCanonicalData = exports.createProofResponse = exports.ProofGenerator = exports.createDefaultConsoleLogger = exports.logger = exports.IdpTokenResolver = exports.UserDidManager = exports.isPolicyEnabled = exports.hasMergedPolicy = exports.extractPolicy = exports.getPolicy = exports.hasMergedToolProtections = exports.extractToolProtections = exports.getToolProtection = exports.fetchRemoteConfig = exports.bytesToBase64 = exports.base64urlDecodeToString = exports.base64urlDecodeToBytes = exports.base64urlEncodeFromString = exports.base64urlEncodeFromBytes = exports.getSchemaStats = exports.getCriticalSchemas = exports.getSchemaById = exports.getSchemasByCategory = exports.getAllSchemas = exports.SCHEMA_REGISTRY = exports.createSchemaVerifier = exports.SchemaVerifier = exports.isValidBase58 = exports.base58Decode = exports.base58Encode = exports.createDelegationErrorFormatter = exports.DelegationErrorFormatter = exports.OAuthRequiredError = exports.DelegationRequiredError = exports.NoOpToolProtectionCache = exports.InMemoryToolProtectionCache = exports.createProofVerificationError = exports.PROOF_VERIFICATION_ERROR_CODES = exports.ProofVerificationError = exports.migrateLegacyKeys = exports.StorageKeyHelpers = exports.createStorageProviders = exports.NoOpOAuthConfigCache = exports.InMemoryOAuthConfigCache = exports.BatchDelegationService = void 0;
|
|
25
|
+
exports.generateResumeToken = exports.MemoryResumeTokenStore = exports.hasSensitiveScopes = void 0;
|
|
26
26
|
// Base providers
|
|
27
27
|
var base_1 = require("./providers/base");
|
|
28
28
|
Object.defineProperty(exports, "CryptoProvider", { enumerable: true, get: function () { return base_1.CryptoProvider; } });
|
|
@@ -98,6 +98,13 @@ Object.defineProperty(exports, "defaultSecretResolver", { enumerable: true, get:
|
|
|
98
98
|
// Tool Context Builder (Phase 1)
|
|
99
99
|
var tool_context_builder_1 = require("./services/tool-context-builder");
|
|
100
100
|
Object.defineProperty(exports, "ToolContextBuilder", { enumerable: true, get: function () { return tool_context_builder_1.ToolContextBuilder; } });
|
|
101
|
+
// Auth-type satisfaction check (security fix: consent-approve auth-gate, Task B3)
|
|
102
|
+
// Consumed by the delegation-enforcement gates in agent.ts and
|
|
103
|
+
// tool-context-builder.ts to reject a delegation whose authorization type does
|
|
104
|
+
// not satisfy the tool's required type.
|
|
105
|
+
var auth_type_satisfies_1 = require("./services/auth-type-satisfies");
|
|
106
|
+
Object.defineProperty(exports, "authTypeSatisfies", { enumerable: true, get: function () { return auth_type_satisfies_1.authTypeSatisfies; } });
|
|
107
|
+
Object.defineProperty(exports, "normalizeAuthType", { enumerable: true, get: function () { return auth_type_satisfies_1.normalizeAuthType; } });
|
|
101
108
|
// OAuth Provider Registry (Phase 2)
|
|
102
109
|
var oauth_provider_registry_1 = require("./services/oauth-provider-registry");
|
|
103
110
|
Object.defineProperty(exports, "OAuthProviderRegistry", { enumerable: true, get: function () { return oauth_provider_registry_1.OAuthProviderRegistry; } });
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;AAEH,iBAAiB;AACjB,yCAQ0B;AAPxB,sGAAA,cAAc,OAAA;AACd,qGAAA,aAAa,OAAA;AACb,qGAAA,aAAa,OAAA;AACb,uGAAA,eAAe,OAAA;AACf,0GAAA,kBAAkB,OAAA;AAClB,wGAAA,gBAAgB,OAAA;AAIlB,mBAAmB;AACnB,6CAI4B;AAH1B,+GAAA,qBAAqB,OAAA;AACrB,kHAAA,wBAAwB,OAAA;AACxB,gHAAA,sBAAsB,OAAA;AAGxB,UAAU;AACV,uCAAiD;AAAxC,uGAAA,eAAe,OAAA;AAGxB,6BAA6B;AAC7B,mEAAuE;AAA9D,6HAAA,uBAAuB,OAAA;AAEhC,4CAA4C;AAC5C,6CAYuB;AAXrB,gHAAA,iBAAiB,OAAA;AACjB,uHAAA,wBAAwB,OAAA;AACxB,mHAAA,oBAAoB,OAAA;AACpB,0HAAA,2BAA2B,OAAA;AAC3B,uHAAA,wBAAwB,OAAA;AACxB,8HAAA,+BAA+B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AsB,OAAA;AACtB,kHAAA,uBAAuB,OAAA;AAKzB,oEAAoE;AACpE,+BAWgB;AAVd,qGAAA,aAAa,OAAA;AACb,0GAAA,kBAAkB,OAAA;AAClB,8GAAA,sBAAsB,OAAA;AACtB,2GAAA,mBAAmB,OAAA"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auth-Type Satisfaction Check
|
|
3
|
+
*
|
|
4
|
+
* Pure comparison used by the delegation-enforcement gate (security fix:
|
|
5
|
+
* consent-approve auth-gate, 2026-07-29, Task B3) to decide whether a
|
|
6
|
+
* delegation's authorization type satisfies a tool's required authorization
|
|
7
|
+
* type.
|
|
8
|
+
*
|
|
9
|
+
* Background: a gated MCP tool call is authorized by presenting a
|
|
10
|
+
* delegation. A bug let a delegation of ANY auth type satisfy a tool that
|
|
11
|
+
* requires a specific type — e.g. an anonymous consent-only (`none`)
|
|
12
|
+
* delegation wrongly satisfied a `password`-gated tool, because call-time
|
|
13
|
+
* enforcement accepted any present delegation without checking its
|
|
14
|
+
* `authorization.type`. This module implements the comparison that closes
|
|
15
|
+
* that gap. Wiring it into the enforcement sites (`agent.ts`,
|
|
16
|
+
* `tool-context-builder.ts`) is a later task (B3) — this module is
|
|
17
|
+
* intentionally standalone and unused by any gate yet.
|
|
18
|
+
*
|
|
19
|
+
* Decision (locked by product owner, 2026-07-29): STRICT NORMALIZED
|
|
20
|
+
* EQUALITY. A delegation type satisfies a required type iff, after folding
|
|
21
|
+
* deprecated aliases, they are equal. There is no "stronger satisfies
|
|
22
|
+
* weaker" lattice — `oauth`/`oauth2` and `password` are NOT interchangeable,
|
|
23
|
+
* and a `password` delegation does NOT satisfy a `none`-gated tool (or vice
|
|
24
|
+
* versa).
|
|
25
|
+
*
|
|
26
|
+
* @module @kya-os/mcp-i-runtime/services/auth-type-satisfies
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* Fold deprecated authorization-type aliases to their canonical form and
|
|
30
|
+
* normalize casing/whitespace.
|
|
31
|
+
*
|
|
32
|
+
* Alias rules mirror `normalizeAuthorizationType` in
|
|
33
|
+
* `packages/contracts/src/tool-protection/index.ts` (~774): `oauth` folds to
|
|
34
|
+
* `oauth2`, `credential` folds to `verifiable_credential`. That function
|
|
35
|
+
* operates on a full `AuthorizationRequirement` object and emits a
|
|
36
|
+
* deprecation warning on every call; this is a bare-string equivalent for
|
|
37
|
+
* use at the enforcement gate, where only the stored/required type strings
|
|
38
|
+
* — not the full requirement object — are available, and where a warning
|
|
39
|
+
* log on every tool call would be noise. (Not reusing the alias mapping
|
|
40
|
+
* directly from `@kya-os/contracts` here — it is not exposed as a
|
|
41
|
+
* standalone string-keyed map, only baked into that function's control
|
|
42
|
+
* flow — so the two rules are mirrored inline per the task's fallback
|
|
43
|
+
* guidance.)
|
|
44
|
+
*
|
|
45
|
+
* Canonical types (`AUTHORIZATION_TYPES`, contracts/src/tool-protection/index.ts
|
|
46
|
+
* ~88-106) are stored as lowercase string consts (e.g. "password", "oauth2",
|
|
47
|
+
* "none"), so normalization here only needs to trim and lowercase for
|
|
48
|
+
* defensive consistency — it does not need to handle differently-cased
|
|
49
|
+
* input from any known caller today.
|
|
50
|
+
*
|
|
51
|
+
* @param type - Raw authorization type string, or nullish if unknown/missing.
|
|
52
|
+
* @returns The normalized type string, or `undefined` if `type` is nullish or
|
|
53
|
+
* empty/whitespace-only after trimming.
|
|
54
|
+
*/
|
|
55
|
+
export declare function normalizeAuthType(type: string | undefined | null): string | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Decide whether a delegation's authorization type satisfies a tool's
|
|
58
|
+
* required authorization type.
|
|
59
|
+
*
|
|
60
|
+
* Strict normalized equality (locked decision, see module docs above): both
|
|
61
|
+
* types are normalized (alias-folded, trimmed, lowercased) and then compared
|
|
62
|
+
* for exact equality. There is no cross-type satisfaction — a `password`
|
|
63
|
+
* delegation does NOT satisfy an `oauth2`-gated tool, and (by the same
|
|
64
|
+
* strict rule) does NOT satisfy a `none`-gated tool either.
|
|
65
|
+
*
|
|
66
|
+
* Note on `none`-required tools: per strict equality, only a `none`
|
|
67
|
+
* delegation satisfies a `none` requirement. In practice, a tool requiring
|
|
68
|
+
* `none` (consent-only) is not expected to reach this call today — it is
|
|
69
|
+
* rejected earlier, before the delegation-presence gate, by
|
|
70
|
+
* `ConsentOnlyModeError` (see `provider-resolver.ts`) — so this function is
|
|
71
|
+
* expected to be invoked only for TYPED requirements (`password`, `oauth2`,
|
|
72
|
+
* `apikey`, etc.). Strict equality is still implemented faithfully for
|
|
73
|
+
* `none` in case that assumption ever changes.
|
|
74
|
+
*
|
|
75
|
+
* Fail-safe rules (both nullish cases return `false`, never `true`):
|
|
76
|
+
* - If `delegationType` is nullish (missing on a legacy stored record that
|
|
77
|
+
* predates persisting `authorizationType`, or simply absent), this
|
|
78
|
+
* returns `false` regardless of `requiredType` — an unknown/unrecorded
|
|
79
|
+
* delegation type never satisfies a typed requirement.
|
|
80
|
+
* - If `requiredType` is nullish (or normalizes to empty), there is no
|
|
81
|
+
* requirement to compare against. Callers are not expected to invoke this
|
|
82
|
+
* with a nullish `requiredType` (a tool with no authorization requirement
|
|
83
|
+
* doesn't reach this gate), but this fails safe to `false` rather than
|
|
84
|
+
* treating "no requirement" as automatically satisfied.
|
|
85
|
+
*
|
|
86
|
+
* @param delegationType - The delegation's stored/asserted authorization
|
|
87
|
+
* type (e.g. from `getDelegationFromStorage`), or nullish if unknown.
|
|
88
|
+
* @param requiredType - The tool's required authorization type (e.g.
|
|
89
|
+
* `protection.authorization.type`), or nullish.
|
|
90
|
+
* @returns `true` iff both types are present and equal after normalization.
|
|
91
|
+
*/
|
|
92
|
+
export declare function authTypeSatisfies(delegationType: string | undefined | null, requiredType: string | undefined | null): boolean;
|
|
93
|
+
//# sourceMappingURL=auth-type-satisfies.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-type-satisfies.d.ts","sourceRoot":"","sources":["../../src/services/auth-type-satisfies.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAC9B,MAAM,GAAG,SAAS,CAmBpB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAgB,iBAAiB,CAC/B,cAAc,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,EACzC,YAAY,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GACtC,OAAO,CAgBT"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Auth-Type Satisfaction Check
|
|
4
|
+
*
|
|
5
|
+
* Pure comparison used by the delegation-enforcement gate (security fix:
|
|
6
|
+
* consent-approve auth-gate, 2026-07-29, Task B3) to decide whether a
|
|
7
|
+
* delegation's authorization type satisfies a tool's required authorization
|
|
8
|
+
* type.
|
|
9
|
+
*
|
|
10
|
+
* Background: a gated MCP tool call is authorized by presenting a
|
|
11
|
+
* delegation. A bug let a delegation of ANY auth type satisfy a tool that
|
|
12
|
+
* requires a specific type — e.g. an anonymous consent-only (`none`)
|
|
13
|
+
* delegation wrongly satisfied a `password`-gated tool, because call-time
|
|
14
|
+
* enforcement accepted any present delegation without checking its
|
|
15
|
+
* `authorization.type`. This module implements the comparison that closes
|
|
16
|
+
* that gap. Wiring it into the enforcement sites (`agent.ts`,
|
|
17
|
+
* `tool-context-builder.ts`) is a later task (B3) — this module is
|
|
18
|
+
* intentionally standalone and unused by any gate yet.
|
|
19
|
+
*
|
|
20
|
+
* Decision (locked by product owner, 2026-07-29): STRICT NORMALIZED
|
|
21
|
+
* EQUALITY. A delegation type satisfies a required type iff, after folding
|
|
22
|
+
* deprecated aliases, they are equal. There is no "stronger satisfies
|
|
23
|
+
* weaker" lattice — `oauth`/`oauth2` and `password` are NOT interchangeable,
|
|
24
|
+
* and a `password` delegation does NOT satisfy a `none`-gated tool (or vice
|
|
25
|
+
* versa).
|
|
26
|
+
*
|
|
27
|
+
* @module @kya-os/mcp-i-runtime/services/auth-type-satisfies
|
|
28
|
+
*/
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.normalizeAuthType = normalizeAuthType;
|
|
31
|
+
exports.authTypeSatisfies = authTypeSatisfies;
|
|
32
|
+
/**
|
|
33
|
+
* Fold deprecated authorization-type aliases to their canonical form and
|
|
34
|
+
* normalize casing/whitespace.
|
|
35
|
+
*
|
|
36
|
+
* Alias rules mirror `normalizeAuthorizationType` in
|
|
37
|
+
* `packages/contracts/src/tool-protection/index.ts` (~774): `oauth` folds to
|
|
38
|
+
* `oauth2`, `credential` folds to `verifiable_credential`. That function
|
|
39
|
+
* operates on a full `AuthorizationRequirement` object and emits a
|
|
40
|
+
* deprecation warning on every call; this is a bare-string equivalent for
|
|
41
|
+
* use at the enforcement gate, where only the stored/required type strings
|
|
42
|
+
* — not the full requirement object — are available, and where a warning
|
|
43
|
+
* log on every tool call would be noise. (Not reusing the alias mapping
|
|
44
|
+
* directly from `@kya-os/contracts` here — it is not exposed as a
|
|
45
|
+
* standalone string-keyed map, only baked into that function's control
|
|
46
|
+
* flow — so the two rules are mirrored inline per the task's fallback
|
|
47
|
+
* guidance.)
|
|
48
|
+
*
|
|
49
|
+
* Canonical types (`AUTHORIZATION_TYPES`, contracts/src/tool-protection/index.ts
|
|
50
|
+
* ~88-106) are stored as lowercase string consts (e.g. "password", "oauth2",
|
|
51
|
+
* "none"), so normalization here only needs to trim and lowercase for
|
|
52
|
+
* defensive consistency — it does not need to handle differently-cased
|
|
53
|
+
* input from any known caller today.
|
|
54
|
+
*
|
|
55
|
+
* @param type - Raw authorization type string, or nullish if unknown/missing.
|
|
56
|
+
* @returns The normalized type string, or `undefined` if `type` is nullish or
|
|
57
|
+
* empty/whitespace-only after trimming.
|
|
58
|
+
*/
|
|
59
|
+
function normalizeAuthType(type) {
|
|
60
|
+
if (type === undefined || type === null) {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
const trimmed = type.trim().toLowerCase();
|
|
64
|
+
if (trimmed === "") {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
// Deprecated alias -> canonical (mirrors normalizeAuthorizationType).
|
|
68
|
+
if (trimmed === "oauth") {
|
|
69
|
+
return "oauth2";
|
|
70
|
+
}
|
|
71
|
+
if (trimmed === "credential") {
|
|
72
|
+
return "verifiable_credential";
|
|
73
|
+
}
|
|
74
|
+
return trimmed;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Decide whether a delegation's authorization type satisfies a tool's
|
|
78
|
+
* required authorization type.
|
|
79
|
+
*
|
|
80
|
+
* Strict normalized equality (locked decision, see module docs above): both
|
|
81
|
+
* types are normalized (alias-folded, trimmed, lowercased) and then compared
|
|
82
|
+
* for exact equality. There is no cross-type satisfaction — a `password`
|
|
83
|
+
* delegation does NOT satisfy an `oauth2`-gated tool, and (by the same
|
|
84
|
+
* strict rule) does NOT satisfy a `none`-gated tool either.
|
|
85
|
+
*
|
|
86
|
+
* Note on `none`-required tools: per strict equality, only a `none`
|
|
87
|
+
* delegation satisfies a `none` requirement. In practice, a tool requiring
|
|
88
|
+
* `none` (consent-only) is not expected to reach this call today — it is
|
|
89
|
+
* rejected earlier, before the delegation-presence gate, by
|
|
90
|
+
* `ConsentOnlyModeError` (see `provider-resolver.ts`) — so this function is
|
|
91
|
+
* expected to be invoked only for TYPED requirements (`password`, `oauth2`,
|
|
92
|
+
* `apikey`, etc.). Strict equality is still implemented faithfully for
|
|
93
|
+
* `none` in case that assumption ever changes.
|
|
94
|
+
*
|
|
95
|
+
* Fail-safe rules (both nullish cases return `false`, never `true`):
|
|
96
|
+
* - If `delegationType` is nullish (missing on a legacy stored record that
|
|
97
|
+
* predates persisting `authorizationType`, or simply absent), this
|
|
98
|
+
* returns `false` regardless of `requiredType` — an unknown/unrecorded
|
|
99
|
+
* delegation type never satisfies a typed requirement.
|
|
100
|
+
* - If `requiredType` is nullish (or normalizes to empty), there is no
|
|
101
|
+
* requirement to compare against. Callers are not expected to invoke this
|
|
102
|
+
* with a nullish `requiredType` (a tool with no authorization requirement
|
|
103
|
+
* doesn't reach this gate), but this fails safe to `false` rather than
|
|
104
|
+
* treating "no requirement" as automatically satisfied.
|
|
105
|
+
*
|
|
106
|
+
* @param delegationType - The delegation's stored/asserted authorization
|
|
107
|
+
* type (e.g. from `getDelegationFromStorage`), or nullish if unknown.
|
|
108
|
+
* @param requiredType - The tool's required authorization type (e.g.
|
|
109
|
+
* `protection.authorization.type`), or nullish.
|
|
110
|
+
* @returns `true` iff both types are present and equal after normalization.
|
|
111
|
+
*/
|
|
112
|
+
function authTypeSatisfies(delegationType, requiredType) {
|
|
113
|
+
const normalizedDelegationType = normalizeAuthType(delegationType);
|
|
114
|
+
if (normalizedDelegationType === undefined) {
|
|
115
|
+
// Fail-safe: an unknown/missing delegation type never satisfies a
|
|
116
|
+
// requirement, typed or not.
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
const normalizedRequiredType = normalizeAuthType(requiredType);
|
|
120
|
+
if (normalizedRequiredType === undefined) {
|
|
121
|
+
// Fail-safe: no requirement to satisfy is not treated as "anything
|
|
122
|
+
// satisfies it".
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
return normalizedDelegationType === normalizedRequiredType;
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=auth-type-satisfies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-type-satisfies.js","sourceRoot":"","sources":["../../src/services/auth-type-satisfies.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;;AA6BH,8CAqBC;AAsCD,8CAmBC;AAzGD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,SAAgB,iBAAiB,CAC/B,IAA+B;IAE/B,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QACxC,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC1C,IAAI,OAAO,KAAK,EAAE,EAAE,CAAC;QACnB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,sEAAsE;IACtE,IAAI,OAAO,KAAK,OAAO,EAAE,CAAC;QACxB,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,IAAI,OAAO,KAAK,YAAY,EAAE,CAAC;QAC7B,OAAO,uBAAuB,CAAC;IACjC,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,SAAgB,iBAAiB,CAC/B,cAAyC,EACzC,YAAuC;IAEvC,MAAM,wBAAwB,GAAG,iBAAiB,CAAC,cAAc,CAAC,CAAC;IACnE,IAAI,wBAAwB,KAAK,SAAS,EAAE,CAAC;QAC3C,kEAAkE;QAClE,6BAA6B;QAC7B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,sBAAsB,GAAG,iBAAiB,CAAC,YAAY,CAAC,CAAC;IAC/D,IAAI,sBAAsB,KAAK,SAAS,EAAE,CAAC;QACzC,mEAAmE;QACnE,iBAAiB;QACjB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,wBAAwB,KAAK,sBAAsB,CAAC;AAC7D,CAAC"}
|
|
@@ -44,9 +44,14 @@ export declare class ToolContextBuilder {
|
|
|
44
44
|
* @param sessionId - Session ID (optional)
|
|
45
45
|
* @param delegationToken - Delegation token (optional)
|
|
46
46
|
* @param toolProtection - Tool protection configuration (optional)
|
|
47
|
+
* @param delegationAuthorizationType - The stored authorization type of the
|
|
48
|
+
* presented delegation (from `getDelegationFromStorage`), or undefined for
|
|
49
|
+
* legacy records that predate persisting it. Used by the delegation-only
|
|
50
|
+
* fallback below to reject a delegation whose type does not satisfy the
|
|
51
|
+
* tool's required type (security fix: consent-approve auth-gate, Task B3).
|
|
47
52
|
* @returns Tool execution context or undefined if not needed
|
|
48
53
|
*/
|
|
49
|
-
buildContext(toolName: string, userDid: string | undefined, sessionId: string | undefined, delegationToken: string | undefined, toolProtection: ToolProtection | null): Promise<ToolExecutionContext | undefined>;
|
|
54
|
+
buildContext(toolName: string, userDid: string | undefined, sessionId: string | undefined, delegationToken: string | undefined, toolProtection: ToolProtection | null, delegationAuthorizationType?: string): Promise<ToolExecutionContext | undefined>;
|
|
50
55
|
/**
|
|
51
56
|
* Build authentication headers based on token usage metadata (CRED-003)
|
|
52
57
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-context-builder.d.ts","sourceRoot":"","sources":["../../src/services/tool-context-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAE1E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"tool-context-builder.d.ts","sourceRoot":"","sources":["../../src/services/tool-context-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAE1E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAQ/D,MAAM,WAAW,wBAAwB;IACvC,4DAA4D;IAC5D,aAAa,EAAE,gBAAgB,CAAC;IAEhC,gEAAgE;IAChE,aAAa,EAAE,kBAAkB,CAAC;IAElC,gEAAgE;IAChE,gBAAgB,EAAE,gBAAgB,CAAC;IAEnC,2CAA2C;IAC3C,SAAS,EAAE,MAAM,CAAC;IAElB,+CAA+C;IAC/C,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;CACpD;AAED;;;;;;GAMG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAEZ;gBAEU,MAAM,EAAE,wBAAwB;IAU5C;;;;;;;;;;;;;;OAcG;IACG,YAAY,CAChB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,eAAe,EAAE,MAAM,GAAG,SAAS,EACnC,cAAc,EAAE,cAAc,GAAG,IAAI,EACrC,2BAA2B,CAAC,EAAE,MAAM,GACnC,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC;IA8J5C;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,gBAAgB;IA2CxB;;;;;;;OAOG;YACW,eAAe;CAsB9B"}
|
|
@@ -14,6 +14,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
14
14
|
exports.ToolContextBuilder = void 0;
|
|
15
15
|
const oauth_required_error_js_1 = require("../types/oauth-required-error.js");
|
|
16
16
|
const provider_resolver_js_1 = require("./provider-resolver.js");
|
|
17
|
+
const auth_type_satisfies_js_1 = require("./auth-type-satisfies.js");
|
|
17
18
|
/**
|
|
18
19
|
* Builder for tool execution context
|
|
19
20
|
*
|
|
@@ -40,9 +41,14 @@ class ToolContextBuilder {
|
|
|
40
41
|
* @param sessionId - Session ID (optional)
|
|
41
42
|
* @param delegationToken - Delegation token (optional)
|
|
42
43
|
* @param toolProtection - Tool protection configuration (optional)
|
|
44
|
+
* @param delegationAuthorizationType - The stored authorization type of the
|
|
45
|
+
* presented delegation (from `getDelegationFromStorage`), or undefined for
|
|
46
|
+
* legacy records that predate persisting it. Used by the delegation-only
|
|
47
|
+
* fallback below to reject a delegation whose type does not satisfy the
|
|
48
|
+
* tool's required type (security fix: consent-approve auth-gate, Task B3).
|
|
43
49
|
* @returns Tool execution context or undefined if not needed
|
|
44
50
|
*/
|
|
45
|
-
async buildContext(toolName, userDid, sessionId, delegationToken, toolProtection) {
|
|
51
|
+
async buildContext(toolName, userDid, sessionId, delegationToken, toolProtection, delegationAuthorizationType) {
|
|
46
52
|
// Only build context if tool requires OAuth/credentials
|
|
47
53
|
if (!toolProtection?.requiredScopes?.length || !userDid) {
|
|
48
54
|
return undefined;
|
|
@@ -80,7 +86,22 @@ class ToolContextBuilder {
|
|
|
80
86
|
// IDP token not available - check if delegation token exists
|
|
81
87
|
// If delegation exists, tool can still execute without IDP token
|
|
82
88
|
// (the tool handler should check for idpToken if it needs external API access)
|
|
83
|
-
|
|
89
|
+
//
|
|
90
|
+
// SECURITY (consent-approve auth-gate, Task B3): a delegation only
|
|
91
|
+
// authorizes this tool if its OWN authorization type satisfies the tool's
|
|
92
|
+
// required type. Reaching this OAuth context builder means the tool is
|
|
93
|
+
// neither consent-only (`none`) nor password — those throw
|
|
94
|
+
// ConsentOnlyModeError / CredentialAuthModeError inside resolveProvider,
|
|
95
|
+
// BEFORE this point — so the effective requirement is OAuth. Fall back to
|
|
96
|
+
// "oauth2" only when the tool omits an explicit authorization.type (legacy
|
|
97
|
+
// oauthProvider-only config); this keeps such tools working while a
|
|
98
|
+
// mismatched delegation (e.g. an anonymous `none` consent-only delegation,
|
|
99
|
+
// or a legacy record with no persisted type → undefined) is rejected. On
|
|
100
|
+
// mismatch we do NOT return the delegation-only context; we fall through
|
|
101
|
+
// to OAuthRequiredError so the tool re-challenges.
|
|
102
|
+
const requiredAuthType = toolProtection.authorization?.type ?? "oauth2";
|
|
103
|
+
if (delegationToken &&
|
|
104
|
+
(0, auth_type_satisfies_js_1.authTypeSatisfies)(delegationAuthorizationType, requiredAuthType)) {
|
|
84
105
|
this.config.logger("[ToolContextBuilder] IDP token not found, but delegation exists - returning minimal context", {
|
|
85
106
|
toolName,
|
|
86
107
|
userDid: userDid.substring(0, 20) + "...",
|
|
@@ -98,7 +119,18 @@ class ToolContextBuilder {
|
|
|
98
119
|
delegationToken,
|
|
99
120
|
};
|
|
100
121
|
}
|
|
101
|
-
|
|
122
|
+
if (delegationToken) {
|
|
123
|
+
// A delegation WAS presented but its authorization type does not satisfy
|
|
124
|
+
// the tool's required type — log and re-challenge instead of authorizing.
|
|
125
|
+
this.config.logger("[ToolContextBuilder] Delegation present but auth-type does not satisfy tool requirement - re-challenging", {
|
|
126
|
+
toolName,
|
|
127
|
+
userDid: userDid.substring(0, 20) + "...",
|
|
128
|
+
provider,
|
|
129
|
+
requiredAuthType,
|
|
130
|
+
delegationAuthorizationType: delegationAuthorizationType ?? null,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
// No (satisfying) delegation token - throw OAuthRequiredError to trigger auth flow
|
|
102
134
|
this.config.logger("[ToolContextBuilder] Token not available, throwing OAuthRequiredError", {
|
|
103
135
|
toolName,
|
|
104
136
|
userDid: userDid.substring(0, 20) + "...",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-context-builder.js","sourceRoot":"","sources":["../../src/services/tool-context-builder.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AAQH,8EAAsE;AACtE,iEAGgC;
|
|
1
|
+
{"version":3,"file":"tool-context-builder.js","sourceRoot":"","sources":["../../src/services/tool-context-builder.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AAQH,8EAAsE;AACtE,iEAGgC;AAChC,qEAA6D;AAmB7D;;;;;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O,WAAW,CAAC;IACrB,CAAC;IAED;;;;;;;OAOG;IACK,KAAK,CAAC,eAAe,CAC3B,cAA8B;QAE9B,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,eAAe,CACjE,cAAc,EACd,IAAI,CAAC,MAAM,CAAC,SAAS,CACtB,CAAC;YAEF,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,wCAAwC,EAAE;gBAC3D,QAAQ;aACT,CAAC,CAAC;YAEH,OAAO,QAAQ,CAAC;QAClB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,iDAAiD,EAAE;gBACpE,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;gBAC7D,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS;aACjC,CAAC,CAAC;YACH,MAAM,KAAK,CAAC,CAAC,gCAAgC;QAC/C,CAAC;IACH,CAAC;CACF;AAzRD,gDAyRC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kya-os/mcp-i-runtime",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Shared product-runtime layer for the MCP-I framework (Node + Cloudflare adapters). Protocol types/values live in @kya-os/mcp (DIF).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Dylan Hobbs",
|
package/src/index.ts
CHANGED
|
@@ -138,6 +138,15 @@ export { ToolContextBuilder } from "./services/tool-context-builder";
|
|
|
138
138
|
|
|
139
139
|
export type { ToolContextBuilderConfig } from "./services/tool-context-builder";
|
|
140
140
|
|
|
141
|
+
// Auth-type satisfaction check (security fix: consent-approve auth-gate, Task B3)
|
|
142
|
+
// Consumed by the delegation-enforcement gates in agent.ts and
|
|
143
|
+
// tool-context-builder.ts to reject a delegation whose authorization type does
|
|
144
|
+
// not satisfy the tool's required type.
|
|
145
|
+
export {
|
|
146
|
+
authTypeSatisfies,
|
|
147
|
+
normalizeAuthType,
|
|
148
|
+
} from "./services/auth-type-satisfies";
|
|
149
|
+
|
|
141
150
|
// OAuth Provider Registry (Phase 2)
|
|
142
151
|
export { OAuthProviderRegistry } from "./services/oauth-provider-registry";
|
|
143
152
|
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for auth-type-satisfies
|
|
3
|
+
*
|
|
4
|
+
* Covers the strict-normalized-equality decision (locked 2026-07-29) for the
|
|
5
|
+
* consent-approve auth-gate security fix:
|
|
6
|
+
* - the demonstrated bug case (a `none` delegation must not satisfy a typed
|
|
7
|
+
* requirement)
|
|
8
|
+
* - happy-path equality across all canonical types
|
|
9
|
+
* - deprecated-alias folding (`oauth` -> `oauth2`, `credential` ->
|
|
10
|
+
* `verifiable_credential`)
|
|
11
|
+
* - non-interchangeability of distinct typed requirements
|
|
12
|
+
* - nullish/fail-safe handling on both sides
|
|
13
|
+
* - a full cross-product table across all 10 canonical authorization types
|
|
14
|
+
* (`AUTHORIZATION_TYPES`, contracts/src/tool-protection/index.ts ~88-106),
|
|
15
|
+
* checked against an independently-defined normalization oracle (not the
|
|
16
|
+
* implementation under test) so the table isn't tautological.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { describe, it, expect } from "vitest";
|
|
20
|
+
import { authTypeSatisfies, normalizeAuthType } from "../auth-type-satisfies";
|
|
21
|
+
|
|
22
|
+
describe("normalizeAuthType", () => {
|
|
23
|
+
it("returns undefined for undefined", () => {
|
|
24
|
+
expect(normalizeAuthType(undefined)).toBeUndefined();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("returns undefined for null", () => {
|
|
28
|
+
expect(normalizeAuthType(null)).toBeUndefined();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("returns undefined for an empty/whitespace-only string", () => {
|
|
32
|
+
expect(normalizeAuthType("")).toBeUndefined();
|
|
33
|
+
expect(normalizeAuthType(" ")).toBeUndefined();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("folds the deprecated 'oauth' alias to 'oauth2'", () => {
|
|
37
|
+
expect(normalizeAuthType("oauth")).toBe("oauth2");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("folds the deprecated 'credential' alias to 'verifiable_credential'", () => {
|
|
41
|
+
expect(normalizeAuthType("credential")).toBe("verifiable_credential");
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("leaves canonical types unchanged", () => {
|
|
45
|
+
expect(normalizeAuthType("oauth2")).toBe("oauth2");
|
|
46
|
+
expect(normalizeAuthType("password")).toBe("password");
|
|
47
|
+
expect(normalizeAuthType("mdl")).toBe("mdl");
|
|
48
|
+
expect(normalizeAuthType("idv")).toBe("idv");
|
|
49
|
+
expect(normalizeAuthType("verifiable_credential")).toBe(
|
|
50
|
+
"verifiable_credential"
|
|
51
|
+
);
|
|
52
|
+
expect(normalizeAuthType("webauthn")).toBe("webauthn");
|
|
53
|
+
expect(normalizeAuthType("siwe")).toBe("siwe");
|
|
54
|
+
expect(normalizeAuthType("apikey")).toBe("apikey");
|
|
55
|
+
expect(normalizeAuthType("none")).toBe("none");
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("trims and lowercases defensively", () => {
|
|
59
|
+
expect(normalizeAuthType(" Password ")).toBe("password");
|
|
60
|
+
expect(normalizeAuthType("OAUTH")).toBe("oauth2");
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe("authTypeSatisfies", () => {
|
|
65
|
+
describe("the bug case: a 'none' delegation must not satisfy a typed requirement", () => {
|
|
66
|
+
it('("none", "password") -> false', () => {
|
|
67
|
+
expect(authTypeSatisfies("none", "password")).toBe(false);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('("none", "oauth2") -> false', () => {
|
|
71
|
+
expect(authTypeSatisfies("none", "oauth2")).toBe(false);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe("happy pairs (strict equality)", () => {
|
|
76
|
+
it('("password", "password") -> true', () => {
|
|
77
|
+
expect(authTypeSatisfies("password", "password")).toBe(true);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('("oauth2", "oauth2") -> true', () => {
|
|
81
|
+
expect(authTypeSatisfies("oauth2", "oauth2")).toBe(true);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('("none", "none") -> true', () => {
|
|
85
|
+
expect(authTypeSatisfies("none", "none")).toBe(true);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('("apikey", "apikey") -> true', () => {
|
|
89
|
+
expect(authTypeSatisfies("apikey", "apikey")).toBe(true);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('("mdl", "mdl") -> true', () => {
|
|
93
|
+
expect(authTypeSatisfies("mdl", "mdl")).toBe(true);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('("idv", "idv") -> true', () => {
|
|
97
|
+
expect(authTypeSatisfies("idv", "idv")).toBe(true);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('("webauthn", "webauthn") -> true', () => {
|
|
101
|
+
expect(authTypeSatisfies("webauthn", "webauthn")).toBe(true);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('("siwe", "siwe") -> true', () => {
|
|
105
|
+
expect(authTypeSatisfies("siwe", "siwe")).toBe(true);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('("verifiable_credential", "verifiable_credential") -> true', () => {
|
|
109
|
+
expect(
|
|
110
|
+
authTypeSatisfies("verifiable_credential", "verifiable_credential")
|
|
111
|
+
).toBe(true);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
describe("alias folding", () => {
|
|
116
|
+
it('("oauth", "oauth2") -> true', () => {
|
|
117
|
+
expect(authTypeSatisfies("oauth", "oauth2")).toBe(true);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('("oauth2", "oauth") -> true', () => {
|
|
121
|
+
expect(authTypeSatisfies("oauth2", "oauth")).toBe(true);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('("oauth", "oauth") -> true', () => {
|
|
125
|
+
expect(authTypeSatisfies("oauth", "oauth")).toBe(true);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('("credential", "verifiable_credential") -> true', () => {
|
|
129
|
+
expect(authTypeSatisfies("credential", "verifiable_credential")).toBe(
|
|
130
|
+
true
|
|
131
|
+
);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('("verifiable_credential", "credential") -> true', () => {
|
|
135
|
+
expect(authTypeSatisfies("verifiable_credential", "credential")).toBe(
|
|
136
|
+
true
|
|
137
|
+
);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('("credential", "credential") -> true', () => {
|
|
141
|
+
expect(authTypeSatisfies("credential", "credential")).toBe(true);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
describe("non-interchangeable types (no stronger-satisfies-weaker lattice)", () => {
|
|
146
|
+
it('("oauth2", "password") -> false', () => {
|
|
147
|
+
expect(authTypeSatisfies("oauth2", "password")).toBe(false);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('("password", "oauth2") -> false', () => {
|
|
151
|
+
expect(authTypeSatisfies("password", "oauth2")).toBe(false);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('("verifiable_credential", "password") -> false', () => {
|
|
155
|
+
expect(authTypeSatisfies("verifiable_credential", "password")).toBe(
|
|
156
|
+
false
|
|
157
|
+
);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('("password", "none") -> false (typed delegation does not satisfy a none-gated tool either)', () => {
|
|
161
|
+
expect(authTypeSatisfies("password", "none")).toBe(false);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it('("apikey", "webauthn") -> false', () => {
|
|
165
|
+
expect(authTypeSatisfies("apikey", "webauthn")).toBe(false);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
describe("nullish / fail-safe handling", () => {
|
|
170
|
+
it('(undefined, "password") -> false', () => {
|
|
171
|
+
expect(authTypeSatisfies(undefined, "password")).toBe(false);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('(null, "password") -> false', () => {
|
|
175
|
+
expect(authTypeSatisfies(null, "password")).toBe(false);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('("password", undefined) -> false (documented rule: no requirement is not auto-satisfied)', () => {
|
|
179
|
+
expect(authTypeSatisfies("password", undefined)).toBe(false);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('("password", null) -> false', () => {
|
|
183
|
+
expect(authTypeSatisfies("password", null)).toBe(false);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it("(undefined, undefined) -> false", () => {
|
|
187
|
+
expect(authTypeSatisfies(undefined, undefined)).toBe(false);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('("", "password") -> false (empty string normalizes to undefined)', () => {
|
|
191
|
+
expect(authTypeSatisfies("", "password")).toBe(false);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('("none", undefined) -> false', () => {
|
|
195
|
+
expect(authTypeSatisfies("none", undefined)).toBe(false);
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
describe("full cross-product table across all 10 canonical types", () => {
|
|
200
|
+
// Independent normalization oracle (deliberately NOT importing
|
|
201
|
+
// normalizeAuthType) so this table verifies authTypeSatisfies's
|
|
202
|
+
// behavior rather than merely restating its own implementation.
|
|
203
|
+
const CANONICAL_NORMALIZED: Record<string, string> = {
|
|
204
|
+
oauth: "oauth2",
|
|
205
|
+
oauth2: "oauth2",
|
|
206
|
+
password: "password",
|
|
207
|
+
mdl: "mdl",
|
|
208
|
+
idv: "idv",
|
|
209
|
+
verifiable_credential: "verifiable_credential",
|
|
210
|
+
webauthn: "webauthn",
|
|
211
|
+
siwe: "siwe",
|
|
212
|
+
apikey: "apikey",
|
|
213
|
+
none: "none",
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
const ALL_TYPES = Object.keys(CANONICAL_NORMALIZED);
|
|
217
|
+
|
|
218
|
+
for (const delegationType of ALL_TYPES) {
|
|
219
|
+
for (const requiredType of ALL_TYPES) {
|
|
220
|
+
const expected =
|
|
221
|
+
CANONICAL_NORMALIZED[delegationType] ===
|
|
222
|
+
CANONICAL_NORMALIZED[requiredType];
|
|
223
|
+
|
|
224
|
+
it(`("${delegationType}", "${requiredType}") -> ${expected}`, () => {
|
|
225
|
+
expect(authTypeSatisfies(delegationType, requiredType)).toBe(
|
|
226
|
+
expected
|
|
227
|
+
);
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
});
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for ToolContextBuilder — delegation auth-type enforcement (Task B3)
|
|
3
|
+
*
|
|
4
|
+
* Security fix: consent-approve auth-gate (2026-07-29). These tests cover the
|
|
5
|
+
* delegation-only fallback in `buildContext` (the OAuth path), asserting that a
|
|
6
|
+
* delegation only authorizes a tool when its OWN authorization type satisfies
|
|
7
|
+
* the tool's required type.
|
|
8
|
+
*
|
|
9
|
+
* They exercise the exact enforcement gap that the demonstrated exploit rode:
|
|
10
|
+
* an anonymous consent-only (`none`) delegation must NOT satisfy an
|
|
11
|
+
* OAuth-gated tool. A legacy stored record with no persisted authorization type
|
|
12
|
+
* (undefined) is likewise rejected (fail-safe → re-challenge).
|
|
13
|
+
*
|
|
14
|
+
* The gate is reached only when no IDP token is stored but a delegation IS
|
|
15
|
+
* present, so every case here mocks `resolveTokenDataFromDid` → null.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
19
|
+
import { ToolContextBuilder } from "../tool-context-builder";
|
|
20
|
+
import type { IdpTokenResolver } from "../../identity/idp-token-resolver";
|
|
21
|
+
import type { OAuthConfigService } from "../oauth-config.service";
|
|
22
|
+
import type { ProviderResolver } from "../provider-resolver";
|
|
23
|
+
import type { ToolProtection } from "../../types/tool-protection";
|
|
24
|
+
import { OAuthRequiredError } from "../../types/oauth-required-error";
|
|
25
|
+
|
|
26
|
+
describe("ToolContextBuilder — delegation auth-type enforcement (B3)", () => {
|
|
27
|
+
let mockTokenResolver: IdpTokenResolver;
|
|
28
|
+
let mockConfigService: OAuthConfigService;
|
|
29
|
+
let mockProviderResolver: ProviderResolver;
|
|
30
|
+
let builder: ToolContextBuilder;
|
|
31
|
+
|
|
32
|
+
// OAuth-gated tool: resolveProvider is mocked, so the concrete provider is
|
|
33
|
+
// irrelevant — only the required authorization.type drives the gate.
|
|
34
|
+
const oauthTool: ToolProtection = {
|
|
35
|
+
requiresDelegation: true,
|
|
36
|
+
requiredScopes: ["read:user"],
|
|
37
|
+
authorization: { type: "oauth2", provider: "github" },
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// Legacy OAuth tool: no explicit authorization.type, provider resolved from
|
|
41
|
+
// the deprecated oauthProvider field. The gate falls back to "oauth2".
|
|
42
|
+
const legacyOauthTool: ToolProtection = {
|
|
43
|
+
requiresDelegation: true,
|
|
44
|
+
requiredScopes: ["read:user"],
|
|
45
|
+
oauthProvider: "github",
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
beforeEach(() => {
|
|
49
|
+
mockTokenResolver = {
|
|
50
|
+
// No stored IDP token → force the delegation-only fallback path.
|
|
51
|
+
resolveTokenDataFromDid: vi.fn().mockResolvedValue(null),
|
|
52
|
+
} as unknown as IdpTokenResolver;
|
|
53
|
+
|
|
54
|
+
mockConfigService = {
|
|
55
|
+
getOAuthConfig: vi.fn(),
|
|
56
|
+
} as unknown as OAuthConfigService;
|
|
57
|
+
|
|
58
|
+
mockProviderResolver = {
|
|
59
|
+
resolveProvider: vi.fn().mockResolvedValue("github"),
|
|
60
|
+
} as unknown as ProviderResolver;
|
|
61
|
+
|
|
62
|
+
builder = new ToolContextBuilder({
|
|
63
|
+
tokenResolver: mockTokenResolver,
|
|
64
|
+
configService: mockConfigService,
|
|
65
|
+
providerResolver: mockProviderResolver,
|
|
66
|
+
projectId: "proj-123",
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("REJECTS a `none`-type delegation for an oauth-gated tool (the exploit)", async () => {
|
|
71
|
+
await expect(
|
|
72
|
+
builder.buildContext(
|
|
73
|
+
"gated-tool",
|
|
74
|
+
"did:key:z6MkUser",
|
|
75
|
+
"session-123",
|
|
76
|
+
"delegation-token-anon",
|
|
77
|
+
oauthTool,
|
|
78
|
+
"none" // anonymous consent-only delegation
|
|
79
|
+
)
|
|
80
|
+
).rejects.toThrow(OAuthRequiredError);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("REJECTS a `password`-type delegation for an oauth-gated tool (cross-type)", async () => {
|
|
84
|
+
await expect(
|
|
85
|
+
builder.buildContext(
|
|
86
|
+
"gated-tool",
|
|
87
|
+
"did:key:z6MkUser",
|
|
88
|
+
"session-123",
|
|
89
|
+
"delegation-token-pw",
|
|
90
|
+
oauthTool,
|
|
91
|
+
"password"
|
|
92
|
+
)
|
|
93
|
+
).rejects.toThrow(OAuthRequiredError);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("REJECTS an undefined-type (legacy record) delegation for a typed tool", async () => {
|
|
97
|
+
await expect(
|
|
98
|
+
builder.buildContext(
|
|
99
|
+
"gated-tool",
|
|
100
|
+
"did:key:z6MkUser",
|
|
101
|
+
"session-123",
|
|
102
|
+
"delegation-token-legacy",
|
|
103
|
+
oauthTool,
|
|
104
|
+
undefined // predates persisting authorizationType → fail-safe
|
|
105
|
+
)
|
|
106
|
+
).rejects.toThrow(OAuthRequiredError);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("ACCEPTS an `oauth2`-type delegation for an oauth2-gated tool (happy path)", async () => {
|
|
110
|
+
const result = await builder.buildContext(
|
|
111
|
+
"gated-tool",
|
|
112
|
+
"did:key:z6MkUser",
|
|
113
|
+
"session-123",
|
|
114
|
+
"delegation-token-oauth",
|
|
115
|
+
oauthTool,
|
|
116
|
+
"oauth2"
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
expect(result).toBeDefined();
|
|
120
|
+
expect(result!.delegationToken).toBe("delegation-token-oauth");
|
|
121
|
+
expect(result!.provider).toBe("github");
|
|
122
|
+
expect(result!.userDid).toBe("did:key:z6MkUser");
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("ACCEPTS an `oauth` (deprecated alias) delegation for an oauth2-gated tool", async () => {
|
|
126
|
+
const result = await builder.buildContext(
|
|
127
|
+
"gated-tool",
|
|
128
|
+
"did:key:z6MkUser",
|
|
129
|
+
"session-123",
|
|
130
|
+
"delegation-token-oauth-alias",
|
|
131
|
+
oauthTool,
|
|
132
|
+
"oauth" // normalizes to oauth2
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
expect(result).toBeDefined();
|
|
136
|
+
expect(result!.delegationToken).toBe("delegation-token-oauth-alias");
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("ACCEPTS an `oauth2` delegation for a legacy oauthProvider-only tool (fallback)", async () => {
|
|
140
|
+
// authorization.type is absent → gate falls back to "oauth2"; a genuine
|
|
141
|
+
// OAuth delegation must still authorize such tools (no regression).
|
|
142
|
+
const result = await builder.buildContext(
|
|
143
|
+
"gated-tool",
|
|
144
|
+
"did:key:z6MkUser",
|
|
145
|
+
"session-123",
|
|
146
|
+
"delegation-token-oauth",
|
|
147
|
+
legacyOauthTool,
|
|
148
|
+
"oauth2"
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
expect(result).toBeDefined();
|
|
152
|
+
expect(result!.delegationToken).toBe("delegation-token-oauth");
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it("REJECTS a `none` delegation for a legacy oauthProvider-only tool", async () => {
|
|
156
|
+
await expect(
|
|
157
|
+
builder.buildContext(
|
|
158
|
+
"gated-tool",
|
|
159
|
+
"did:key:z6MkUser",
|
|
160
|
+
"session-123",
|
|
161
|
+
"delegation-token-anon",
|
|
162
|
+
legacyOauthTool,
|
|
163
|
+
"none"
|
|
164
|
+
)
|
|
165
|
+
).rejects.toThrow(OAuthRequiredError);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auth-Type Satisfaction Check
|
|
3
|
+
*
|
|
4
|
+
* Pure comparison used by the delegation-enforcement gate (security fix:
|
|
5
|
+
* consent-approve auth-gate, 2026-07-29, Task B3) to decide whether a
|
|
6
|
+
* delegation's authorization type satisfies a tool's required authorization
|
|
7
|
+
* type.
|
|
8
|
+
*
|
|
9
|
+
* Background: a gated MCP tool call is authorized by presenting a
|
|
10
|
+
* delegation. A bug let a delegation of ANY auth type satisfy a tool that
|
|
11
|
+
* requires a specific type — e.g. an anonymous consent-only (`none`)
|
|
12
|
+
* delegation wrongly satisfied a `password`-gated tool, because call-time
|
|
13
|
+
* enforcement accepted any present delegation without checking its
|
|
14
|
+
* `authorization.type`. This module implements the comparison that closes
|
|
15
|
+
* that gap. Wiring it into the enforcement sites (`agent.ts`,
|
|
16
|
+
* `tool-context-builder.ts`) is a later task (B3) — this module is
|
|
17
|
+
* intentionally standalone and unused by any gate yet.
|
|
18
|
+
*
|
|
19
|
+
* Decision (locked by product owner, 2026-07-29): STRICT NORMALIZED
|
|
20
|
+
* EQUALITY. A delegation type satisfies a required type iff, after folding
|
|
21
|
+
* deprecated aliases, they are equal. There is no "stronger satisfies
|
|
22
|
+
* weaker" lattice — `oauth`/`oauth2` and `password` are NOT interchangeable,
|
|
23
|
+
* and a `password` delegation does NOT satisfy a `none`-gated tool (or vice
|
|
24
|
+
* versa).
|
|
25
|
+
*
|
|
26
|
+
* @module @kya-os/mcp-i-runtime/services/auth-type-satisfies
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Fold deprecated authorization-type aliases to their canonical form and
|
|
31
|
+
* normalize casing/whitespace.
|
|
32
|
+
*
|
|
33
|
+
* Alias rules mirror `normalizeAuthorizationType` in
|
|
34
|
+
* `packages/contracts/src/tool-protection/index.ts` (~774): `oauth` folds to
|
|
35
|
+
* `oauth2`, `credential` folds to `verifiable_credential`. That function
|
|
36
|
+
* operates on a full `AuthorizationRequirement` object and emits a
|
|
37
|
+
* deprecation warning on every call; this is a bare-string equivalent for
|
|
38
|
+
* use at the enforcement gate, where only the stored/required type strings
|
|
39
|
+
* — not the full requirement object — are available, and where a warning
|
|
40
|
+
* log on every tool call would be noise. (Not reusing the alias mapping
|
|
41
|
+
* directly from `@kya-os/contracts` here — it is not exposed as a
|
|
42
|
+
* standalone string-keyed map, only baked into that function's control
|
|
43
|
+
* flow — so the two rules are mirrored inline per the task's fallback
|
|
44
|
+
* guidance.)
|
|
45
|
+
*
|
|
46
|
+
* Canonical types (`AUTHORIZATION_TYPES`, contracts/src/tool-protection/index.ts
|
|
47
|
+
* ~88-106) are stored as lowercase string consts (e.g. "password", "oauth2",
|
|
48
|
+
* "none"), so normalization here only needs to trim and lowercase for
|
|
49
|
+
* defensive consistency — it does not need to handle differently-cased
|
|
50
|
+
* input from any known caller today.
|
|
51
|
+
*
|
|
52
|
+
* @param type - Raw authorization type string, or nullish if unknown/missing.
|
|
53
|
+
* @returns The normalized type string, or `undefined` if `type` is nullish or
|
|
54
|
+
* empty/whitespace-only after trimming.
|
|
55
|
+
*/
|
|
56
|
+
export function normalizeAuthType(
|
|
57
|
+
type: string | undefined | null
|
|
58
|
+
): string | undefined {
|
|
59
|
+
if (type === undefined || type === null) {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const trimmed = type.trim().toLowerCase();
|
|
64
|
+
if (trimmed === "") {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Deprecated alias -> canonical (mirrors normalizeAuthorizationType).
|
|
69
|
+
if (trimmed === "oauth") {
|
|
70
|
+
return "oauth2";
|
|
71
|
+
}
|
|
72
|
+
if (trimmed === "credential") {
|
|
73
|
+
return "verifiable_credential";
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return trimmed;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Decide whether a delegation's authorization type satisfies a tool's
|
|
81
|
+
* required authorization type.
|
|
82
|
+
*
|
|
83
|
+
* Strict normalized equality (locked decision, see module docs above): both
|
|
84
|
+
* types are normalized (alias-folded, trimmed, lowercased) and then compared
|
|
85
|
+
* for exact equality. There is no cross-type satisfaction — a `password`
|
|
86
|
+
* delegation does NOT satisfy an `oauth2`-gated tool, and (by the same
|
|
87
|
+
* strict rule) does NOT satisfy a `none`-gated tool either.
|
|
88
|
+
*
|
|
89
|
+
* Note on `none`-required tools: per strict equality, only a `none`
|
|
90
|
+
* delegation satisfies a `none` requirement. In practice, a tool requiring
|
|
91
|
+
* `none` (consent-only) is not expected to reach this call today — it is
|
|
92
|
+
* rejected earlier, before the delegation-presence gate, by
|
|
93
|
+
* `ConsentOnlyModeError` (see `provider-resolver.ts`) — so this function is
|
|
94
|
+
* expected to be invoked only for TYPED requirements (`password`, `oauth2`,
|
|
95
|
+
* `apikey`, etc.). Strict equality is still implemented faithfully for
|
|
96
|
+
* `none` in case that assumption ever changes.
|
|
97
|
+
*
|
|
98
|
+
* Fail-safe rules (both nullish cases return `false`, never `true`):
|
|
99
|
+
* - If `delegationType` is nullish (missing on a legacy stored record that
|
|
100
|
+
* predates persisting `authorizationType`, or simply absent), this
|
|
101
|
+
* returns `false` regardless of `requiredType` — an unknown/unrecorded
|
|
102
|
+
* delegation type never satisfies a typed requirement.
|
|
103
|
+
* - If `requiredType` is nullish (or normalizes to empty), there is no
|
|
104
|
+
* requirement to compare against. Callers are not expected to invoke this
|
|
105
|
+
* with a nullish `requiredType` (a tool with no authorization requirement
|
|
106
|
+
* doesn't reach this gate), but this fails safe to `false` rather than
|
|
107
|
+
* treating "no requirement" as automatically satisfied.
|
|
108
|
+
*
|
|
109
|
+
* @param delegationType - The delegation's stored/asserted authorization
|
|
110
|
+
* type (e.g. from `getDelegationFromStorage`), or nullish if unknown.
|
|
111
|
+
* @param requiredType - The tool's required authorization type (e.g.
|
|
112
|
+
* `protection.authorization.type`), or nullish.
|
|
113
|
+
* @returns `true` iff both types are present and equal after normalization.
|
|
114
|
+
*/
|
|
115
|
+
export function authTypeSatisfies(
|
|
116
|
+
delegationType: string | undefined | null,
|
|
117
|
+
requiredType: string | undefined | null
|
|
118
|
+
): boolean {
|
|
119
|
+
const normalizedDelegationType = normalizeAuthType(delegationType);
|
|
120
|
+
if (normalizedDelegationType === undefined) {
|
|
121
|
+
// Fail-safe: an unknown/missing delegation type never satisfies a
|
|
122
|
+
// requirement, typed or not.
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const normalizedRequiredType = normalizeAuthType(requiredType);
|
|
127
|
+
if (normalizedRequiredType === undefined) {
|
|
128
|
+
// Fail-safe: no requirement to satisfy is not treated as "anything
|
|
129
|
+
// satisfies it".
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return normalizedDelegationType === normalizedRequiredType;
|
|
134
|
+
}
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
ConsentOnlyModeError,
|
|
22
22
|
CredentialAuthModeError,
|
|
23
23
|
} from "./provider-resolver.js";
|
|
24
|
+
import { authTypeSatisfies } from "./auth-type-satisfies.js";
|
|
24
25
|
|
|
25
26
|
export interface ToolContextBuilderConfig {
|
|
26
27
|
/** IDP token resolver for resolving tokens from User DID */
|
|
@@ -69,6 +70,11 @@ export class ToolContextBuilder {
|
|
|
69
70
|
* @param sessionId - Session ID (optional)
|
|
70
71
|
* @param delegationToken - Delegation token (optional)
|
|
71
72
|
* @param toolProtection - Tool protection configuration (optional)
|
|
73
|
+
* @param delegationAuthorizationType - The stored authorization type of the
|
|
74
|
+
* presented delegation (from `getDelegationFromStorage`), or undefined for
|
|
75
|
+
* legacy records that predate persisting it. Used by the delegation-only
|
|
76
|
+
* fallback below to reject a delegation whose type does not satisfy the
|
|
77
|
+
* tool's required type (security fix: consent-approve auth-gate, Task B3).
|
|
72
78
|
* @returns Tool execution context or undefined if not needed
|
|
73
79
|
*/
|
|
74
80
|
async buildContext(
|
|
@@ -76,7 +82,8 @@ export class ToolContextBuilder {
|
|
|
76
82
|
userDid: string | undefined,
|
|
77
83
|
sessionId: string | undefined,
|
|
78
84
|
delegationToken: string | undefined,
|
|
79
|
-
toolProtection: ToolProtection | null
|
|
85
|
+
toolProtection: ToolProtection | null,
|
|
86
|
+
delegationAuthorizationType?: string
|
|
80
87
|
): Promise<ToolExecutionContext | undefined> {
|
|
81
88
|
// Only build context if tool requires OAuth/credentials
|
|
82
89
|
if (!toolProtection?.requiredScopes?.length || !userDid) {
|
|
@@ -127,14 +134,34 @@ export class ToolContextBuilder {
|
|
|
127
134
|
// IDP token not available - check if delegation token exists
|
|
128
135
|
// If delegation exists, tool can still execute without IDP token
|
|
129
136
|
// (the tool handler should check for idpToken if it needs external API access)
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
137
|
+
//
|
|
138
|
+
// SECURITY (consent-approve auth-gate, Task B3): a delegation only
|
|
139
|
+
// authorizes this tool if its OWN authorization type satisfies the tool's
|
|
140
|
+
// required type. Reaching this OAuth context builder means the tool is
|
|
141
|
+
// neither consent-only (`none`) nor password — those throw
|
|
142
|
+
// ConsentOnlyModeError / CredentialAuthModeError inside resolveProvider,
|
|
143
|
+
// BEFORE this point — so the effective requirement is OAuth. Fall back to
|
|
144
|
+
// "oauth2" only when the tool omits an explicit authorization.type (legacy
|
|
145
|
+
// oauthProvider-only config); this keeps such tools working while a
|
|
146
|
+
// mismatched delegation (e.g. an anonymous `none` consent-only delegation,
|
|
147
|
+
// or a legacy record with no persisted type → undefined) is rejected. On
|
|
148
|
+
// mismatch we do NOT return the delegation-only context; we fall through
|
|
149
|
+
// to OAuthRequiredError so the tool re-challenges.
|
|
150
|
+
const requiredAuthType = toolProtection.authorization?.type ?? "oauth2";
|
|
151
|
+
if (
|
|
152
|
+
delegationToken &&
|
|
153
|
+
authTypeSatisfies(delegationAuthorizationType, requiredAuthType)
|
|
154
|
+
) {
|
|
155
|
+
this.config.logger(
|
|
156
|
+
"[ToolContextBuilder] IDP token not found, but delegation exists - returning minimal context",
|
|
157
|
+
{
|
|
158
|
+
toolName,
|
|
159
|
+
userDid: userDid.substring(0, 20) + "...",
|
|
160
|
+
provider,
|
|
161
|
+
scopes: toolProtection.requiredScopes,
|
|
162
|
+
note: "Tool can execute with delegation-only authorization",
|
|
163
|
+
}
|
|
164
|
+
);
|
|
138
165
|
|
|
139
166
|
// Return minimal context with delegation info
|
|
140
167
|
// Tools that need IDP token for external API calls should check for idpToken
|
|
@@ -147,13 +174,31 @@ export class ToolContextBuilder {
|
|
|
147
174
|
};
|
|
148
175
|
}
|
|
149
176
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
177
|
+
if (delegationToken) {
|
|
178
|
+
// A delegation WAS presented but its authorization type does not satisfy
|
|
179
|
+
// the tool's required type — log and re-challenge instead of authorizing.
|
|
180
|
+
this.config.logger(
|
|
181
|
+
"[ToolContextBuilder] Delegation present but auth-type does not satisfy tool requirement - re-challenging",
|
|
182
|
+
{
|
|
183
|
+
toolName,
|
|
184
|
+
userDid: userDid.substring(0, 20) + "...",
|
|
185
|
+
provider,
|
|
186
|
+
requiredAuthType,
|
|
187
|
+
delegationAuthorizationType: delegationAuthorizationType ?? null,
|
|
188
|
+
}
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// No (satisfying) delegation token - throw OAuthRequiredError to trigger auth flow
|
|
193
|
+
this.config.logger(
|
|
194
|
+
"[ToolContextBuilder] Token not available, throwing OAuthRequiredError",
|
|
195
|
+
{
|
|
196
|
+
toolName,
|
|
197
|
+
userDid: userDid.substring(0, 20) + "...",
|
|
198
|
+
provider,
|
|
199
|
+
scopes: toolProtection.requiredScopes,
|
|
200
|
+
}
|
|
201
|
+
);
|
|
157
202
|
|
|
158
203
|
// Throw error with provider and scopes info
|
|
159
204
|
// Auth URL will be built by the Cloudflare layer (agent.ts)
|
|
@@ -210,7 +255,9 @@ export class ToolContextBuilder {
|
|
|
210
255
|
* @param tokenData - Token data with usage metadata
|
|
211
256
|
* @returns Headers object for API calls
|
|
212
257
|
*/
|
|
213
|
-
private buildAuthHeaders(
|
|
258
|
+
private buildAuthHeaders(
|
|
259
|
+
tokenData: IdpTokensWithMetadata
|
|
260
|
+
): Record<string, string> {
|
|
214
261
|
const authHeaders: Record<string, string> = {};
|
|
215
262
|
|
|
216
263
|
const tokenUsage = tokenData.tokenUsage || "bearer"; // Default to bearer for OAuth
|
|
@@ -282,4 +329,3 @@ export class ToolContextBuilder {
|
|
|
282
329
|
}
|
|
283
330
|
}
|
|
284
331
|
}
|
|
285
|
-
|