@kya-os/mcp-i-cloudflare 1.17.0 → 1.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (268) hide show
  1. package/README.md +273 -54
  2. package/dist/adapter.d.ts +3 -17
  3. package/dist/adapter.d.ts.map +1 -1
  4. package/dist/adapter.js +39 -477
  5. package/dist/adapter.js.map +1 -1
  6. package/dist/agent.d.ts +59 -35
  7. package/dist/agent.d.ts.map +1 -1
  8. package/dist/agent.js +386 -404
  9. package/dist/agent.js.map +1 -1
  10. package/dist/app.d.ts.map +1 -1
  11. package/dist/app.js +150 -94
  12. package/dist/app.js.map +1 -1
  13. package/dist/audit/deployment-binding.d.ts +16 -16
  14. package/dist/authority-outcome.d.ts +110 -0
  15. package/dist/authority-outcome.d.ts.map +1 -0
  16. package/dist/authority-outcome.js +154 -0
  17. package/dist/authority-outcome.js.map +1 -0
  18. package/dist/config.d.ts +8 -77
  19. package/dist/config.d.ts.map +1 -1
  20. package/dist/config.js +0 -83
  21. package/dist/config.js.map +1 -1
  22. package/dist/delegation-http/bearer-retry.d.ts +84 -32
  23. package/dist/delegation-http/bearer-retry.d.ts.map +1 -1
  24. package/dist/delegation-http/bearer-retry.js +124 -139
  25. package/dist/delegation-http/bearer-retry.js.map +1 -1
  26. package/dist/delegation-http/connect-gate.d.ts +47 -0
  27. package/dist/delegation-http/connect-gate.d.ts.map +1 -0
  28. package/dist/delegation-http/connect-gate.js +104 -0
  29. package/dist/delegation-http/connect-gate.js.map +1 -0
  30. package/dist/delegation-http/constants.d.ts +4 -49
  31. package/dist/delegation-http/constants.d.ts.map +1 -1
  32. package/dist/delegation-http/constants.js +4 -58
  33. package/dist/delegation-http/constants.js.map +1 -1
  34. package/dist/delegation-http/issuer-binding.d.ts +26 -0
  35. package/dist/delegation-http/issuer-binding.d.ts.map +1 -0
  36. package/dist/delegation-http/issuer-binding.js +51 -0
  37. package/dist/delegation-http/issuer-binding.js.map +1 -0
  38. package/dist/delegation-http/lazy-auth-gate.d.ts +88 -0
  39. package/dist/delegation-http/lazy-auth-gate.d.ts.map +1 -0
  40. package/dist/delegation-http/lazy-auth-gate.js +203 -0
  41. package/dist/delegation-http/lazy-auth-gate.js.map +1 -0
  42. package/dist/delegation-http/native-challenge.d.ts +52 -0
  43. package/dist/delegation-http/native-challenge.d.ts.map +1 -0
  44. package/dist/delegation-http/native-challenge.js +124 -0
  45. package/dist/delegation-http/native-challenge.js.map +1 -0
  46. package/dist/delegation-http/native-consent-redirect.d.ts +21 -0
  47. package/dist/delegation-http/native-consent-redirect.d.ts.map +1 -0
  48. package/dist/delegation-http/native-consent-redirect.js +43 -0
  49. package/dist/delegation-http/native-consent-redirect.js.map +1 -0
  50. package/dist/delegation-http/native-http.d.ts +1 -86
  51. package/dist/delegation-http/native-http.d.ts.map +1 -1
  52. package/dist/delegation-http/native-http.js +2 -130
  53. package/dist/delegation-http/native-http.js.map +1 -1
  54. package/dist/delegation-http/native-oauth-state-do.d.ts +13 -35
  55. package/dist/delegation-http/native-oauth-state-do.d.ts.map +1 -1
  56. package/dist/delegation-http/native-oauth-state-do.js +10 -165
  57. package/dist/delegation-http/native-oauth-state-do.js.map +1 -1
  58. package/dist/delegation-http/protected-resource.d.ts +37 -0
  59. package/dist/delegation-http/protected-resource.d.ts.map +1 -0
  60. package/dist/delegation-http/protected-resource.js +43 -0
  61. package/dist/delegation-http/protected-resource.js.map +1 -0
  62. package/dist/delegation-http/request-proof.d.ts +20 -0
  63. package/dist/delegation-http/request-proof.d.ts.map +1 -0
  64. package/dist/delegation-http/request-proof.js +29 -0
  65. package/dist/delegation-http/request-proof.js.map +1 -0
  66. package/dist/delegation-http/sid.d.ts +4 -12
  67. package/dist/delegation-http/sid.d.ts.map +1 -1
  68. package/dist/delegation-http/sid.js +4 -19
  69. package/dist/delegation-http/sid.js.map +1 -1
  70. package/dist/delegation-http/well-known-capability.d.ts +8 -12
  71. package/dist/delegation-http/well-known-capability.d.ts.map +1 -1
  72. package/dist/delegation-http/well-known-capability.js +9 -18
  73. package/dist/delegation-http/well-known-capability.js.map +1 -1
  74. package/dist/helpers/env-mapper.d.ts.map +1 -1
  75. package/dist/helpers/env-mapper.js +7 -29
  76. package/dist/helpers/env-mapper.js.map +1 -1
  77. package/dist/index.d.ts +2 -4
  78. package/dist/index.d.ts.map +1 -1
  79. package/dist/index.js +11 -8
  80. package/dist/index.js.map +1 -1
  81. package/dist/proof-generator.d.ts +24 -17
  82. package/dist/proof-generator.d.ts.map +1 -1
  83. package/dist/proof-generator.js +42 -56
  84. package/dist/proof-generator.js.map +1 -1
  85. package/dist/runtime/amount-limit-refusal.d.ts +3 -0
  86. package/dist/runtime/amount-limit-refusal.d.ts.map +1 -0
  87. package/dist/runtime/amount-limit-refusal.js +7 -0
  88. package/dist/runtime/amount-limit-refusal.js.map +1 -0
  89. package/dist/runtime/oauth-handler.d.ts +1 -1
  90. package/dist/runtime/oauth-handler.d.ts.map +1 -1
  91. package/dist/runtime/oauth-handler.js +31 -34
  92. package/dist/runtime/oauth-handler.js.map +1 -1
  93. package/dist/runtime.d.ts +34 -10
  94. package/dist/runtime.d.ts.map +1 -1
  95. package/dist/runtime.js +65 -16
  96. package/dist/runtime.js.map +1 -1
  97. package/dist/security/admission-refusal.d.ts +3 -3
  98. package/dist/security/admission-refusal.d.ts.map +1 -1
  99. package/dist/security/admission-refusal.js +14 -6
  100. package/dist/security/admission-refusal.js.map +1 -1
  101. package/dist/security/holder-binding.d.ts +34 -0
  102. package/dist/security/holder-binding.d.ts.map +1 -0
  103. package/dist/security/holder-binding.js +75 -0
  104. package/dist/security/holder-binding.js.map +1 -0
  105. package/dist/security/mcp-admission.d.ts +29 -1
  106. package/dist/security/mcp-admission.d.ts.map +1 -1
  107. package/dist/security/mcp-admission.js +78 -12
  108. package/dist/security/mcp-admission.js.map +1 -1
  109. package/dist/security/native-holder-admission.d.ts +39 -0
  110. package/dist/security/native-holder-admission.d.ts.map +1 -0
  111. package/dist/security/native-holder-admission.js +65 -0
  112. package/dist/security/native-holder-admission.js.map +1 -0
  113. package/dist/security/outcome-proof.d.ts +39 -0
  114. package/dist/security/outcome-proof.d.ts.map +1 -0
  115. package/dist/security/outcome-proof.js +54 -0
  116. package/dist/security/outcome-proof.js.map +1 -0
  117. package/dist/security/request-nonce-store.d.ts +43 -0
  118. package/dist/security/request-nonce-store.d.ts.map +1 -0
  119. package/dist/security/request-nonce-store.js +129 -0
  120. package/dist/security/request-nonce-store.js.map +1 -0
  121. package/dist/security/routed-request.d.ts +41 -0
  122. package/dist/security/routed-request.d.ts.map +1 -0
  123. package/dist/security/routed-request.js +86 -0
  124. package/dist/security/routed-request.js.map +1 -0
  125. package/dist/security/sign-in-amr.d.ts +23 -0
  126. package/dist/security/sign-in-amr.d.ts.map +1 -0
  127. package/dist/security/sign-in-amr.js +44 -0
  128. package/dist/security/sign-in-amr.js.map +1 -0
  129. package/dist/services/approval-route.d.ts +3 -2
  130. package/dist/services/approval-route.d.ts.map +1 -1
  131. package/dist/services/approval-route.js.map +1 -1
  132. package/dist/services/checkpoint-decision.d.ts +56 -0
  133. package/dist/services/checkpoint-decision.d.ts.map +1 -0
  134. package/dist/services/checkpoint-decision.js +109 -0
  135. package/dist/services/checkpoint-decision.js.map +1 -0
  136. package/dist/services/consent-page-renderer.d.ts.map +1 -1
  137. package/dist/services/consent-page-renderer.js +2 -3
  138. package/dist/services/consent-page-renderer.js.map +1 -1
  139. package/dist/services/consent.service.d.ts +11 -49
  140. package/dist/services/consent.service.d.ts.map +1 -1
  141. package/dist/services/consent.service.js +81 -307
  142. package/dist/services/consent.service.js.map +1 -1
  143. package/dist/services/credential-auth.handler.d.ts.map +1 -1
  144. package/dist/services/credential-auth.handler.js +2 -8
  145. package/dist/services/credential-auth.handler.js.map +1 -1
  146. package/dist/services/delegation-authority.d.ts +53 -0
  147. package/dist/services/delegation-authority.d.ts.map +1 -0
  148. package/dist/services/delegation-authority.js +130 -0
  149. package/dist/services/delegation-authority.js.map +1 -0
  150. package/dist/services/delegation-trust.d.ts +35 -64
  151. package/dist/services/delegation-trust.d.ts.map +1 -1
  152. package/dist/services/delegation-trust.js +98 -279
  153. package/dist/services/delegation-trust.js.map +1 -1
  154. package/dist/services/delegation.service.d.ts +83 -105
  155. package/dist/services/delegation.service.d.ts.map +1 -1
  156. package/dist/services/delegation.service.js +166 -518
  157. package/dist/services/delegation.service.js.map +1 -1
  158. package/dist/services/idp-token-storage.d.ts +32 -12
  159. package/dist/services/idp-token-storage.d.ts.map +1 -1
  160. package/dist/services/idp-token-storage.js +79 -36
  161. package/dist/services/idp-token-storage.js.map +1 -1
  162. package/dist/services/issuer-keys.d.ts +55 -0
  163. package/dist/services/issuer-keys.d.ts.map +1 -0
  164. package/dist/services/issuer-keys.js +184 -0
  165. package/dist/services/issuer-keys.js.map +1 -0
  166. package/dist/services/oauth-security.service.d.ts +17 -1
  167. package/dist/services/oauth-security.service.d.ts.map +1 -1
  168. package/dist/services/oauth-security.service.js +29 -10
  169. package/dist/services/oauth-security.service.js.map +1 -1
  170. package/dist/services/proof.service.d.ts +10 -0
  171. package/dist/services/proof.service.d.ts.map +1 -1
  172. package/dist/services/proof.service.js +28 -6
  173. package/dist/services/proof.service.js.map +1 -1
  174. package/dist/services/resource-audience.d.ts +12 -9
  175. package/dist/services/resource-audience.d.ts.map +1 -1
  176. package/dist/services/resource-audience.js +12 -9
  177. package/dist/services/resource-audience.js.map +1 -1
  178. package/dist/services/unenforceable-tool-protection.d.ts +32 -0
  179. package/dist/services/unenforceable-tool-protection.d.ts.map +1 -0
  180. package/dist/services/unenforceable-tool-protection.js +90 -0
  181. package/dist/services/unenforceable-tool-protection.js.map +1 -0
  182. package/dist/services/upstream-fetch.d.ts +14 -0
  183. package/dist/services/upstream-fetch.d.ts.map +1 -0
  184. package/dist/services/upstream-fetch.js +56 -0
  185. package/dist/services/upstream-fetch.js.map +1 -0
  186. package/dist/types.d.ts +5 -18
  187. package/dist/types.d.ts.map +1 -1
  188. package/dist/utils/oauth-profile.d.ts +19 -0
  189. package/dist/utils/oauth-profile.d.ts.map +1 -1
  190. package/dist/utils/oauth-profile.js +54 -1
  191. package/dist/utils/oauth-profile.js.map +1 -1
  192. package/dist/utils/tool-security-schemes.d.ts +65 -0
  193. package/dist/utils/tool-security-schemes.d.ts.map +1 -0
  194. package/dist/utils/tool-security-schemes.js +168 -0
  195. package/dist/utils/tool-security-schemes.js.map +1 -0
  196. package/package.json +5 -6
  197. package/dist/delegation-http/anchor-do.d.ts +0 -84
  198. package/dist/delegation-http/anchor-do.d.ts.map +0 -1
  199. package/dist/delegation-http/anchor-do.js +0 -412
  200. package/dist/delegation-http/anchor-do.js.map +0 -1
  201. package/dist/delegation-http/anchor-registration-validate.d.ts +0 -61
  202. package/dist/delegation-http/anchor-registration-validate.d.ts.map +0 -1
  203. package/dist/delegation-http/anchor-registration-validate.js +0 -191
  204. package/dist/delegation-http/anchor-registration-validate.js.map +0 -1
  205. package/dist/delegation-http/anchor-registration.d.ts +0 -62
  206. package/dist/delegation-http/anchor-registration.d.ts.map +0 -1
  207. package/dist/delegation-http/anchor-registration.js +0 -337
  208. package/dist/delegation-http/anchor-registration.js.map +0 -1
  209. package/dist/delegation-http/anchor-routing.d.ts +0 -20
  210. package/dist/delegation-http/anchor-routing.d.ts.map +0 -1
  211. package/dist/delegation-http/anchor-routing.js +0 -27
  212. package/dist/delegation-http/anchor-routing.js.map +0 -1
  213. package/dist/delegation-http/challenge-middleware.d.ts +0 -28
  214. package/dist/delegation-http/challenge-middleware.d.ts.map +0 -1
  215. package/dist/delegation-http/challenge-middleware.js +0 -190
  216. package/dist/delegation-http/challenge-middleware.js.map +0 -1
  217. package/dist/delegation-http/challenge.d.ts +0 -102
  218. package/dist/delegation-http/challenge.d.ts.map +0 -1
  219. package/dist/delegation-http/challenge.js +0 -223
  220. package/dist/delegation-http/challenge.js.map +0 -1
  221. package/dist/delegation-http/consent-anchor-bridge.d.ts +0 -70
  222. package/dist/delegation-http/consent-anchor-bridge.d.ts.map +0 -1
  223. package/dist/delegation-http/consent-anchor-bridge.js +0 -1130
  224. package/dist/delegation-http/consent-anchor-bridge.js.map +0 -1
  225. package/dist/delegation-http/consent-preparation-page.d.ts +0 -18
  226. package/dist/delegation-http/consent-preparation-page.d.ts.map +0 -1
  227. package/dist/delegation-http/consent-preparation-page.js +0 -172
  228. package/dist/delegation-http/consent-preparation-page.js.map +0 -1
  229. package/dist/delegation-http/credential-consent.d.ts +0 -149
  230. package/dist/delegation-http/credential-consent.d.ts.map +0 -1
  231. package/dist/delegation-http/credential-consent.js +0 -338
  232. package/dist/delegation-http/credential-consent.js.map +0 -1
  233. package/dist/delegation-http/native-capabilities.d.ts +0 -4
  234. package/dist/delegation-http/native-capabilities.d.ts.map +0 -1
  235. package/dist/delegation-http/native-capabilities.js +0 -53
  236. package/dist/delegation-http/native-capabilities.js.map +0 -1
  237. package/dist/delegation-http/native-oauth-state.d.ts +0 -28
  238. package/dist/delegation-http/native-oauth-state.d.ts.map +0 -1
  239. package/dist/delegation-http/native-oauth-state.js +0 -146
  240. package/dist/delegation-http/native-oauth-state.js.map +0 -1
  241. package/dist/delegation-http/native-oauth.d.ts +0 -26
  242. package/dist/delegation-http/native-oauth.d.ts.map +0 -1
  243. package/dist/delegation-http/native-oauth.js +0 -393
  244. package/dist/delegation-http/native-oauth.js.map +0 -1
  245. package/dist/delegation-http/native-pickup.d.ts +0 -20
  246. package/dist/delegation-http/native-pickup.d.ts.map +0 -1
  247. package/dist/delegation-http/native-pickup.js +0 -227
  248. package/dist/delegation-http/native-pickup.js.map +0 -1
  249. package/dist/delegation-http/pickup-routes.d.ts +0 -43
  250. package/dist/delegation-http/pickup-routes.d.ts.map +0 -1
  251. package/dist/delegation-http/pickup-routes.js +0 -166
  252. package/dist/delegation-http/pickup-routes.js.map +0 -1
  253. package/dist/delegation-http/register.d.ts +0 -26
  254. package/dist/delegation-http/register.d.ts.map +0 -1
  255. package/dist/delegation-http/register.js +0 -95
  256. package/dist/delegation-http/register.js.map +0 -1
  257. package/dist/delegation-http/registrar-auth.d.ts +0 -24
  258. package/dist/delegation-http/registrar-auth.d.ts.map +0 -1
  259. package/dist/delegation-http/registrar-auth.js +0 -61
  260. package/dist/delegation-http/registrar-auth.js.map +0 -1
  261. package/dist/delegation-http/remote-issuer.d.ts +0 -52
  262. package/dist/delegation-http/remote-issuer.d.ts.map +0 -1
  263. package/dist/delegation-http/remote-issuer.js +0 -324
  264. package/dist/delegation-http/remote-issuer.js.map +0 -1
  265. package/dist/delegation-http/types.d.ts +0 -116
  266. package/dist/delegation-http/types.d.ts.map +0 -1
  267. package/dist/delegation-http/types.js +0 -11
  268. package/dist/delegation-http/types.js.map +0 -1
@@ -27,7 +27,7 @@ import { isPostCredentialMarker, isPostOAuthMarker, resolveApprovalRoute, stripS
27
27
  import { createCredentialAuthHandler } from "./credential-auth.handler";
28
28
  import { parseMultipartFields, reconstructMalformedMultipart, isMalformedSingleEntry, extractFieldNameFromKey, } from "./multipart-parser";
29
29
  import { IdpTokenStorage } from "./idp-token-storage";
30
- import { OAuthSecurityService } from "./oauth-security.service";
30
+ import { OAuthSecurityService, TokenEncryptionUnavailableError, hasTokenEncryptionSecret, } from "./oauth-security.service";
31
31
  import { didKeyFragment } from "@kya-os/mcp";
32
32
  import { CONSENT_BUNDLE, CONSENT_BUNDLE_SIZE, CONSENT_BUNDLE_PATH, CONSENT_BUNDLE_HASH, resolveExpirationDays, DEFAULT_EXPIRATION_DAYS, resolveCapabilitiesForScopes, } from "@kya-os/consent";
33
33
  import { calculateDOInstanceId, parseDORoutingStrategy, parseDOShardCount, } from "../utils/do-routing";
@@ -734,148 +734,6 @@ export class ConsentService {
734
734
  generateDidKeyFromPublicKey(publicKeyBase64) {
735
735
  return generateDidKeyFromBase64(publicKeyBase64);
736
736
  }
737
- /**
738
- * The session's own throwaway DID, or undefined.
739
- *
740
- * A session record also holds a signed-in user's DID once the OAuth callback
741
- * or the credential handler has run (`updateSessionWithIdentity`), and that
742
- * write keeps the earlier throwaway `keyPair`. So the DID counts as
743
- * throwaway only when it is the did:key of the key pair stored with it.
744
- */
745
- sessionThrowawayDid(session) {
746
- const userDid = session?.userDid;
747
- const publicKey = session?.keyPair?.publicKey;
748
- if (typeof userDid !== "string" || typeof publicKey !== "string") {
749
- return undefined;
750
- }
751
- try {
752
- return this.generateDidKeyFromPublicKey(publicKey) === userDid
753
- ? userDid
754
- : undefined;
755
- }
756
- catch {
757
- return undefined;
758
- }
759
- }
760
- /**
761
- * A fresh throwaway did:key and its key pair. Nothing is stored.
762
- *
763
- * @returns The key pair (its `did` is the throwaway DID), or null if key
764
- * generation fails
765
- */
766
- async createThrowawayIdentity() {
767
- try {
768
- const rawKeyPair = await new WebCryptoProvider().generateKeyPair();
769
- const did = this.generateDidKeyFromPublicKey(rawKeyPair.publicKey);
770
- return {
771
- did,
772
- publicKey: rawKeyPair.publicKey,
773
- privateKey: rawKeyPair.privateKey,
774
- keyId: `${did}#${didKeyFragment(did)}`,
775
- };
776
- }
777
- catch (error) {
778
- logger.error("[ConsentService] Failed to generate a throwaway identity:", error);
779
- return null;
780
- }
781
- }
782
- /**
783
- * Generate an ephemeral userDid for consent-only flows
784
- *
785
- * This creates a session-scoped ephemeral did:key that enables:
786
- * 1. Delegation storage at PRIORITY 1 key (user+agent scoped)
787
- * 2. Reliable delegation lookup even if session_id changes
788
- *
789
- * For consent-only flows, there's no OAuth identity to create a persistent
790
- * userDid mapping. This ephemeral userDid is stored in the session cache
791
- * and used for delegation storage during the current session.
792
- *
793
- * @param sessionId - Session ID to associate the ephemeral userDid with
794
- * @returns Ephemeral userDid (did:key format), or null if generation fails,
795
- * the session record can't be read before the write, or the session
796
- * already holds a signed-in user's DID (which is never returned or
797
- * overwritten here)
798
- */
799
- async generateEphemeralUserDidForSession(sessionId) {
800
- // Check if session already has a userDid and key pair
801
- if (this.env.DELEGATION_STORAGE) {
802
- try {
803
- const sessionKey = STORAGE_KEYS.session(sessionId);
804
- const existingSession = (await this.env.DELEGATION_STORAGE.get(sessionKey, "json"));
805
- const throwawayDid = this.sessionThrowawayDid(existingSession);
806
- if (throwawayDid) {
807
- logger.debug("[ConsentService] Session already has a throwaway userDid, reusing:", {
808
- sessionId: sessionId.substring(0, 20) + "...",
809
- userDid: throwawayDid.substring(0, 20) + "...",
810
- });
811
- return throwawayDid;
812
- }
813
- // SECURITY: a signed-in user's DID is neither returned (consent-only
814
- // must not mint under it) nor overwritten.
815
- if (existingSession?.userDid) {
816
- return null;
817
- }
818
- }
819
- catch (error) {
820
- logger.warn("[ConsentService] Failed to check existing session userDid:", error);
821
- }
822
- }
823
- // Generate new ephemeral keypair - THIS TIME WE STORE IT!
824
- logger.debug("[ConsentService] Generating ephemeral key pair for consent-only VC signing");
825
- try {
826
- // Full UserKeyPair for VC signing
827
- const keyPair = await this.createThrowawayIdentity();
828
- if (!keyPair) {
829
- return null;
830
- }
831
- const ephemeralUserDid = keyPair.did;
832
- // Store key pair in session for VC signing
833
- // This enables consent-only users to sign their delegation VCs!
834
- if (this.env.DELEGATION_STORAGE) {
835
- const sessionKey = STORAGE_KEYS.session(sessionId);
836
- let existingSession;
837
- try {
838
- existingSession = (await this.env.DELEGATION_STORAGE.get(sessionKey, "json"));
839
- }
840
- catch (readError) {
841
- // The check above may have been skipped by a failed read too, so
842
- // without this record there is no proof the session holds no
843
- // signed-in DID. Write nothing.
844
- logger.warn("[ConsentService] Failed to re-read session before storing ephemeral key pair:", readError);
845
- return null;
846
- }
847
- // SECURITY: re-check before writing, so a signed-in DID is never
848
- // overwritten even when the first read failed.
849
- if (existingSession?.userDid &&
850
- !this.sessionThrowawayDid(existingSession)) {
851
- return null;
852
- }
853
- try {
854
- await this.env.DELEGATION_STORAGE.put(sessionKey, JSON.stringify({
855
- ...existingSession,
856
- userDid: ephemeralUserDid,
857
- keyPair, // Store the full key pair for VC signing!
858
- identityState: "ephemeral",
859
- }), { expirationTtl: DEFAULT_SESSION_CACHE_TTL });
860
- logger.debug("[ConsentService] ✅ Ephemeral key pair stored in session for VC signing");
861
- }
862
- catch (storeError) {
863
- logger.warn("[ConsentService] Failed to store ephemeral key pair (VC signing may fail):", storeError);
864
- }
865
- }
866
- logger.info("[ConsentService] ✅ Ephemeral key pair generated:", {
867
- sessionId: sessionId.substring(0, 20) + "...",
868
- userDid: ephemeralUserDid.substring(0, 30) + "...",
869
- hasPrivateKey: true,
870
- note: "User can now sign delegation VCs!",
871
- });
872
- return ephemeralUserDid;
873
- }
874
- catch (error) {
875
- logger.debug("[ConsentService] Failed to generate ephemeral key pair:", error);
876
- return null;
877
- }
878
- }
879
737
  /**
880
738
  * Issue a Delegation Verifiable Credential as JWT
881
739
  *
@@ -1942,6 +1800,14 @@ export class ConsentService {
1942
1800
  protection = await toolProtectionService.checkToolProtection(tool, agentDidObj.did);
1943
1801
  toolOAuthProvider = protection?.oauthProvider;
1944
1802
  }
1803
+ // A tool that needs no sign-in is approved at the organization's
1804
+ // authorization service. Only the clickwrap after a completed sign-in is
1805
+ // rendered here.
1806
+ if (protection?.authorization?.type === "none" &&
1807
+ !isPostCredentialClickwrap &&
1808
+ !isPostOAuthClickwrap) {
1809
+ return this.consentAtAuthorizationServicePage();
1810
+ }
1945
1811
  let oauthRequired;
1946
1812
  let defaultProvider;
1947
1813
  try {
@@ -2957,8 +2823,7 @@ export class ConsentService {
2957
2823
  /**
2958
2824
  * Interpret the `CONSENT_REQUIRE_IDENTITY` env override that gates the
2959
2825
  * identity-required refusal in `handleApproval`. Defaults to enabled - only
2960
- * an explicit `"false"`/`"0"` disables it, mirroring the escape-hatch
2961
- * convention used for `MCPI_HTTP_CHALLENGE` in config.ts.
2826
+ * an explicit `"false"`/`"0"` disables it.
2962
2827
  */
2963
2828
  isIdentityRequired() {
2964
2829
  const raw = this.env.CONSENT_REQUIRE_IDENTITY;
@@ -2999,20 +2864,38 @@ export class ConsentService {
2999
2864
  });
3000
2865
  }
3001
2866
  /**
3002
- * 503 returned by `handleApproval` when a consent-only approval has a
3003
- * session but no throwaway DID could be made or reused (key generation or a
3004
- * session read failed). Nothing is minted; the user can retry.
2867
+ * 410 returned when an approval carries no completed sign-in: the approval
2868
+ * happens at the organization's authorization service. Nothing is minted.
3005
2869
  */
3006
- identityUnavailableResponse() {
2870
+ consentAtAuthorizationServiceResponse() {
3007
2871
  return new Response(JSON.stringify({
3008
2872
  success: false,
3009
- error: "Could not set up an identity for this approval. Please try again.",
3010
- error_code: "identity_unavailable",
2873
+ error: "This approval happens at the organization's authorization service",
2874
+ error_code: "consent_at_authorization_service",
3011
2875
  }), {
3012
- status: 503,
2876
+ status: 410,
3013
2877
  headers: { "Content-Type": "application/json" },
3014
2878
  });
3015
2879
  }
2880
+ /**
2881
+ * 410 page for a consent URL whose tool needs no sign-in. It carries no
2882
+ * form: the approval happens at the organization's authorization service.
2883
+ */
2884
+ consentAtAuthorizationServicePage() {
2885
+ const html = '<!doctype html><html lang="en"><head><meta charset="utf-8">' +
2886
+ '<meta name="viewport" content="width=device-width, initial-scale=1">' +
2887
+ "<title>Approval moved</title></head><body>" +
2888
+ "<h1>Approval happens elsewhere</h1>" +
2889
+ "<p>This approval happens at the organization's authorization service.</p>" +
2890
+ "</body></html>";
2891
+ return new Response(html, {
2892
+ status: 410,
2893
+ headers: {
2894
+ "Content-Type": "text/html; charset=utf-8",
2895
+ "Cache-Control": "no-cache, no-store, must-revalidate",
2896
+ },
2897
+ });
2898
+ }
3016
2899
  /** A non-empty string, or undefined. */
3017
2900
  optionalString(value) {
3018
2901
  return typeof value === "string" && value.trim().length > 0
@@ -3124,19 +3007,13 @@ export class ConsentService {
3124
3007
  }
3125
3008
  // SECURITY (A3, spec §3.1/§3.2, defect #2): the identity a delegation is
3126
3009
  // minted under is authoritative ONLY from a trusted source resolved below
3127
- // — a server-signed identity assertion (credential/OAuth clickwrap) or the
3128
- // server-generated ephemeral / session-stored DID (pure consent-only).
3010
+ // — a server-signed identity assertion (credential/OAuth clickwrap).
3129
3011
  // A caller-supplied `user_did` body field is NEVER an identity source.
3130
3012
  // This holds the trusted value; it overwrites `bodyObj.user_did`
3131
3013
  // unconditionally before validation so no downstream consumer can read a
3132
3014
  // forged one. `undefined` for the plain authenticated (non-clickwrap)
3133
3015
  // shapes, which fall back to server-side session resolution.
3134
3016
  let trustedUserDid;
3135
- // Set only when a consent-only approval in a signed-in session mints
3136
- // under a fresh throwaway DID: the key that signs its VC, and whether the
3137
- // session record must keep the signed-in DID.
3138
- let consentOnlySigningKey;
3139
- let keepSessionUserDid = false;
3140
3017
  // CRED-003: Check for credential provider submission
3141
3018
  // Credential submissions include `provider_type: 'credential'` or 'password' and are handled separately
3142
3019
  // IMPORTANT: Checkpoint tool protection uses 'password' for credential-based auth validation,
@@ -3157,10 +3034,15 @@ export class ConsentService {
3157
3034
  const isPostOAuthClickwrap = route === "oauth" || isPostOAuthMarker(bodyObj.oauth_provider_type);
3158
3035
  const isPostCredentialClickwrap = route === "clickwrap" &&
3159
3036
  isPostCredentialMarker(bodyObj.credential_provider_type);
3037
+ // An approval with no completed sign-in is not taken here: approval
3038
+ // happens at the organization's authorization service. Nothing is minted.
3039
+ if (!isPostOAuthClickwrap && !isPostCredentialClickwrap) {
3040
+ logger.debug("[ConsentService] Approval without a completed sign-in refused");
3041
+ return this.consentAtAuthorizationServiceResponse();
3042
+ }
3160
3043
  // ✅ Clickwrap approval. This can be:
3161
- // 1. Pure consent-only: User consents without authentication (clickwrap only)
3162
- // 2. Post-credential clickwrap: User already authenticated via credentials, this is the clickwrap step
3163
- // 3. Post-OAuth clickwrap: User already authenticated via OAuth, this is the clickwrap step
3044
+ // 1. Post-credential clickwrap: User already authenticated via credentials, this is the clickwrap step
3045
+ // 2. Post-OAuth clickwrap: User already authenticated via OAuth, this is the clickwrap step
3164
3046
  if (route === "clickwrap" || route === "oauth") {
3165
3047
  const sessionId = bodyObj.session_id;
3166
3048
  if (isPostCredentialClickwrap) {
@@ -3177,7 +3059,7 @@ export class ConsentService {
3177
3059
  let signedProvider;
3178
3060
  if (this.isDevConsentTestMode()) {
3179
3061
  // Dev/test escape hatch (BOTH MCPI_TEST_CONSENT and a development
3180
- // env), mirroring consent-anchor-bridge's call-site CSRF relaxation:
3062
+ // env):
3181
3063
  // no signed assertion is required, so local/miniflare runs work
3182
3064
  // without OAUTH_ENCRYPTION_SECRET. Never on prod/staging/unset.
3183
3065
  trustedUserDid = bodyObj.user_did;
@@ -3312,89 +3194,10 @@ export class ConsentService {
3312
3194
  note: "Delegation will have authorization.type='oauth' to match tool protection",
3313
3195
  });
3314
3196
  }
3315
- // If neither credential nor OAuth, this is pure consent-only
3316
- if (!(isPostCredentialClickwrap || isPostOAuthClickwrap)) {
3317
- // Pure consent-only mode - no prior authentication
3318
- logger.debug("[ConsentService] Consent-only mode detected (pure clickwrap)");
3319
- // SECURITY (A3, spec §3.2, review #5): a pure consent-only mint is
3320
- // intentionally anonymous/ephemeral — it never had a victim identity
3321
- // to attribute. Any caller-supplied `user_did` is forgeable and must
3322
- // NEVER survive. Discard it up-front, before the ephemeral/session DID
3323
- // is (maybe) resolved below, so no sub-path — including the
3324
- // DELEGATION_STORAGE-unbound `else` fallback that used to leave the
3325
- // body value intact — can carry a forged DID into the mint.
3326
- trustedUserDid = undefined;
3327
- if (sessionId && this.env.DELEGATION_STORAGE) {
3328
- let existingSession = null;
3329
- try {
3330
- const sessionKey = STORAGE_KEYS.session(sessionId);
3331
- existingSession = (await this.env.DELEGATION_STORAGE.get(sessionKey, "json"));
3332
- }
3333
- catch (error) {
3334
- logger.warn("[ConsentService] Failed to read session for userDid:", error);
3335
- }
3336
- const throwawayDid = this.sessionThrowawayDid(existingSession);
3337
- if (throwawayDid) {
3338
- // The session's own throwaway identity from an earlier
3339
- // consent-only step: reuse it so the agent's lookups stay on it.
3340
- logger.debug("[ConsentService] Session already has a throwaway userDid, reusing:", {
3341
- sessionId: sessionId.substring(0, 20) + "...",
3342
- userDid: throwawayDid.substring(0, 30) + "...",
3343
- });
3344
- trustedUserDid = throwawayDid;
3345
- }
3346
- else if (existingSession?.userDid) {
3347
- // SECURITY: the session holds a signed-in user's DID (written
3348
- // by the OAuth callback or the credential handler). A
3349
- // consent-only approval proves no sign-in, so it must never be
3350
- // minted under that DID. Use a fresh throwaway identity for this
3351
- // grant only and leave the session's identity alone.
3352
- const fresh = await this.createThrowawayIdentity();
3353
- if (fresh) {
3354
- trustedUserDid = fresh.did;
3355
- consentOnlySigningKey = fresh;
3356
- keepSessionUserDid = true;
3357
- }
3358
- }
3359
- else {
3360
- // Generate ephemeral userDid for pure consent-only
3361
- // This enables PRIORITY 1 delegation key (user+agent scoped) for reliable lookup
3362
- const ephemeralUserDid = await this.generateEphemeralUserDidForSession(sessionId);
3363
- if (ephemeralUserDid) {
3364
- // Store ephemeral userDid in session cache
3365
- // This ensures storeDelegationToken can find it and use PRIORITY 1 key
3366
- await this.updateSessionWithIdentity(sessionId, ephemeralUserDid, null // No OAuth identity for consent-only
3367
- );
3368
- // Server-generated ephemeral DID (not a caller-supplied value)
3369
- // — safe to trust as the anonymous consent-only subject.
3370
- trustedUserDid = ephemeralUserDid;
3371
- logger.debug("[ConsentService] ✅ Ephemeral userDid stored in session for consent-only flow:", {
3372
- sessionId: sessionId.substring(0, 20) + "...",
3373
- userDid: ephemeralUserDid.substring(0, 30) + "...",
3374
- note: "Enables reliable delegation lookup via PRIORITY 1 key",
3375
- });
3376
- }
3377
- else {
3378
- logger.warn("[ConsentService] ⚠️ Failed to generate ephemeral userDid");
3379
- }
3380
- }
3381
- // SECURITY: fail closed. With no DID here, storeDelegationToken
3382
- // resolves one from the session record, which can be a signed-in
3383
- // user's DID, and the consent-only grant would replace their own
3384
- // grant under it.
3385
- if (!trustedUserDid) {
3386
- return this.identityUnavailableResponse();
3387
- }
3388
- }
3389
- else {
3390
- logger.warn("[ConsentService] ⚠️ No session_id for consent-only flow - delegation will use session-scoped storage only");
3391
- }
3392
- }
3393
3197
  }
3394
3198
  // SECURITY (A3, spec §3.2, defect #2 :4419/:4477): overwrite the forgeable
3395
3199
  // `user_did` body field with the trusted value resolved above — a signed
3396
- // assertion, or the server-generated ephemeral / session DID — for EVERY
3397
- // shape, unconditionally. For the plain authenticated (non-clickwrap)
3200
+ // assertion — for EVERY shape, unconditionally. For the plain authenticated (non-clickwrap)
3398
3201
  // shapes `trustedUserDid` is undefined, which wipes any caller-supplied
3399
3202
  // `user_did` so it can never be an identity source; those shapes then fall
3400
3203
  // back to server-side session resolution below. This is the single choke
@@ -3406,9 +3209,7 @@ export class ConsentService {
3406
3209
  // auth-type sidecar both read it from here.
3407
3210
  bodyObj.provider_type = isPostOAuthClickwrap
3408
3211
  ? "oauth"
3409
- : isPostCredentialClickwrap
3410
- ? CONSENT_PROVIDER_TYPES.PASSWORD
3411
- : CONSENT_PROVIDER_TYPES.NONE;
3212
+ : CONSENT_PROVIDER_TYPES.PASSWORD;
3412
3213
  const validation = validateConsentApprovalRequest(body);
3413
3214
  if (!validation.success) {
3414
3215
  logger.error("[ConsentService] Approval request validation failed:", {
@@ -3449,27 +3250,16 @@ export class ConsentService {
3449
3250
  const projectId = approvalRequest.project_id;
3450
3251
  // ✅ Lazy initialization with projectId
3451
3252
  const auditService = await this.getAuditService(projectId);
3452
- // Check if user needs credentials before delegation
3453
- // Skip credential requirement for consent-only mode (provider_type: 'none').
3454
- // Read the EFFECTIVE provider_type off bodyObj, not the `providerType`
3455
- // captured above: the post-OAuth/post-credential clickwrap branches above
3456
- // rewrite bodyObj.provider_type to 'oauth'/'password' while `providerType`
3457
- // stays the original raw 'none'. Gating on the stale value would treat
3458
- // those already-authenticated clickwrap submissions as consent-only and
3459
- // skip the identity check entirely.
3253
+ // Check if user needs credentials before delegation. Read the EFFECTIVE
3254
+ // provider_type off bodyObj: the post-OAuth/post-credential clickwrap
3255
+ // branches above rewrite it to 'oauth'/'password'.
3460
3256
  const effectiveProviderType = bodyObj.provider_type;
3461
- const isConsentOnlyMode = effectiveProviderType === CONSENT_PROVIDER_TYPES.NONE;
3462
3257
  // Resolve identity once, ahead of the gate below, using the same priority
3463
3258
  // createDelegation used to apply internally (request.user_did first, then
3464
3259
  // session lookup). The resolved value is threaded into createDelegation so
3465
3260
  // it is never resolved a second time.
3466
3261
  let resolvedUserDid = approvalRequest.user_did;
3467
- // Never for consent-only: the session lookup can return a signed-in
3468
- // user's DID, and a consent-only approval proves no sign-in. One with a
3469
- // stored session has a throwaway DID by now or was refused above.
3470
- if (!resolvedUserDid &&
3471
- approvalRequest.session_id &&
3472
- !isConsentOnlyMode) {
3262
+ if (!resolvedUserDid && approvalRequest.session_id) {
3473
3263
  try {
3474
3264
  // No OAuth identity: a caller-supplied one would select another
3475
3265
  // user's stored DID (see getUserDidForSession's first lookup).
@@ -3480,7 +3270,7 @@ export class ConsentService {
3480
3270
  logger.debug("[ConsentService] Failed to resolve userDid ahead of identity gate:", error);
3481
3271
  }
3482
3272
  }
3483
- const needsCredentials = !isConsentOnlyMode && !resolvedUserDid;
3273
+ const needsCredentials = !resolvedUserDid;
3484
3274
  if (needsCredentials && auditService) {
3485
3275
  await auditService
3486
3276
  .logCredentialRequired({
@@ -3516,7 +3306,7 @@ export class ConsentService {
3516
3306
  }
3517
3307
  // Create delegation via Checkpoint API
3518
3308
  logger.debug("[ConsentService] Creating delegation...");
3519
- const delegationResult = await this.createDelegation(approvalRequest, resolveExpirationDays(consentConfig.expirationDays), resolvedUserDid ?? null, consentOnlySigningKey);
3309
+ const delegationResult = await this.createDelegation(approvalRequest, resolveExpirationDays(consentConfig.expirationDays), resolvedUserDid ?? null);
3520
3310
  if (!delegationResult.success) {
3521
3311
  logger.error("[ConsentService] Delegation creation failed:", {
3522
3312
  error: delegationResult.error,
@@ -3549,7 +3339,7 @@ export class ConsentService {
3549
3339
  // match the tool's authorization.type; 'credential'/'password' form
3550
3340
  // submissions were routed to handleCredentialApproval earlier), so it
3551
3341
  // maps cleanly through normalizeAuthType — no 'credential' mis-fold here.
3552
- effectiveProviderType, keepSessionUserDid);
3342
+ effectiveProviderType);
3553
3343
  // ✅ After successful delegation creation - log audit events
3554
3344
  if (auditService && delegationResult.success) {
3555
3345
  try {
@@ -3617,12 +3407,9 @@ export class ConsentService {
3617
3407
  * Create delegation via Checkpoint API
3618
3408
  *
3619
3409
  * @param request - Approval request
3620
- * @param signingKeyPair - Key that signs the delegation VC when the user DID
3621
- * is a throwaway identity not stored on the session (consent-only in a
3622
- * signed-in session). Otherwise the session's own key is used.
3623
3410
  * @returns Delegation creation result
3624
3411
  */
3625
- async createDelegation(request, expirationDaysOverride, resolvedUserDid, signingKeyPair) {
3412
+ async createDelegation(request, expirationDaysOverride, resolvedUserDid) {
3626
3413
  // Resolve the mandate from the APPROVED scopes first: nothing (no VC, no
3627
3414
  // POST) may happen when a configured provider cannot answer.
3628
3415
  const mandateResolution = await this.resolveMandate(request.scopes ?? [], request.project_id);
@@ -3734,7 +3521,7 @@ export class ConsentService {
3734
3521
  // SECURITY: no OAuth identity from the request. It would pick the
3735
3522
  // signing key stored for that identity, i.e. sign as another user.
3736
3523
  // The key comes from this session's own server-side record.
3737
- const vcResult = await this.issueDelegationVC(localDelegation, request.session_id, undefined, signingKeyPair);
3524
+ const vcResult = await this.issueDelegationVC(localDelegation, request.session_id, undefined);
3738
3525
  credentialJwt = vcResult ?? undefined;
3739
3526
  if (credentialJwt) {
3740
3527
  logger.debug("[ConsentService] VC issued for delegation:", {
@@ -3947,12 +3734,8 @@ export class ConsentService {
3947
3734
  * persisting so the call-time enforcement gate (Task B2/B3) reads a
3948
3735
  * consistent value ("password" | "oauth2" | "none" | …). Undefined → the
3949
3736
  * field is omitted and the gate fails safe (never satisfies a typed tool).
3950
- * @param keepSessionUserDid - Keep the session record's existing userDid
3951
- * instead of overwriting it with this delegation's: set when a
3952
- * consent-only grant in a signed-in session was minted under a fresh
3953
- * throwaway DID, so the session keeps its signed-in identity.
3954
3737
  */
3955
- async storeDelegationToken(sessionId, agentDid, token, delegationId, providedUserDid, serverOrigin, authorizationType, keepSessionUserDid = false) {
3738
+ async storeDelegationToken(sessionId, agentDid, token, delegationId, providedUserDid, serverOrigin, authorizationType) {
3956
3739
  const delegationStorage = this.env.DELEGATION_STORAGE;
3957
3740
  // Task B2: normalize once (folds deprecated aliases: oauth→oauth2) so every
3958
3741
  // stored record and every read compares in the same vocabulary.
@@ -4054,9 +3837,7 @@ export class ConsentService {
4054
3837
  const existingData = (await delegationStorage.get(sessionKey, "json"));
4055
3838
  await delegationStorage.put(sessionKey, JSON.stringify({
4056
3839
  ...existingData,
4057
- userDid: keepSessionUserDid
4058
- ? (existingData?.userDid ?? userDid)
4059
- : userDid,
3840
+ userDid,
4060
3841
  agentDid,
4061
3842
  delegationToken: token,
4062
3843
  delegationId,
@@ -4211,8 +3992,7 @@ export class ConsentService {
4211
3992
  const isInlineMode = body.inline_mode === true;
4212
3993
  // SECURITY (A4, spec §3.3): the ONLY sanctioned CSRF relaxation is the
4213
3994
  // dev/test escape hatch — BOTH MCPI_TEST_CONSENT and a development env —
4214
- // applied here at the call site (mirroring consent-anchor-bridge's
4215
- // `isTestConsentMode` gate on `validateCsrfToken`), never inside the
3995
+ // applied here at the call site, never inside the
4216
3996
  // validator/minter, which are strictly fail-closed. Production, staging,
4217
3997
  // and unset always enforce CSRF.
4218
3998
  const skipCsrf = isInlineMode || this.isDevConsentTestMode();
@@ -4239,6 +4019,16 @@ export class ConsentService {
4239
4019
  }), { status: 403, headers: { "Content-Type": "application/json" } });
4240
4020
  }
4241
4021
  }
4022
+ // The provider's session is only ever stored encrypted. Without the
4023
+ // secret, refuse before the credentials reach the provider.
4024
+ if (!hasTokenEncryptionSecret(this.env.OAUTH_ENCRYPTION_SECRET)) {
4025
+ logger.error("[ConsentService] OAUTH_ENCRYPTION_SECRET is unset; refusing the sign-in (fail-closed)");
4026
+ return new Response(JSON.stringify({
4027
+ success: false,
4028
+ error: "Sign-in is unavailable: this server can't store the sign-in securely (OAUTH_ENCRYPTION_SECRET is not set)",
4029
+ error_code: new TokenEncryptionUnavailableError().code,
4030
+ }), { status: 503, headers: { "Content-Type": "application/json" } });
4031
+ }
4242
4032
  try {
4243
4033
  // 1. Fetch credential provider config from Checkpoint
4244
4034
  const providerConfig = await this.getCredentialProviderConfig(project_id, provider);
@@ -4517,8 +4307,7 @@ export class ConsentService {
4517
4307
  if (this.isDevConsentTestMode()) {
4518
4308
  // Dev/test escape hatch (BOTH MCPI_TEST_CONSENT and a development env):
4519
4309
  // no signed assertion is minted, so local/miniflare runs work without
4520
- // OAUTH_ENCRYPTION_SECRET. Mirrors consent-anchor-bridge's call-site
4521
- // relaxation. Never reached on production/staging/unset deployments.
4310
+ // OAUTH_ENCRYPTION_SECRET. Never reached on production/staging/unset deployments.
4522
4311
  clickwrapUrl.searchParams.set("user_did", identityResult.userDid);
4523
4312
  }
4524
4313
  else {
@@ -4850,8 +4639,7 @@ export class ConsentService {
4850
4639
  // SECURITY (A4, spec §3.3, defect #4): fail CLOSED. The old code returned
4851
4640
  // `true` here ("graceful degradation"), silently disabling CSRF on a
4852
4641
  // state-changing endpoint whenever the secret was unset — the exact
4853
- // fail-open this PR removes. Matches consent-anchor-bridge's
4854
- // `validateCsrfToken`. The single allowed relaxation is the dev/test
4642
+ // fail-open this PR removes. The single allowed relaxation is the dev/test
4855
4643
  // escape hatch applied at the CALL SITE (see `handleCredentialApproval`),
4856
4644
  // never here in the validator.
4857
4645
  logger.warn("[ConsentService] No OAUTH_ENCRYPTION_SECRET for CSRF validation — rejecting (fail-closed)");
@@ -4971,7 +4759,7 @@ export class ConsentService {
4971
4759
  /**
4972
4760
  * Whether local/miniflare testing may relax consent security checks.
4973
4761
  *
4974
- * Mirrors `consent-anchor-bridge.ts`'s `isTestConsentMode` verbatim: requires
4762
+ * Requires
4975
4763
  * BOTH `MCPI_TEST_CONSENT === "true"` AND an explicit `development`
4976
4764
  * environment. The flag alone must NEVER relax a check on a
4977
4765
  * production/staging/unset deployment.
@@ -5098,7 +4886,7 @@ export class ConsentService {
5098
4886
  *
5099
4887
  * FAIL-CLOSED, ALWAYS: returns `null` if `OAUTH_ENCRYPTION_SECRET` is unset
5100
4888
  * or empty. There is deliberately NO dev/test relaxation inside this
5101
- * helper — mirrors `consent-anchor-bridge.ts`'s `validateCsrfToken`, NOT
4889
+ * helper, unlike
5102
4890
  * `validateCredentialCsrfToken`'s legacy "return true to allow flow to
5103
4891
  * continue" behavior (the fail-open this PR closes). Any future dev/test
5104
4892
  * bypass belongs at the call site (see `isDevConsentTestMode`'s
@@ -5228,15 +5016,12 @@ export class ConsentService {
5228
5016
  if (fullFormatProviderId) {
5229
5017
  result.user_id = fullFormatProviderId;
5230
5018
  logger.debug("[ConsentService] Full format: Including provider user_id from credential auth:", {
5231
- user_id: fullFormatProviderId.substring(0, 20) + "...",
5232
- user_identifier: request.credential_user_email?.substring(0, 20) + "...",
5019
+ has_user_id: true,
5020
+ has_user_email: !!request.credential_user_email,
5233
5021
  });
5234
5022
  }
5235
5023
  logger.debug("[ConsentService] Full format: Including user identity fields:", {
5236
5024
  user_did: userDid.substring(0, 20) + "...",
5237
- user_identifier: request.credential_user_email
5238
- ? request.credential_user_email.substring(0, 20) + "..."
5239
- : "(fallback to DID)",
5240
5025
  has_user_id: !!fullFormatProviderId,
5241
5026
  source: request.credential_user_email ? "email" : "did-fallback",
5242
5027
  });
@@ -5279,12 +5064,8 @@ export class ConsentService {
5279
5064
  };
5280
5065
  if (fullFormatUserEmail || fullFormatProviderUserId) {
5281
5066
  logger.debug("[ConsentService] Full format: Including user info in custom_fields for Checkpoint compatibility:", {
5282
- user_email: fullFormatUserEmail
5283
- ? fullFormatUserEmail.substring(0, 20) + "..."
5284
- : undefined,
5285
- user_id: fullFormatProviderUserId
5286
- ? fullFormatProviderUserId.substring(0, 20) + "..."
5287
- : undefined,
5067
+ has_user_email: !!fullFormatUserEmail,
5068
+ has_user_id: !!fullFormatProviderUserId,
5288
5069
  });
5289
5070
  }
5290
5071
  }
@@ -5360,15 +5141,12 @@ export class ConsentService {
5360
5141
  if (providerId) {
5361
5142
  simplifiedRequest.user_id = providerId;
5362
5143
  logger.debug("[ConsentService] Including provider user_id from credential auth:", {
5363
- user_id: providerId.substring(0, 20) + "...",
5364
- user_identifier: request.credential_user_email?.substring(0, 20) + "...",
5144
+ has_user_id: true,
5145
+ has_user_email: !!request.credential_user_email,
5365
5146
  });
5366
5147
  }
5367
5148
  logger.debug("[ConsentService] Including user info in delegation request:", {
5368
5149
  user_did: userDid.substring(0, 20) + "...",
5369
- user_identifier: request.credential_user_email
5370
- ? request.credential_user_email.substring(0, 20) + "..."
5371
- : "(fallback to DID)",
5372
5150
  has_user_id: !!providerId,
5373
5151
  source: request.credential_user_email ? "email" : "did-fallback",
5374
5152
  });
@@ -5442,12 +5220,8 @@ export class ConsentService {
5442
5220
  }
5443
5221
  if (userEmail || providerUserId) {
5444
5222
  logger.debug("[ConsentService] Including user info in custom_fields for Checkpoint compatibility:", {
5445
- user_email: userEmail
5446
- ? userEmail.substring(0, 20) + "..."
5447
- : undefined,
5448
- user_id: providerUserId
5449
- ? providerUserId.substring(0, 20) + "..."
5450
- : undefined,
5223
+ has_user_email: !!userEmail,
5224
+ has_user_id: !!providerUserId,
5451
5225
  });
5452
5226
  }
5453
5227
  }