@kya-os/checkpoint-nextjs 1.10.0 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. package/CHANGELOG.md +261 -0
  2. package/README.md +217 -35
  3. package/dist/{adapt.mjs → adapt-BvqYgrAk.mjs} +15 -4
  4. package/dist/adapt-BvqYgrAk.mjs.map +1 -0
  5. package/dist/{adapt.js → adapt-DUEIfZnx.js} +34 -13
  6. package/dist/api-client-JHOrRUA_.d.mts +222 -0
  7. package/dist/api-client-JHOrRUA_.d.mts.map +1 -0
  8. package/dist/api-client-JHOrRUA_.d.ts +222 -0
  9. package/dist/api-client-JHOrRUA_.d.ts.map +1 -0
  10. package/dist/api-client.d.mts +2 -204
  11. package/dist/api-client.d.ts +2 -204
  12. package/dist/api-client.js +19 -18
  13. package/dist/api-client.mjs +20 -16
  14. package/dist/api-client.mjs.map +1 -1
  15. package/dist/api-middleware-BtsYJU5u.d.mts +131 -0
  16. package/dist/api-middleware-BtsYJU5u.d.mts.map +1 -0
  17. package/dist/{api-middleware-CMDRoQik.mjs → api-middleware-DvmkJ_Li.mjs} +68 -38
  18. package/dist/api-middleware-DvmkJ_Li.mjs.map +1 -0
  19. package/dist/api-middleware-DyLDqOYF.d.ts +131 -0
  20. package/dist/api-middleware-DyLDqOYF.d.ts.map +1 -0
  21. package/dist/{api-middleware-CDSh3TSE.js → api-middleware-beNlXd5P.js} +75 -63
  22. package/dist/api-middleware.d.mts +2 -152
  23. package/dist/api-middleware.d.ts +2 -152
  24. package/dist/api-middleware.js +1 -5
  25. package/dist/api-middleware.mjs +2 -3
  26. package/dist/cedar-wasm.d.mts +20 -0
  27. package/dist/cedar-wasm.d.mts.map +1 -0
  28. package/dist/cedar-wasm.d.ts +19 -0
  29. package/dist/cedar-wasm.d.ts.map +1 -0
  30. package/dist/cedar-wasm.js +24 -0
  31. package/dist/cedar-wasm.mjs +23 -0
  32. package/dist/cedar-wasm.mjs.map +1 -0
  33. package/dist/config-D7h2w_it.d.mts +89 -0
  34. package/dist/config-D7h2w_it.d.mts.map +1 -0
  35. package/dist/config-DkXvl4nH.d.ts +89 -0
  36. package/dist/config-DkXvl4nH.d.ts.map +1 -0
  37. package/dist/engine-wasm.d.mts +20 -0
  38. package/dist/engine-wasm.d.mts.map +1 -0
  39. package/dist/engine-wasm.d.ts +19 -0
  40. package/dist/engine-wasm.d.ts.map +1 -0
  41. package/dist/engine-wasm.js +24 -0
  42. package/dist/engine-wasm.mjs +23 -0
  43. package/dist/engine-wasm.mjs.map +1 -0
  44. package/dist/index-edge.d.mts +8 -0
  45. package/dist/index-edge.d.ts +8 -0
  46. package/dist/index-edge.js +14 -0
  47. package/dist/index-edge.mjs +7 -0
  48. package/dist/index.d.mts +8 -10
  49. package/dist/index.d.ts +8 -10
  50. package/dist/index.js +20 -49
  51. package/dist/index.mjs +21 -8
  52. package/dist/index.mjs.map +1 -1
  53. package/dist/middleware-bundler.d.mts +1 -1
  54. package/dist/middleware-bundler.d.mts.map +1 -1
  55. package/dist/middleware-bundler.d.ts +1 -1
  56. package/dist/middleware-bundler.d.ts.map +1 -1
  57. package/dist/middleware-bundler.js +5 -5
  58. package/dist/middleware-bundler.mjs +5 -5
  59. package/dist/middleware-bundler.mjs.map +1 -1
  60. package/dist/middleware-core-B1GuspOY.js +169 -0
  61. package/dist/middleware-core-BmW2kH8J.d.ts +14 -0
  62. package/dist/middleware-core-BmW2kH8J.d.ts.map +1 -0
  63. package/dist/middleware-core-CnPUoD2v.d.mts +14 -0
  64. package/dist/middleware-core-CnPUoD2v.d.mts.map +1 -0
  65. package/dist/middleware-core-WZeMSRqx.mjs +159 -0
  66. package/dist/middleware-core-WZeMSRqx.mjs.map +1 -0
  67. package/dist/middleware-edge.d.mts +11 -3
  68. package/dist/middleware-edge.d.mts.map +1 -1
  69. package/dist/middleware-edge.d.ts +11 -3
  70. package/dist/middleware-edge.d.ts.map +1 -1
  71. package/dist/middleware-edge.js +68 -29
  72. package/dist/middleware-edge.mjs +68 -31
  73. package/dist/middleware-edge.mjs.map +1 -1
  74. package/dist/middleware-node-context-BvqrL2Ra.mjs +16 -0
  75. package/dist/middleware-node-context-BvqrL2Ra.mjs.map +1 -0
  76. package/dist/middleware-node-context-TRMTgp3y.js +20 -0
  77. package/dist/middleware-node.d.mts +12 -3
  78. package/dist/middleware-node.d.mts.map +1 -0
  79. package/dist/middleware-node.d.ts +12 -3
  80. package/dist/middleware-node.d.ts.map +1 -0
  81. package/dist/middleware-node.js +14 -6
  82. package/dist/middleware-node.mjs +14 -6
  83. package/dist/middleware-node.mjs.map +1 -1
  84. package/dist/posture-outcome-Ccujx_9V.d.mts +14 -0
  85. package/dist/posture-outcome-Ccujx_9V.d.mts.map +1 -0
  86. package/dist/posture-outcome-Ccujx_9V.d.ts +14 -0
  87. package/dist/posture-outcome-Ccujx_9V.d.ts.map +1 -0
  88. package/dist/posture-outcome-DQ4fdMfq.mjs +21 -0
  89. package/dist/posture-outcome-DQ4fdMfq.mjs.map +1 -0
  90. package/dist/posture-outcome-DddsJtL8.js +25 -0
  91. package/dist/public-api-Cw7Zj290.d.ts +5 -0
  92. package/dist/public-api-DgCw1uo6.d.mts +5 -0
  93. package/dist/rolldown-runtime-C24Yb2bl.js +33 -0
  94. package/dist/utils-Cnwg0VrY.mjs +88 -0
  95. package/dist/utils-Cnwg0VrY.mjs.map +1 -0
  96. package/dist/utils-dyFxqlFI.js +104 -0
  97. package/package.json +27 -62
  98. package/EDGE_RUNTIME_WASM_SETUP.md +0 -342
  99. package/bin/setup-edge-wasm.js +0 -513
  100. package/dist/adapt.d.mts +0 -11
  101. package/dist/adapt.d.mts.map +0 -1
  102. package/dist/adapt.d.ts +0 -11
  103. package/dist/adapt.d.ts.map +0 -1
  104. package/dist/adapt.mjs.map +0 -1
  105. package/dist/api-client.d.mts.map +0 -1
  106. package/dist/api-client.d.ts.map +0 -1
  107. package/dist/api-middleware-CMDRoQik.mjs.map +0 -1
  108. package/dist/api-middleware.d.mts.map +0 -1
  109. package/dist/api-middleware.d.ts.map +0 -1
  110. package/dist/composed-policy-BCaNiVHv.d.mts +0 -98
  111. package/dist/composed-policy-BCaNiVHv.d.mts.map +0 -1
  112. package/dist/composed-policy-zzJYNFTb.d.ts +0 -98
  113. package/dist/composed-policy-zzJYNFTb.d.ts.map +0 -1
  114. package/dist/composed-policy.d.mts +0 -2
  115. package/dist/composed-policy.d.ts +0 -2
  116. package/dist/composed-policy.js +0 -136
  117. package/dist/composed-policy.mjs +0 -132
  118. package/dist/composed-policy.mjs.map +0 -1
  119. package/dist/config-CbAg2mze.d.ts +0 -255
  120. package/dist/config-CbAg2mze.d.ts.map +0 -1
  121. package/dist/config-Doe0Tn53.d.mts +0 -255
  122. package/dist/config-Doe0Tn53.d.mts.map +0 -1
  123. package/dist/create-middleware.d.mts +0 -11
  124. package/dist/create-middleware.d.mts.map +0 -1
  125. package/dist/create-middleware.d.ts +0 -11
  126. package/dist/create-middleware.d.ts.map +0 -1
  127. package/dist/create-middleware.js +0 -39
  128. package/dist/create-middleware.mjs +0 -38
  129. package/dist/create-middleware.mjs.map +0 -1
  130. package/dist/edge/index.d.mts +0 -88
  131. package/dist/edge/index.d.mts.map +0 -1
  132. package/dist/edge/index.d.ts +0 -88
  133. package/dist/edge/index.d.ts.map +0 -1
  134. package/dist/edge/index.js +0 -362
  135. package/dist/edge/index.mjs +0 -362
  136. package/dist/edge/index.mjs.map +0 -1
  137. package/dist/edge-runtime-loader.d.mts +0 -49
  138. package/dist/edge-runtime-loader.d.mts.map +0 -1
  139. package/dist/edge-runtime-loader.d.ts +0 -49
  140. package/dist/edge-runtime-loader.d.ts.map +0 -1
  141. package/dist/edge-runtime-loader.js +0 -297
  142. package/dist/edge-runtime-loader.mjs +0 -292
  143. package/dist/edge-runtime-loader.mjs.map +0 -1
  144. package/dist/edge-wasm-middleware.d.mts +0 -43
  145. package/dist/edge-wasm-middleware.d.mts.map +0 -1
  146. package/dist/edge-wasm-middleware.d.ts +0 -43
  147. package/dist/edge-wasm-middleware.d.ts.map +0 -1
  148. package/dist/edge-wasm-middleware.js +0 -37
  149. package/dist/edge-wasm-middleware.mjs +0 -35
  150. package/dist/edge-wasm-middleware.mjs.map +0 -1
  151. package/dist/middleware-core-BYQP9FND.mjs +0 -165
  152. package/dist/middleware-core-BYQP9FND.mjs.map +0 -1
  153. package/dist/middleware-core-D6TijE6P.js +0 -175
  154. package/dist/middleware-node-CE4GevYs.d.ts +0 -20
  155. package/dist/middleware-node-CE4GevYs.d.ts.map +0 -1
  156. package/dist/middleware-node-DtyOuPta.d.mts +0 -20
  157. package/dist/middleware-node-DtyOuPta.d.mts.map +0 -1
  158. package/dist/middleware-node-context-BqPbf-fI.mjs +0 -34
  159. package/dist/middleware-node-context-BqPbf-fI.mjs.map +0 -1
  160. package/dist/middleware-node-context-rgnc7UNR.js +0 -38
  161. package/dist/middleware.d.mts +0 -25
  162. package/dist/middleware.d.mts.map +0 -1
  163. package/dist/middleware.d.ts +0 -25
  164. package/dist/middleware.d.ts.map +0 -1
  165. package/dist/middleware.js +0 -53
  166. package/dist/middleware.mjs +0 -51
  167. package/dist/middleware.mjs.map +0 -1
  168. package/dist/nodejs-wasm-loader.d.mts +0 -42
  169. package/dist/nodejs-wasm-loader.d.mts.map +0 -1
  170. package/dist/nodejs-wasm-loader.d.ts +0 -42
  171. package/dist/nodejs-wasm-loader.d.ts.map +0 -1
  172. package/dist/nodejs-wasm-loader.js +0 -70
  173. package/dist/nodejs-wasm-loader.mjs +0 -66
  174. package/dist/nodejs-wasm-loader.mjs.map +0 -1
  175. package/dist/policy.d.mts +0 -138
  176. package/dist/policy.d.mts.map +0 -1
  177. package/dist/policy.d.ts +0 -138
  178. package/dist/policy.d.ts.map +0 -1
  179. package/dist/policy.js +0 -236
  180. package/dist/policy.mjs +0 -205
  181. package/dist/policy.mjs.map +0 -1
  182. package/dist/session-tracker.d.mts +0 -50
  183. package/dist/session-tracker.d.mts.map +0 -1
  184. package/dist/session-tracker.d.ts +0 -50
  185. package/dist/session-tracker.d.ts.map +0 -1
  186. package/dist/session-tracker.js +0 -148
  187. package/dist/session-tracker.mjs +0 -147
  188. package/dist/session-tracker.mjs.map +0 -1
  189. package/dist/translate.d.mts +0 -48
  190. package/dist/translate.d.mts.map +0 -1
  191. package/dist/translate.d.ts +0 -48
  192. package/dist/translate.d.ts.map +0 -1
  193. package/dist/translate.js +0 -79
  194. package/dist/translate.mjs +0 -79
  195. package/dist/translate.mjs.map +0 -1
  196. package/dist/types-C0SkqLMM.d.mts +0 -102
  197. package/dist/types-C0SkqLMM.d.mts.map +0 -1
  198. package/dist/types-C7DNSCTO.d.ts +0 -102
  199. package/dist/types-C7DNSCTO.d.ts.map +0 -1
  200. package/dist/utils-Cj4XNhIY.mjs +0 -35
  201. package/dist/utils-Cj4XNhIY.mjs.map +0 -1
  202. package/dist/utils-DAisnYnI.js +0 -45
  203. package/dist/wasm-setup.d.mts +0 -47
  204. package/dist/wasm-setup.d.mts.map +0 -1
  205. package/dist/wasm-setup.d.ts +0 -47
  206. package/dist/wasm-setup.d.ts.map +0 -1
  207. package/dist/wasm-setup.js +0 -91
  208. package/dist/wasm-setup.mjs +0 -95
  209. package/dist/wasm-setup.mjs.map +0 -1
  210. package/wasm/agentshield_wasm.d.ts +0 -479
  211. package/wasm/agentshield_wasm.js +0 -1536
  212. package/wasm/agentshield_wasm_bg.wasm +0 -0
  213. package/wasm/package.json +0 -30
  214. package/wasm.d.ts +0 -21
package/CHANGELOG.md CHANGED
@@ -1,5 +1,266 @@
1
+ <!-- Generated by `pnpm changelog:generate` from the "## Release notes" sections of merged pull requests. Do not edit this file by hand: change the PR's release notes and regenerate. -->
2
+
1
3
  # @kya-os/checkpoint-nextjs
2
4
 
5
+ ## 1.12.0 - 2026-10-22
6
+
7
+ ### Breaking changes
8
+
9
+ - Removed: `adapters.didResolver` and `adapters.statusListCache`. Use `adapters.fetch` to replace the transport DID documents and status lists are fetched with; it must connect only to a vetted public address, refuse redirects, cap the body and enforce a deadline. (#6600)
10
+ - Removed: `adapters.policyEvaluator` and `reputationBaseline` from `CheckpointConfig`. A config that still sets them has them ignored: no TS code produces a Block, and a tenant's rules are Cedar. (#6678)
11
+
12
+ ### Changed
13
+
14
+ - A status list that cannot be fetched or verified is answered `503 kyaos/status-pending` with `Retry-After: 1`. (#6600)
15
+ - `withCheckpoint` runs wasm-runtime's shared request pipeline (`./pipeline`), so it needs a wasm-runtime release that has it. `CheckpointConfig` extends wasm-runtime's `CheckpointHostConfig`; its fields are unchanged. With `debug` on, an engine that fails to load is logged once instead of twice. (#6650)
16
+
17
+ ### Deprecated
18
+
19
+ - `tenantHost` is optional; it is no longer used and will be removed. (#6678)
20
+
21
+ ## 1.11.0 - 2026-10-21
22
+
23
+ ### Added
24
+
25
+ - `withCheckpoint` claims an accepted signed request once, before it reaches the handler, using the dashboard's shared ledger when `apiKey` and `projectId` are set, or an in-process store otherwise; the new `requestClaimStore` option picks the store. (#6422)
26
+
27
+ ### Changed
28
+
29
+ - On the Node.js runtime (`proxy.ts`, or `middleware.ts` with `runtime: 'nodejs'`), `@kya-os/checkpoint-nextjs` now runs the engine's Node build, the same as `./node`. Under Turbopack a `proxy.ts` with `withCheckpoint` traces 117 files (5.6 MiB) instead of about 257 MiB, well inside Vercel's 250 MB function limit, with the same verdicts.
30
+ If the engine cannot load, every request is answered 503, the cause is logged, and the next request tries again.
31
+ webpack on the Node.js runtime is still not supported: it now builds, then answers every request 503 with the cause logged. (#6438)
32
+
33
+ ### Other merged changes
34
+
35
+ - chore(release): set nextjs and express to 1.10.0 in package.json and the version literal (#5192)
36
+ - chore: remove comments that excuse unresolved design debt (#5224)
37
+ - fix(deps): update next to 16.3.5 security release (#4993)
38
+ - chore(deps): remove unused dependencies and import cycles (#5299)
39
+ - fix(detection): detection pattern and fingerprint accuracy pass (#5437)
40
+ - fix(policy): verify authentication and make backfill claims atomic (#5687)
41
+ - chore(deps): patch security advisories (next 16.3.8, pnpm overrides) (#5833)
42
+ - Revert "fix(detection): classify zero-evidence requests as unknown instead of human" (#5881)
43
+ - fix(detection): classify zero-evidence requests as unknown instead of human (#5886)
44
+ - feat(nextjs): make @kya-os/checkpoint-nextjs engine-only and fix its next.js entries (#6271)
45
+ - fix(nextjs): load every entry in plain node esm (#6312)
46
+ - fix(nextjs): fail closed on edge when an enforcing cedar policy has no module (#6298)
47
+ - refactor(wasm-runtime): add make engine defaults and share it across the sdks (#6303)
48
+ - perf(sdk): load lean checkpoint-shared entries in express and next.js (#6306)
49
+ - fix(wasm-runtime): stop fetching a tenant policy that does not exist (#6301)
50
+ - fix(sdk): raise the node floor to the versions that can require an es module (#6293)
51
+ - feat(nextjs): run edge detection and cedar on one module (#6343)
52
+ - refactor(wasm-runtime): one composed-policy context for express and next.js (#6360)
53
+
54
+ ### Notes (#5387)
55
+
56
+ - Browser posture is also read from the `KYA-Posture` and
57
+ `KYA-Posture-Session` request headers, which a page on another host, or one
58
+ that blocks cookies, sends from the beacon's `onReceipt`. Each header wins
59
+ over its cookie. Needs `@kya-os/checkpoint-wasm-runtime` and
60
+ `@kya-os/checkpoint-shared` releases that carry `postureFromRequest`.
61
+
62
+ ### Notes (#5508)
63
+
64
+ - `withCheckpointApi` now reports the decision it acted on, the engine that
65
+ made it, and itself. The detection it logs carries `enforcement.action`,
66
+ the gateway's engine info under the name `checkpoint-remote`, and an `sdk`
67
+ block (package, version, and `node` or `edge`). Activity previously showed
68
+ these rows as "Unrecognized runtime" with no verdict. The `sdk` block is
69
+ omitted when the build injected no package version.
70
+
71
+ ### Notes (#5410)
72
+
73
+ #### Changed
74
+
75
+ - **Action for Next.js 15 users:** set `clientIpPolicy` on `withCheckpoint`,
76
+ `withCheckpointApi` and `createEdgeCheckpoint`. Next.js 15 removed
77
+ `request.ip`, so the default `direct` policy resolves no IP. The engine
78
+ used to fall back to `x-real-ip` or `x-forwarded-for` when a signature
79
+ failed; it no longer does (see `@kya-os/checkpoint-wasm-runtime`), so on
80
+ the default policy a request with a failed signature loses the
81
+ `vendor_ip_feed` match, the Tier-4 cloud check and reputation. On Vercel
82
+ set `{ platform: 'vercel' }`; self-hosted, use the `trusted-proxy` profile
83
+ with `trustedHops`.
84
+ - The `vercel` client-IP profile is honored only when `VERCEL=1`. Anywhere else
85
+ it resolves like `direct`, so a self-hosted app that copies a Vercel
86
+ snippet can no longer have its IP chosen by a client-sent
87
+ `x-vercel-forwarded-for` or `x-forwarded-for`.
88
+ - `trustedHops` counts the trusted proxy addresses at the right of
89
+ `x-forwarded-for`, which is one fewer than the number of proxies, and now
90
+ accepts `0` (the rightmost entry) for a single proxy; `0` needs the
91
+ `@kya-os/checkpoint-shared` release that carries this change, and resolves
92
+ no IP with an older one.
93
+ - An untrusted resolution (an `x-real-ip` or `x-forwarded-for` fallback the
94
+ selected profile does not vouch for) is no longer forwarded as the client
95
+ IP to the engine, the reporter or the API middleware.
96
+
97
+ ### Notes (#5438)
98
+
99
+ - `withCheckpointApi` answers a `rate_limited` enforce decision (the project
100
+ policy's `requestsPerMinute` throttle) with a `429`, a `Retry-After` header
101
+ and a `RATE_LIMITED` body instead of the `403` access-denied shape. It is not
102
+ turned into a redirect by `onBlock: 'redirect'`; `customBlockedResponse` and
103
+ `blockedResponse.headers` still apply. The limit is counted per client IP
104
+ the middleware relays, so set `clientIpPolicy` to the platform that fronts
105
+ your app: with the default `direct` policy on Next.js 15 no IP is relayed
106
+ and the limit is skipped.
107
+
108
+ ### Notes (#5594)
109
+
110
+ #### Added
111
+
112
+ - `getCheckpointPostureOutcome(request, { browserPosture, projectId })` returns the
113
+ browser-posture outcome for a request in a route handler or page:
114
+ `{ status, reason?, posture? }` with `status` `verified`, `absent` or `rejected`, and the
115
+ verified claims (a frozen copy) only when verified. It verifies the token from the
116
+ `KYA-Posture` headers or cookies with the same verifier and posture config
117
+ `withCheckpoint` takes, so nothing is forwarded from the middleware and no secret is
118
+ needed. It always checks, whether or not the middleware ran for the route.
119
+ `status: 'verified'` means the token signature and claims are valid, so check
120
+ `posture.verdict` before treating the visitor as human. The accessor runs the
121
+ same config validation as `withCheckpoint` (`projectId` must be the lowercase project
122
+ UUID) and throws on an invalid config. Needs a
123
+ `@kya-os/checkpoint-wasm-runtime` release that carries `postureOutcomeView`.
124
+
125
+ ### Notes (#5707)
126
+
127
+ - Policy-load timeouts and fast origin failures now follow the documented
128
+ `failOpen` and `fallbackPolicy` settings. The default remains fail-open;
129
+ `failOpen: false` with no fallback returns `503 POLICY_UNAVAILABLE`.
130
+
131
+ ### Notes (#5579)
132
+
133
+ #### Fixed
134
+
135
+ - `CheckpointApiClient.enforce` and `quickCheck` no longer send cookies,
136
+ `Authorization` or other credential-looking headers (any name containing
137
+ `authorization`, `auth`, `token`, `secret`, `password`, `api-key`,
138
+ `subscription-key` or `credential`, except `kya-` headers) to Checkpoint, so
139
+ `withCheckpointApi` and direct callers are covered alike. The only exceptions
140
+ are every `_as_beacon_session` cookie and a KYA delegation credential bearer,
141
+ which the engine verifies.
142
+
143
+ ### zero-evidence requests are `IncompleteData`, not `Human` (breaking wire change) (#5060)
144
+
145
+ - **Behavior change:** the embedded engine no longer classifies a request that carries no evidence as `Human`. For
146
+ that request `detectionDetail.detectionClass.type` is now `IncompleteData` and `detectionDetail.riskLevel` is
147
+ `medium` instead of `low`. `isAgent` stays false.
148
+ - The engine marks that verdict with `detectionDetail.metadata.detection_basis = "no_evidence"`. It is the only thing
149
+ that separates a zero-evidence request from other `IncompleteData` verdicts, and the composed-policy projection reads
150
+ it to give the visitor the category `no_evidence`.
151
+ - A request with suspicious headers is still `IncompleteData` (the engine's internal Unknown class), but its
152
+ `detectionDetail.verificationMethod` is now `none` instead of `pattern`.
153
+ - Composed rules aimed at all agents now exempt only `human` and `no_evidence` visitors, so any other `incomplete_data`
154
+ visitor is matched by them. A forged `mcp_i_handshake` or `kyaos_handshake` envelope that the engine blocks projects
155
+ as category `unknown`, not `incomplete_data`.
156
+ - For a zero-evidence request `detectionDetail.isBot` and `detectionDetail.isAiCrawler` are now absent; they were `false`.
157
+ Read a missing value as false. Its `reasons` now read `Request did not carry enough signal to classify confidently`
158
+ where they read `No known agent indicators matched`.
159
+ - A deployed rule that does not compare the category to `no_evidence` reads it as `human` because the composed-policy
160
+ compile rewrites the policy text (`withNoEvidenceExclusion` in `@kya-os/checkpoint-shared`). The dashboard serves the
161
+ stored text, so a release that predates the rewrite reads it, `@scopes` included, exactly as before.
162
+ - Composed-policy evaluation now applies that same rewrite to the policy text inside the compile, once per distinct policy
163
+ text on a cache miss and not on every request, so a custom `PolicyFetcher` is covered and text that already carries
164
+ the rewrite is unchanged. Apart from computed reads, a statement is skipped only when it compares the category to the literal `"no_evidence"`.
165
+ The rewrite takes a direct read of the category, including a parenthesized principal and a bracket key written with
166
+ escapes; whitespace between tokens is the 25 Unicode `White_Space` characters and a `//` comment ends at a line feed
167
+ or a lone carriage return. A statement that reads the category through a computed value holding the principal, such as an `if` or a record
168
+ that carries `principal`, is left as written and sees `no_evidence`, and a `principal` that is an attribute name or
169
+ record key is never rewritten. If the engine rejects the rewritten text as invalid Cedar, the authored text is
170
+ compiled instead, a `no_evidence` visitor is still read as `human` for that policy, and the new optional
171
+ `ComposedPolicyLogger.compileFallback(projectId, error)` is called once per policy text, or `console.warn` when the
172
+ logger does not supply it. A policy nested deeper than 32 levels is refused as invalid Cedar before the engine
173
+ compiles it. Needs a `@kya-os/checkpoint-wasm-runtime` release that carries the rewrite.
174
+ - `engineInfo.version` and `engineInfo.rulesetVersion` are now `0.2.1` (they were `0.2.0`). `engineInfo.rulesetHash` is
175
+ unchanged: it hashes the bundled vendor keys, vendor feeds and user-agent pattern table, and none of them changed.
176
+ - `withCheckpoint` reports through `@kya-os/checkpoint-wasm-runtime`, whose reporter now sends `detection.detectionBasis`
177
+ to `POST /api/v1/log-detection`. Needs a `@kya-os/checkpoint-wasm-runtime` release that carries it. The
178
+ `CheckpointApiClient.logDetection` call used by `withCheckpointApi` sends the top-level `detectionBasis` that the
179
+ gateway's `/__detect/enforce` returns on the detection. It used to read `metadata.detection_basis`, which that route
180
+ does not set, so nothing was forwarded. `ApiDetectionDetail` gained the optional `detectionBasis` field. The
181
+ dashboard accepts only `no_evidence` and `posture_evidence` and stores it only on an `incomplete_data` row.
182
+ - `withCheckpoint` results (Node and Edge) never carry `Human` now. It still comes from the older
183
+ `createEdgeCheckpoint` detector in `@kya-os/checkpoint-nextjs/edge-runtime-loader`, which reports `Human` when its
184
+ WASM call or its pattern fallback finds no agent.
185
+
186
+ ### Notes (#5968)
187
+
188
+ - `resolveDelegationChallenge` is now also called for a `Block` the engine marks `consent_remediable` (a scope
189
+ shortfall against the host's required scopes, or a delegation whose own `exp` passed or whose status list says
190
+ revoked). Return context with the route's required scopes, from your route configuration and never from
191
+ `result.decision.reason.requested`, and the request gets the same Delegation challenge a first-contact `Challenge`
192
+ gets, so the agent can send the human back to consent. Return `undefined` and the request keeps its block. Every
193
+ other block still renders as before and never calls the resolver. Needs the `@kya-os/checkpoint-wasm-runtime`
194
+ release that carries the re-challenge.
195
+
196
+ ### Notes (#5652)
197
+
198
+ #### Fail-closed credential handling
199
+
200
+ A request presenting a KYA credential that fails verification returns 503 even when `failOpen` is enabled. Trusted roots are resolved for KYA signatures, delegation-proof headers, and structurally recognized VC-JWTs. Opaque and unrelated bearer tokens do not trigger root lookup. Credential claims still require engine verification, including issuer, project, holder, expiry, and revocation checks. Cedar evaluation errors on enforcing projects fail closed; shadow mode keeps the structured decision.
201
+
202
+ #### Changed
203
+
204
+ ### Node 20.16+ or 22.3+ required; did:web and status-list fetches are hardened (breaking) (#6094)
205
+
206
+ - **BREAKING:** `engines.node` is now `^20.16.0 || >=22.3.0` (was `>=18.0.0`), so installing on older Node warns.
207
+ Node 18 and Node 20 before 20.16 are end of life and have no `process.getBuiltinModule`, which the default DID
208
+ resolver needs for its connect-time address check. There every did:web and status-list fetch is refused: a request
209
+ with a did:web identity is blocked and one whose credential has a status list gets a 503. One warning per process
210
+ names the Node version.
211
+ - **BREAKING for hosts whose only route out is a proxy:** on Node the default `didResolver` and `statusListCache`
212
+ fetch with `https.get` and `agent: false`. That ignores an undici global dispatcher
213
+ (`setGlobalDispatcher(new ProxyAgent(...))`) and Node 24's `NODE_USE_ENV_PROXY`, which global `fetch` honoured
214
+ before, so such a host fails every did:web and status-list fetch (503). Workaround: pass your proxied fetch,
215
+ `adapters: { didResolver: makeDidResolver({ fetch: proxiedFetch }), statusListCache: makeStatusListCache({ fetch: proxiedFetch }) }`
216
+ (both from `@kya-os/checkpoint-wasm-runtime/adapters`). Redirects, ports and size stay checked, but the
217
+ connect-time address check is then your job.
218
+ - The default DID resolver and status-list cache now refuse redirects, ports other than 443, bodies over 64 KiB and,
219
+ on Node, hosts that resolve to a private, loopback, link-local, CGNAT or metadata address. See the
220
+ `@kya-os/checkpoint-wasm-runtime` changelog (#3331).
221
+
222
+ ### the `agentshield_wasm` setup CLI and binary are removed (breaking) (#6084)
223
+
224
+ Shipped under a minor because nothing consumes this package yet.
225
+
226
+ #### BREAKING, removal
227
+
228
+ - **The `checkpoint-setup-edge` bin, the bundled `wasm/` files, `wasm.d.ts` and `EDGE_RUNTIME_WASM_SETUP.md`.**
229
+ The CLI copied the retired `agentshield_wasm` binary into an app for `createEdgeWasmMiddleware`, which already throws.
230
+ **Migration path:** `withCheckpoint` (from `@kya-os/checkpoint-nextjs/edge` on the edge runtime), which runs the `kya-os-engine` build that `@kya-os/checkpoint-wasm-runtime` ships.
231
+ - **The `@kya-os/checkpoint` dependency.**
232
+ `CheckpointEvents`, the type of the `events` option, now comes from `@kya-os/checkpoint-shared`.
233
+ Import it from there if your code names it.
234
+
235
+ RELEASE ORDER: publish `@kya-os/checkpoint-shared` (which adds `CheckpointEvents`) and `@kya-os/checkpoint-wasm-runtime` first.
236
+
237
+ ### Notes (#6187)
238
+
239
+ - **Breaking:** verification and reporting now withhold unauthenticated client addresses. NextRequest exposes no socket peer, so `trusted-proxy` and `cloudflare` return no address even with a peer callback. Current NextRequest objects also lack the legacy `request.ip` used by `direct`. On Vercel, select its managed `vercel` profile. For self-hosted deployments, authenticate addresses at a transport-aware ingress and keep Next address evidence unavailable. See [migration steps](https://github.com/Know-That-Ai/checkpoint/blob/main/docs/runbooks/client-ip-resolution.md#migrate-existing-configurations).
240
+
241
+ ### Notes (#5748)
242
+
243
+ Client-IP handling tightens after the engine stopped deriving an IP from
244
+ forwarded headers. Next.js 15 users on Vercel must now set `clientIpPolicy`.
245
+
246
+ #### Added
247
+
248
+ - OpenAI Tier-1 signing keys now rotate without an SDK release. Verification
249
+ fetches a signed key feed from `feeds.kya.vouched.id` through
250
+ `@kya-os/checkpoint-wasm-runtime`, and a request that misses on an unknown or
251
+ expired OpenAI key is answered at once while the feed refreshes in the background, so the next
252
+ request uses the new keys. This adds
253
+ outbound HTTPS from your server to that host, so allow-list it if you filter
254
+ egress. Point it elsewhere with `KYA_VENDOR_KEY_FEED_URL`. Needs a
255
+ `@kya-os/checkpoint-wasm-runtime` release that carries the feed hook; this
256
+ package needs no code change.
257
+
258
+ ### Notes (#5783)
259
+
260
+ #### Changed
261
+
262
+ - The browser posture reader now applies the token's `detection` claim, `automation_disclosed` and an `agent-driven` verdict, in that order, over a human or incomplete-data baseline, and `automation_corroborated` last as incomplete data. A webdriver-disclosed session now upgrades to a bot, so a policy that blocks bots now blocks it. Needs the `@kya-os/checkpoint-wasm-runtime` release that carries this reader.
263
+
3
264
  ## 1.10.0
4
265
 
5
266
  Picks up the Zod 4 flip through its dependency ranges, plus two behaviour
package/README.md CHANGED
@@ -4,45 +4,163 @@ Next.js middleware for Checkpoint AI agent detection and enforcement.
4
4
 
5
5
  ## Features
6
6
 
7
- - 🚀 **Next.js Middleware**: Edge-compatible middleware for all routes
8
- - 🧩 **Two Deployment Shapes**: In-process WASM engine or SaaS gateway
7
+ - 🚀 **Next.js Middleware**: Node.js (`proxy.ts`) and Edge runtime middleware
8
+ - 🧩 **Two Deployment Shapes**: In-process WebAssembly engine or SaaS gateway
9
9
  - 🎯 **Flexible Actions**: Block, redirect, or challenge detected agents
10
10
  - 🛡️ **Edge Runtime**: Optimized for Vercel Edge Functions
11
11
  - 📊 **Dashboard Reporting**: Detections land in your Checkpoint dashboard
12
12
 
13
13
  ## Two deployment shapes
14
14
 
15
- This package ships two complementary middleware factories. Pick the one that
16
- fits your runtime; both are first-class and supported.
15
+ This package ships two middleware factories.
16
+ Both return a Next.js middleware function with the same request and response contract, and you can use both in one app on different routes.
17
17
 
18
- | Shape | Factory | Where verification runs | Use when |
19
- | ---------------- | ------------------- | --------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
20
- | **Local engine** | `withCheckpoint` | In-process, via WASM (`kya-os-engine`) | You want the lowest possible latency, deterministic verdicts, no network round-trip per request, and your runtime can load the WASM artifact (Vercel Node, Vercel Edge with the bundled artifact, Cloudflare Workers with `nodejs_compat`). This is the canonical Phase D output. |
21
- | **SaaS gateway** | `withCheckpointApi` | Cloudflare DNS gateway (`https://detect.checkpoint-gateway.ai`) | You want centralized policy + dashboard rules without a redeploy, you're on a runtime where the WASM artifact won't load (bare-Edge, browser embedding), or you want a single HTTPS hop with cached verdicts. Trades ~30–50ms of edge latency for zero local engine state. |
22
-
23
- Both factories return a Next.js middleware function — the request/response
24
- contract is identical. You can run both side-by-side in the same app on
25
- different routes if your policy demands it.
18
+ | Shape | Factory | Where verification runs | Use when |
19
+ | ---------------- | ------------------- | --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
20
+ | **Local engine** | `withCheckpoint` | In-process, through WebAssembly (`kya-os-engine`) | You want the lowest latency, verdicts from the engine itself, and no network round trip per request. On Next.js, run it as Edge middleware; see [Runtimes and bundlers](#runtimes-and-bundlers). |
21
+ | **SaaS gateway** | `withCheckpointApi` | Cloudflare DNS gateway (`https://detect.checkpoint-gateway.ai`) | You run somewhere WebAssembly can't load, or want one HTTPS hop with centralized policy. It adds about 30 to 50 ms per request and sends request metadata to the gateway. |
26
22
 
27
23
  ```ts
28
- // middleware.ts — local engine
24
+ // middleware.ts (Edge runtime): local engine
25
+ import engineWasmModule from '@kya-os/checkpoint-nextjs/engine-wasm';
29
26
  import { withCheckpoint } from '@kya-os/checkpoint-nextjs';
30
- export default withCheckpoint({ tenantHost: 'demo.example' });
31
27
 
32
- // middleware.ts — SaaS gateway
28
+ export default withCheckpoint({
29
+ // Honor platform headers only inside Vercel's managed runtime.
30
+ clientIpPolicy: { platform: 'vercel' },
31
+ engineWasmModule,
32
+ });
33
+ ```
34
+
35
+ ```ts
36
+ // middleware.ts: SaaS gateway
33
37
  import { withCheckpointApi } from '@kya-os/checkpoint-nextjs';
38
+
34
39
  export default withCheckpointApi({
40
+ // Honor platform headers only inside Vercel's managed runtime.
41
+ clientIpPolicy: { platform: 'vercel' },
35
42
  apiKey: process.env.CHECKPOINT_API_KEY!,
36
43
  onBlock: 'redirect',
37
44
  redirectUrl: '/blocked',
38
45
  });
39
46
  ```
40
47
 
41
- > Pre-Phase-D the SaaS-gateway factory shipped as `withAgentShield`; the
42
- > name is preserved as a `@deprecated` alias for one release. Same for
43
- > `AgentShieldClient` / `AgentShieldClientConfig` → `CheckpointApiClient`
44
- > / `CheckpointApiClientConfig`. New code should import the
45
- > `Checkpoint*` names.
48
+ ## Runtimes and bundlers
49
+
50
+ `withCheckpoint` loads the engine's WebAssembly inside your middleware, so what works depends on the runtime and the bundler.
51
+ On Next.js, run it as Edge middleware: that works with Turbopack and webpack.
52
+
53
+ | Middleware file | Import | Turbopack (Next.js 16 default) | webpack (Next.js 15 default) |
54
+ | ------------------------------------------------------- | --------------------------------------------------- | ------------------------------ | -------------------------------------------------- |
55
+ | `middleware.ts` on the Edge runtime (recommended) | `@kya-os/checkpoint-nextjs` with `engineWasmModule` | Supported | Supported with [`unstable_allowDynamic`](#webpack) |
56
+ | `proxy.ts`, or `middleware.ts` with `runtime: 'nodejs'` | `@kya-os/checkpoint-nextjs` | Supported | Not supported yet |
57
+
58
+ `withCheckpointApi` needs no WebAssembly and works with either bundler and either runtime; on webpack's Edge runtime it needs the [`unstable_allowDynamic`](#webpack) config too.
59
+
60
+ ### Edge runtime
61
+
62
+ The Edge runtime does not let code compile WebAssembly from bytes, so the engine has to arrive as a compiled `WebAssembly.Module`.
63
+ Import it from `@kya-os/checkpoint-nextjs/engine-wasm` and pass it as `engineWasmModule`:
64
+
65
+ ```ts
66
+ // middleware.ts (Edge runtime)
67
+ import engineWasmModule from '@kya-os/checkpoint-nextjs/engine-wasm';
68
+ import { withCheckpoint } from '@kya-os/checkpoint-nextjs';
69
+
70
+ export default withCheckpoint({
71
+ clientIpPolicy: { platform: 'vercel' },
72
+ engineWasmModule,
73
+ });
74
+
75
+ export const config = {
76
+ matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
77
+ };
78
+ ```
79
+
80
+ `/engine-wasm` imports the binary from this package's own `@kya-os/checkpoint-wasm-runtime` dependency, so it always matches the engine code that loads it, and your app needs no direct dependency on that package.
81
+ On the Edge runtime, `@kya-os/checkpoint-nextjs` resolves to the Edge build (export conditions `edge-light`, `edge-runtime`, `workerd` and `worker`, the same as `/edge`), and without `engineWasmModule` every request is answered 503 and the missing module is logged.
82
+
83
+ #### Cedar policies on the Edge runtime
84
+
85
+ To evaluate the project's Cedar policy on the Edge runtime, pass the Cedar build as `engineWasmModule`, in place of the engine-only build.
86
+ The Cedar build is the engine plus the Cedar policy evaluator, so one module runs detection and the policy:
87
+
88
+ ```ts
89
+ import engineWasmModule from '@kya-os/checkpoint-nextjs/cedar-wasm';
90
+ import { withCheckpoint } from '@kya-os/checkpoint-nextjs';
91
+
92
+ export default withCheckpoint({
93
+ projectId: process.env.CHECKPOINT_PROJECT_ID,
94
+ engineWasmModule,
95
+ });
96
+ ```
97
+
98
+ It is opt-in because it is larger than the engine-only build.
99
+ Configs that pass it as `cedarWasmModule` keep working: on its own it serves both roles, and next to the engine-only build it runs as a second instance, so the bundle carries the engine twice (with `debug`, a hint is logged).
100
+
101
+ Without a Cedar module the project's policy is still fetched and never skipped.
102
+ A project with no Cedar policy is unaffected, and a policy in shadow mode keeps the structured decision.
103
+ A project whose Cedar policy is enforcing has every request answered 503, and the missing module is logged once.
104
+
105
+ The Edge middleware bundle, gzipped, measured in a Next.js 16 app (Turbopack) whose middleware is `withCheckpoint` alone:
106
+
107
+ | Modules | Edge bundle | Vercel Edge limit |
108
+ | ------------------------------------------------------ | ------------- | -------------------------- |
109
+ | `/engine-wasm` as `engineWasmModule` | about 0.94 MB | fits Hobby (1 MB) |
110
+ | `/cedar-wasm` as `engineWasmModule` | about 1.38 MB | fits Pro (2 MB), not Hobby |
111
+ | `/engine-wasm` plus `/cedar-wasm` as `cedarWasmModule` | about 2.13 MB | exceeds Pro |
112
+
113
+ Your own middleware code adds to these.
114
+ If the bundle does not fit your plan, use `withCheckpointApi`, which carries no WebAssembly.
115
+
116
+ ### webpack
117
+
118
+ On the Edge runtime, webpack rejects any module that contains code able to evaluate code at runtime, even when that code never runs.
119
+ Two dependencies trip the check, so allow them in the middleware config:
120
+
121
+ ```ts
122
+ export const config = {
123
+ matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
124
+ unstable_allowDynamic: [
125
+ // The Zod schema library bundled into checkpoint-shared probes for `new Function`
126
+ // support inside a try/catch (its allowsEval check).
127
+ '**/@kya-os/checkpoint-shared/dist/**',
128
+ // The engine's wasm-bindgen glue can compile WebAssembly from bytes; passing
129
+ // engineWasmModule means that path never runs.
130
+ '**/@kya-os/checkpoint-wasm-runtime/wasm/**',
131
+ ],
132
+ };
133
+ ```
134
+
135
+ `withCheckpointApi` needs both entries when you import it from `@kya-os/checkpoint-nextjs`, because on the Edge runtime that is the Edge build, which includes the engine glue.
136
+ Import it from `@kya-os/checkpoint-nextjs/api-middleware` and only the `checkpoint-shared` entry is needed.
137
+
138
+ ### Node.js runtime
139
+
140
+ On the Node.js runtime, `@kya-os/checkpoint-nextjs` runs the engine's Node build, which loads its `.wasm` through `new URL(..., import.meta.url)`.
141
+ Next.js always bundles `proxy.ts` and `middleware.ts`, and Turbopack follows that URL and copies the file into the build output, so the same build works bundled and unbundled.
142
+ `@kya-os/checkpoint-nextjs/node` is the same build.
143
+
144
+ In a minimal Next.js 16 app, `proxy.ts` with `withCheckpoint` traces 117 files (5.6 MiB), against 111 files for a `proxy.ts` without it.
145
+ If the engine cannot load (a missing or unreadable `.wasm`), every request is answered 503, the cause is logged, and the next request tries again.
146
+
147
+ On webpack, the Node.js runtime is not supported yet: the build succeeds, but webpack rewrites the `.wasm` URL into a value Node's file read rejects, so the engine fails to load and every request is answered 503.
148
+
149
+ ### Background work
150
+
151
+ A request can start work that outlives its response: a refresh of the engine's vendor keys, and the detection report when `apiKey` is set.
152
+ `withCheckpoint` registers that work with the `waitUntil` of the event Next.js passes to middleware, so Vercel does not cancel it once the response is sent.
153
+ If you wrap `withCheckpoint` in your own middleware, pass the event through:
154
+
155
+ ```ts
156
+ const checkpoint = withCheckpoint({});
157
+
158
+ export default function middleware(request: NextRequest, event: NextFetchEvent) {
159
+ return checkpoint(request, event);
160
+ }
161
+ ```
162
+
163
+ Without an event, it falls back to `waitUntil` from `@vercel/functions`, which only has an effect on Vercel.
46
164
 
47
165
  ## Installation
48
166
 
@@ -54,17 +172,23 @@ npm install @kya-os/checkpoint-nextjs
54
172
 
55
173
  ## Client-IP trust policy
56
174
 
57
- Client-IP resolution defaults to the direct framework or socket peer. For a
58
- Next.js deployment behind Vercel, select the Vercel profile explicitly:
175
+ Set `clientIpPolicy` to resolve an observed client address only where the runtime can authenticate its source. Next.js 15 removed `request.ip`; the default `direct` policy therefore returns no address on current NextRequest objects.
59
176
 
60
- withCheckpoint({
61
- tenantHost: 'your.tenant.example',
62
- clientIpPolicy: { platform: 'vercel' },
63
- });
177
+ | Deployment | Configuration and result |
178
+ | --------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
179
+ | Vercel managed runtime | `{ platform: 'vercel' }` accepts Vercel's overwritten singleton address header when `VERCEL=1` |
180
+ | Legacy Next runtime with a platform-provided `request.ip` | `{ platform: 'direct' }` uses that framework address |
181
+ | Self-hosted Next behind a proxy or Cloudflare | No authenticated address is available through NextRequest; `trusted-proxy` and `cloudflare` return no address |
64
182
 
65
- Forwarding headers are normalized and are not trusted by the middleware
66
- without a matching deployment profile. See the client-IP resolution runbook
67
- for the profile matrix and proxy-chain guidance.
183
+ The Next adapter adopts the strict `resolveObservedClientAddress` contract. Selecting a profile does not authenticate a forwarding header. NextRequest exposes no socket peer for the SDK to verify. Supplying `isTrustedPeer` cannot provide the missing transport address. The SDK withholds the address from both verification and reporting when that boundary is unavailable.
184
+
185
+ For Vercel, keep `clientIpPolicy: { platform: 'vercel' }` and use the runtime-provided `VERCEL=1` signal. Do not set that variable manually on a self-hosted application to enable header trust. Outside Vercel, the Next adapter resolves this profile like `direct`.
186
+
187
+ #### Migrate self-hosted proxy configurations
188
+
189
+ Earlier versions accepted Cloudflare or X-Forwarded-For values when a profile was selected. Those configurations now return no address through NextRequest. Configure a transport-aware ingress, such as `@kya-os/checkpoint-express`, to verify the actual proxy peer and exact forwarding chain. Keep the Next application on `direct` until it has an authenticated address source. Do not copy a header into `request.ip` or invent a peer value to restore the old behavior.
190
+
191
+ Unavailable address evidence does not establish a clean network result. The strict resolver returns `status: 'unavailable'`, a reason, and a null `observedClientAddress`; the Next adapter returns `undefined` for its compatibility API. See the [client-IP resolution runbook](https://github.com/Know-That-Ai/checkpoint/blob/main/docs/runbooks/client-ip-resolution.md) for the supported boundaries and migration checks.
68
192
 
69
193
  ### Middleware Setup
70
194
 
@@ -74,6 +198,8 @@ Create `middleware.js` (or `middleware.ts`) in your project root:
74
198
  import { withCheckpointApi } from '@kya-os/checkpoint-nextjs';
75
199
 
76
200
  export default withCheckpointApi({
201
+ // Honor platform headers only inside Vercel's managed runtime.
202
+ clientIpPolicy: { platform: 'vercel' },
77
203
  apiKey: process.env.CHECKPOINT_API_KEY,
78
204
  });
79
205
 
@@ -129,8 +255,9 @@ export default withCheckpointApi({
129
255
  // Request timeout in ms. Default: 5000
130
256
  timeout: 5000,
131
257
 
132
- // Fail open (allow) on API errors. Default: true
133
- failOpen: true,
258
+ // Fail open (allow) on API errors. Default: false (503 + Retry-After).
259
+ // Requests that present a credential are answered 503 even when true.
260
+ failOpen: false,
134
261
 
135
262
  // Observability callback when an agent is detected
136
263
  onAgentDetected: async (request, decision) => {
@@ -142,13 +269,39 @@ export default withCheckpointApi({
142
269
  });
143
270
  ```
144
271
 
145
- The local-engine shape (`withCheckpoint`) takes a `CheckpointConfig` instead:
146
- `tenantHost` (required), plus optional `enforcementMode` (`'enforce'` |
147
- `'observe'`), `apiKey` (enables dashboard reporting), `projectId` (enforces
148
- your deployed dashboard policy in-process), and more. See the
272
+ The local-engine shape (`withCheckpoint`) takes a `CheckpointConfig` instead,
273
+ every field optional: `enforcementMode` (`'enforce'` | `'observe'`), `apiKey`
274
+ (enables dashboard reporting), `projectId` (enforces your deployed dashboard
275
+ policy in-process), and more. `tenantHost` is deprecated: it is no longer used
276
+ and will be removed. See the
149
277
  [middleware docs](https://kya.vouched.id/docs/enforce/middleware) for the
150
278
  full option tables for both shapes.
151
279
 
280
+ ## Failure behavior
281
+
282
+ `withCheckpoint` answers `503` (`Retry-After: 3`, `Cache-Control: no-store`)
283
+ when the verification pipeline errors; it never passes the request through or
284
+ returns a 500. If the policy API is unreachable, the last successfully fetched
285
+ policy (at most 24h old) is served; with none, the request is answered `503`
286
+ and the default policy is never substituted. The last-good copy lives in
287
+ process memory and, when a `PolicyCacheAdapter` is configured, in that adapter
288
+ (so a cold process or isolate can still serve it). A policy-origin 401/403/404
289
+ or a body that is not a policy-API response is treated like an outage:
290
+ last-good is served for up to 24h.
291
+
292
+ ### DID documents and status lists
293
+
294
+ The engine names every DID document and status list a request needs, after its own trust checks, and `withCheckpoint` fetches only what it names, before the request is decided.
295
+ A status list that cannot be fetched or verified is answered `503` with `Retry-After: 1` (`kyaos/status-pending`); a request signer's DID document that cannot be fetched is refused (`401 kyaos/did-unresolvable`).
296
+
297
+ On the Node.js runtime each fetch connects only to a public address its own DNS lookup checked, refuses redirects, caps the body and has a deadline.
298
+ The Edge runtime has no connect hook, so there the same rules apply except the address check, and the platform's egress rules are what keep a fetch off private addresses.
299
+ `adapters.fetch` replaces the transport, and the connect-time address check becomes your job: a custom `fetch` must connect only to a vetted public address (check every address DNS returns, and never re-resolve), refuse redirects, cap the body and enforce a deadline.
300
+ `safeGet`, `makeSafeLookup` and `isBlockedIpAddress` from `@kya-os/checkpoint-wasm-runtime/adapters` are the pieces the default uses.
301
+
302
+ `withCheckpoint` itself never throws, because a Next.js middleware module that fails to load can let requests through unchecked.
303
+ An invalid configuration (for example a missing `engineWasmModule` on the Edge runtime) and an engine that fails to load (for example an unreadable `.wasm`) are logged with a `[checkpoint]` prefix and every request is answered `503`.
304
+
152
305
  ## Actions
153
306
 
154
307
  ### Block Agents
@@ -318,3 +471,32 @@ MIT OR Apache-2.0
318
471
 
319
472
  For opt-in classification, signed posture and scoped consent step-up, see the
320
473
  [browser integrity rollout runbook](../../docs/runbooks/browser-integrity.md).
474
+
475
+ ### Reading the browser posture outcome
476
+
477
+ With `browserPosture` configured, read the posture outcome for a request in a route
478
+ handler or page. The accessor verifies the posture token from the request's `KYA-Posture`
479
+ headers or cookies with the same verifier and the same posture config the middleware
480
+ uses, so nothing is forwarded and there is no extra secret:
481
+
482
+ ```ts
483
+ import { getCheckpointPostureOutcome } from '@kya-os/checkpoint-nextjs';
484
+ import { browserPosture, projectId } from '@/checkpoint-config';
485
+
486
+ export async function POST(request: Request) {
487
+ const outcome = await getCheckpointPostureOutcome(request, { browserPosture, projectId });
488
+ return Response.json({ posture: outcome.status, verdict: outcome.posture?.verdict });
489
+ }
490
+ ```
491
+
492
+ The result is `{ status: 'verified' | 'absent' | 'rejected', reason?, posture? }`, with
493
+ `posture` (the verified claims, as a frozen copy) only when verified. The accessor always
494
+ checks: it returns `verified`, `absent` or `rejected` for the request it is given, and does
495
+ not depend on the middleware having run or on the route matching it. `status: 'verified'`
496
+ means the token signature and claims are valid, so check `posture.verdict` before treating
497
+ the visitor as human. Given a bare `Headers` (for example `await headers()` in a server
498
+ component), pass those instead of a request. Verification is a single ES256 check, so
499
+ calling it in a handler as well as in the middleware costs little. A verified token that carries
500
+ the beacon's agent or bot verdict (`posture.detection`), or discloses automation, also
501
+ reclassifies a request the engine called human or incomplete data.
502
+ The accessor validates `browserPosture` and `projectId` with the same check `withCheckpoint` runs at startup: `projectId` must be the lowercase project UUID, not the friendly id, and any invalid config throws. Pass the same config object the middleware takes. Treat `absent` and `rejected` alike (neither is usable posture evidence), and log `reason` on the server rather than returning it to the client.
@@ -1,5 +1,6 @@
1
- import { BLOCKED_PATH, VERDICT_COOKIE_NAME, acceptsHtml, classifyResponseShape, encodeVerdictCookie } from "@kya-os/checkpoint-shared";
2
- import { NextResponse } from "next/server";
1
+ import { NextResponse } from "next/server.js";
2
+ import { BLOCKED_PATH, VERDICT_COOKIE_NAME, acceptsHtml, classifyResponseShape, encodeVerdictCookie } from "@kya-os/checkpoint-shared/host-adapter";
3
+ import { FAIL_CLOSED_BODY, FAIL_CLOSED_HEADERS, FAIL_CLOSED_STATUS } from "@kya-os/checkpoint-shared/policy/enforcement";
3
4
 
4
5
  //#region src/adapt.ts
5
6
  /**
@@ -30,6 +31,16 @@ import { NextResponse } from "next/server";
30
31
  * deviation note confirmed the `X-Checkpoint-*` prefix is canon.
31
32
  */
32
33
  /**
34
+ * 503 (Retry-After, no-store) for an engine/pipeline fault. Never a 500 and
35
+ * never a pass-through: an unverifiable request is not allowed.
36
+ */
37
+ function failClosedResponse() {
38
+ return NextResponse.json(FAIL_CLOSED_BODY, {
39
+ status: FAIL_CLOSED_STATUS,
40
+ headers: FAIL_CLOSED_HEADERS
41
+ });
42
+ }
43
+ /**
33
44
  * Convert the engine's transport-agnostic `RenderedResponse` into a
34
45
  * `NextResponse`. Sites-1's Playwright suite is the regression gate;
35
46
  * any drift here is caught downstream.
@@ -82,5 +93,5 @@ function applyHeaders(res, rendered) {
82
93
  }
83
94
 
84
95
  //#endregion
85
- export { adaptToNextResponse };
86
- //# sourceMappingURL=adapt.mjs.map
96
+ export { failClosedResponse as n, adaptToNextResponse as t };
97
+ //# sourceMappingURL=adapt-BvqYgrAk.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapt-BvqYgrAk.mjs","names":[],"sources":["../src/adapt.ts"],"sourcesContent":["/**\n * D.3 — `RenderedResponse` → `NextResponse` adapter.\n *\n * The host wrapper's *only* job on the outbound path: take the\n * transport-agnostic `RenderedResponse` Phase C's\n * `renderDecisionAsResponse` produces and translate it to a\n * `NextResponse`. Zero verdict decisions, zero engine I/O.\n *\n * Shared between the Node-runtime and Edge-runtime entries. The\n * branching here is identical in both — Next.js `NextResponse` has the\n * same API surface across runtimes; only the underlying response\n * primitive differs (Node http.ServerResponse vs Edge `Response`).\n *\n * Architectural pins per architect § 4.3 / § 4.4:\n *\n * 1. **Verdict-cookie format is contract.** Sites-1's Sonner toast\n * depends on `__checkpoint_verdict=%7B%22verdict%22%3A%22<v>%22...\n * %7D` (single URL-encoded JSON). Byte-format pinned by adapt.test.\n *\n * 2. **HTML-accepting clients → `/blocked` rewrite at status 200**\n * (so the page renders with the verdict cookie set; Sonner picks\n * up the cookie and shows the toast). Non-HTML clients → JSON 4xx.\n *\n * 3. **`X-Checkpoint-Engine` carries `result.engineInfo.name`** —\n * `checkpoint-engine-wasm` after Phase D ships. Brian's Sites-2\n * deviation note confirmed the `X-Checkpoint-*` prefix is canon.\n */\n\nimport { type NextRequest, NextResponse } from 'next/server.js';\n\nimport type { RenderedResponse } from '@kya-os/checkpoint-wasm-runtime/orchestrator';\nimport {\n VERDICT_COOKIE_NAME,\n BLOCKED_PATH,\n encodeVerdictCookie,\n acceptsHtml,\n classifyResponseShape,\n} from '@kya-os/checkpoint-shared/host-adapter';\nimport {\n FAIL_CLOSED_BODY,\n FAIL_CLOSED_HEADERS,\n FAIL_CLOSED_STATUS,\n} from '@kya-os/checkpoint-shared/policy/enforcement';\n\n/**\n * 503 (Retry-After, no-store) for an engine/pipeline fault. Never a 500 and\n * never a pass-through: an unverifiable request is not allowed.\n */\nexport function failClosedResponse(): NextResponse {\n return NextResponse.json(FAIL_CLOSED_BODY, {\n status: FAIL_CLOSED_STATUS,\n headers: FAIL_CLOSED_HEADERS,\n });\n}\n\n/**\n * Convert the engine's transport-agnostic `RenderedResponse` into a\n * `NextResponse`. Sites-1's Playwright suite is the regression gate;\n * any drift here is caught downstream.\n */\nexport function adaptToNextResponse(rendered: RenderedResponse, req: NextRequest): NextResponse {\n const clientAcceptsHtml = acceptsHtml(req.headers);\n const verdictCookie = encodeVerdictCookie(rendered);\n const shape = classifyResponseShape(rendered, clientAcceptsHtml);\n\n switch (shape) {\n case 'pass-through': {\n // Permit OR Observe-mode any-verdict.\n const res = NextResponse.next();\n applyHeaders(res, rendered);\n setVerdictCookie(res, verdictCookie);\n return res;\n }\n\n case 'redirect': {\n // Decision::Redirect → 302 + Location.\n const target = new URL(rendered.headers.Location!);\n const res = NextResponse.redirect(target);\n applyHeaders(res, rendered);\n setVerdictCookie(res, verdictCookie);\n return res;\n }\n\n case 'html-block': {\n // Sites-1 contract: HTML clients (browsers) need a renderable page\n // to show the rejection UI. The verdict cookie carries the reason;\n // the /blocked route reads it and renders the toast.\n const blockedUrl = new URL(BLOCKED_PATH, req.url);\n const res = NextResponse.rewrite(blockedUrl, { status: 200 });\n applyHeaders(res, rendered);\n setVerdictCookie(res, verdictCookie);\n return res;\n }\n\n case 'json-block': {\n // The orchestrator's RenderedResponse already supplies the correct\n // status (401/403/422/...); we just need to materialise the body.\n // application/problem+json (Instruct) uses the Content-Type from\n // rendered.headers; defaults to application/json for everything else.\n const body = rendered.body ?? {};\n const res = NextResponse.json(body, { status: rendered.status as number });\n applyHeaders(res, rendered);\n setVerdictCookie(res, verdictCookie);\n return res;\n }\n }\n}\n\n// -----------------------------------------------------------------------------\n// Helpers — Next.js-specific glue. The framework-agnostic primitives\n// (encodeVerdictCookie, acceptsHtml, classifyResponseShape,\n// VERDICT_COOKIE_NAME, BLOCKED_PATH) live in `@kya-os/checkpoint-shared`\n// so checkpoint-express + future host wrappers produce byte-identical\n// cookies and route HTML/JSON branching the same way.\n// -----------------------------------------------------------------------------\n\nfunction setVerdictCookie(res: NextResponse, value: string): void {\n // Path / SameSite / HttpOnly chosen for the Sonner-bridge use case:\n // path=/ so any route can read it, SameSite=Lax so first-party\n // navigations carry it, HttpOnly=false so the client-side toast JS\n // can read it (it's verdict UX, not a session token).\n res.cookies.set({\n name: VERDICT_COOKIE_NAME,\n value,\n path: '/',\n sameSite: 'lax',\n httpOnly: false,\n });\n}\n\nfunction applyHeaders(res: NextResponse, rendered: RenderedResponse): void {\n // NextResponse.next() / rewrite() / json() return responses with\n // some default headers; orchestrator headers (X-Checkpoint-*, Location)\n // override. We don't strip pre-existing headers — only set new ones.\n for (const [key, value] of Object.entries(rendered.headers)) {\n res.headers.set(key, value);\n }\n for (const [key, value] of rendered.headerEntries ?? []) {\n res.headers.append(key, value);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,SAAgB,qBAAmC;CACjD,OAAO,aAAa,KAAK,kBAAkB;EACzC,QAAQ;EACR,SAAS;CACX,CAAC;AACH;;;;;;AAOA,SAAgB,oBAAoB,UAA4B,KAAgC;CAC9F,MAAM,oBAAoB,YAAY,IAAI,OAAO;CACjD,MAAM,gBAAgB,oBAAoB,QAAQ;CAGlD,QAFc,sBAAsB,UAAU,iBAElC,GAAZ;EACE,KAAK,gBAAgB;GAEnB,MAAM,MAAM,aAAa,KAAK;GAC9B,aAAa,KAAK,QAAQ;GAC1B,iBAAiB,KAAK,aAAa;GACnC,OAAO;EACT;EAEA,KAAK,YAAY;GAEf,MAAM,SAAS,IAAI,IAAI,SAAS,QAAQ,QAAS;GACjD,MAAM,MAAM,aAAa,SAAS,MAAM;GACxC,aAAa,KAAK,QAAQ;GAC1B,iBAAiB,KAAK,aAAa;GACnC,OAAO;EACT;EAEA,KAAK,cAAc;GAIjB,MAAM,aAAa,IAAI,IAAI,cAAc,IAAI,GAAG;GAChD,MAAM,MAAM,aAAa,QAAQ,YAAY,EAAE,QAAQ,IAAI,CAAC;GAC5D,aAAa,KAAK,QAAQ;GAC1B,iBAAiB,KAAK,aAAa;GACnC,OAAO;EACT;EAEA,KAAK,cAAc;GAKjB,MAAM,OAAO,SAAS,QAAQ,CAAC;GAC/B,MAAM,MAAM,aAAa,KAAK,MAAM,EAAE,QAAQ,SAAS,OAAiB,CAAC;GACzE,aAAa,KAAK,QAAQ;GAC1B,iBAAiB,KAAK,aAAa;GACnC,OAAO;EACT;CACF;AACF;AAUA,SAAS,iBAAiB,KAAmB,OAAqB;CAKhE,IAAI,QAAQ,IAAI;EACd,MAAM;EACN;EACA,MAAM;EACN,UAAU;EACV,UAAU;CACZ,CAAC;AACH;AAEA,SAAS,aAAa,KAAmB,UAAkC;CAIzE,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,SAAS,OAAO,GACxD,IAAI,QAAQ,IAAI,KAAK,KAAK;CAE5B,KAAK,MAAM,CAAC,KAAK,UAAU,SAAS,iBAAiB,CAAC,GACpD,IAAI,QAAQ,OAAO,KAAK,KAAK;AAEjC"}