@kya-os/checkpoint-nextjs 1.10.0 → 1.11.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 (210) hide show
  1. package/CHANGELOG.md +245 -0
  2. package/README.md +205 -31
  3. package/dist/{adapt.mjs → adapt-BdQ9R7Iw.mjs} +15 -4
  4. package/dist/adapt-BdQ9R7Iw.mjs.map +1 -0
  5. package/dist/{adapt.js → adapt-CCSKGjVH.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-BWjokNis.d.mts +131 -0
  16. package/dist/api-middleware-BWjokNis.d.mts.map +1 -0
  17. package/dist/{api-middleware-CDSh3TSE.js → api-middleware-Bf3xmM9W.js} +75 -63
  18. package/dist/{api-middleware-CMDRoQik.mjs → api-middleware-C-ngFX_8.mjs} +68 -38
  19. package/dist/api-middleware-C-ngFX_8.mjs.map +1 -0
  20. package/dist/api-middleware-DyLDqOYF.d.ts +131 -0
  21. package/dist/api-middleware-DyLDqOYF.d.ts.map +1 -0
  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-Doe0Tn53.d.mts → config-CPP1RV0f.d.mts} +65 -29
  34. package/dist/config-CPP1RV0f.d.mts.map +1 -0
  35. package/dist/{config-CbAg2mze.d.ts → config-DVgOFxJs.d.ts} +66 -30
  36. package/dist/config-DVgOFxJs.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 +4 -4
  58. package/dist/middleware-bundler.mjs +4 -4
  59. package/dist/middleware-bundler.mjs.map +1 -1
  60. package/dist/middleware-core-B0jf5_Hm.mjs +264 -0
  61. package/dist/middleware-core-B0jf5_Hm.mjs.map +1 -0
  62. package/dist/middleware-core-Bol44X9C.d.ts +17 -0
  63. package/dist/middleware-core-Bol44X9C.d.ts.map +1 -0
  64. package/dist/middleware-core-CMc-2QkU.js +274 -0
  65. package/dist/middleware-core-DycsbHUd.d.mts +17 -0
  66. package/dist/middleware-core-DycsbHUd.d.mts.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 +77 -24
  72. package/dist/middleware-edge.mjs +74 -23
  73. package/dist/middleware-edge.mjs.map +1 -1
  74. package/dist/{middleware-node-context-rgnc7UNR.js → middleware-node-context-591KsiYg.js} +8 -7
  75. package/dist/{middleware-node-context-BqPbf-fI.mjs → middleware-node-context-D_ZyUEcA.mjs} +6 -5
  76. package/dist/middleware-node-context-D_ZyUEcA.mjs.map +1 -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 +13 -5
  82. package/dist/middleware-node.mjs +13 -5
  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-CYsHrTQI.d.ts +5 -0
  92. package/dist/public-api-DkG7pRE0.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.map +0 -1
  120. package/dist/config-Doe0Tn53.d.mts.map +0 -1
  121. package/dist/create-middleware.d.mts +0 -11
  122. package/dist/create-middleware.d.mts.map +0 -1
  123. package/dist/create-middleware.d.ts +0 -11
  124. package/dist/create-middleware.d.ts.map +0 -1
  125. package/dist/create-middleware.js +0 -39
  126. package/dist/create-middleware.mjs +0 -38
  127. package/dist/create-middleware.mjs.map +0 -1
  128. package/dist/edge/index.d.mts +0 -88
  129. package/dist/edge/index.d.mts.map +0 -1
  130. package/dist/edge/index.d.ts +0 -88
  131. package/dist/edge/index.d.ts.map +0 -1
  132. package/dist/edge/index.js +0 -362
  133. package/dist/edge/index.mjs +0 -362
  134. package/dist/edge/index.mjs.map +0 -1
  135. package/dist/edge-runtime-loader.d.mts +0 -49
  136. package/dist/edge-runtime-loader.d.mts.map +0 -1
  137. package/dist/edge-runtime-loader.d.ts +0 -49
  138. package/dist/edge-runtime-loader.d.ts.map +0 -1
  139. package/dist/edge-runtime-loader.js +0 -297
  140. package/dist/edge-runtime-loader.mjs +0 -292
  141. package/dist/edge-runtime-loader.mjs.map +0 -1
  142. package/dist/edge-wasm-middleware.d.mts +0 -43
  143. package/dist/edge-wasm-middleware.d.mts.map +0 -1
  144. package/dist/edge-wasm-middleware.d.ts +0 -43
  145. package/dist/edge-wasm-middleware.d.ts.map +0 -1
  146. package/dist/edge-wasm-middleware.js +0 -37
  147. package/dist/edge-wasm-middleware.mjs +0 -35
  148. package/dist/edge-wasm-middleware.mjs.map +0 -1
  149. package/dist/middleware-core-BYQP9FND.mjs +0 -165
  150. package/dist/middleware-core-BYQP9FND.mjs.map +0 -1
  151. package/dist/middleware-core-D6TijE6P.js +0 -175
  152. package/dist/middleware-node-CE4GevYs.d.ts +0 -20
  153. package/dist/middleware-node-CE4GevYs.d.ts.map +0 -1
  154. package/dist/middleware-node-DtyOuPta.d.mts +0 -20
  155. package/dist/middleware-node-DtyOuPta.d.mts.map +0 -1
  156. package/dist/middleware-node-context-BqPbf-fI.mjs.map +0 -1
  157. package/dist/middleware.d.mts +0 -25
  158. package/dist/middleware.d.mts.map +0 -1
  159. package/dist/middleware.d.ts +0 -25
  160. package/dist/middleware.d.ts.map +0 -1
  161. package/dist/middleware.js +0 -53
  162. package/dist/middleware.mjs +0 -51
  163. package/dist/middleware.mjs.map +0 -1
  164. package/dist/nodejs-wasm-loader.d.mts +0 -42
  165. package/dist/nodejs-wasm-loader.d.mts.map +0 -1
  166. package/dist/nodejs-wasm-loader.d.ts +0 -42
  167. package/dist/nodejs-wasm-loader.d.ts.map +0 -1
  168. package/dist/nodejs-wasm-loader.js +0 -70
  169. package/dist/nodejs-wasm-loader.mjs +0 -66
  170. package/dist/nodejs-wasm-loader.mjs.map +0 -1
  171. package/dist/policy.d.mts +0 -138
  172. package/dist/policy.d.mts.map +0 -1
  173. package/dist/policy.d.ts +0 -138
  174. package/dist/policy.d.ts.map +0 -1
  175. package/dist/policy.js +0 -236
  176. package/dist/policy.mjs +0 -205
  177. package/dist/policy.mjs.map +0 -1
  178. package/dist/session-tracker.d.mts +0 -50
  179. package/dist/session-tracker.d.mts.map +0 -1
  180. package/dist/session-tracker.d.ts +0 -50
  181. package/dist/session-tracker.d.ts.map +0 -1
  182. package/dist/session-tracker.js +0 -148
  183. package/dist/session-tracker.mjs +0 -147
  184. package/dist/session-tracker.mjs.map +0 -1
  185. package/dist/translate.d.mts +0 -48
  186. package/dist/translate.d.mts.map +0 -1
  187. package/dist/translate.d.ts +0 -48
  188. package/dist/translate.d.ts.map +0 -1
  189. package/dist/translate.js +0 -79
  190. package/dist/translate.mjs +0 -79
  191. package/dist/translate.mjs.map +0 -1
  192. package/dist/types-C0SkqLMM.d.mts +0 -102
  193. package/dist/types-C0SkqLMM.d.mts.map +0 -1
  194. package/dist/types-C7DNSCTO.d.ts +0 -102
  195. package/dist/types-C7DNSCTO.d.ts.map +0 -1
  196. package/dist/utils-Cj4XNhIY.mjs +0 -35
  197. package/dist/utils-Cj4XNhIY.mjs.map +0 -1
  198. package/dist/utils-DAisnYnI.js +0 -45
  199. package/dist/wasm-setup.d.mts +0 -47
  200. package/dist/wasm-setup.d.mts.map +0 -1
  201. package/dist/wasm-setup.d.ts +0 -47
  202. package/dist/wasm-setup.d.ts.map +0 -1
  203. package/dist/wasm-setup.js +0 -91
  204. package/dist/wasm-setup.mjs +0 -95
  205. package/dist/wasm-setup.mjs.map +0 -1
  206. package/wasm/agentshield_wasm.d.ts +0 -479
  207. package/wasm/agentshield_wasm.js +0 -1536
  208. package/wasm/agentshield_wasm_bg.wasm +0 -0
  209. package/wasm/package.json +0 -30
  210. package/wasm.d.ts +0 -21
package/CHANGELOG.md CHANGED
@@ -1,5 +1,250 @@
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.11.0 - 2026-10-21
6
+
7
+ ### Added
8
+
9
+ - `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)
10
+
11
+ ### Changed
12
+
13
+ - 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.
14
+ If the engine cannot load, every request is answered 503, the cause is logged, and the next request tries again.
15
+ webpack on the Node.js runtime is still not supported: it now builds, then answers every request 503 with the cause logged. (#6438)
16
+
17
+ ### Other merged changes
18
+
19
+ - chore(release): set nextjs and express to 1.10.0 in package.json and the version literal (#5192)
20
+ - chore: remove comments that excuse unresolved design debt (#5224)
21
+ - fix(deps): update next to 16.3.5 security release (#4993)
22
+ - chore(deps): remove unused dependencies and import cycles (#5299)
23
+ - fix(detection): detection pattern and fingerprint accuracy pass (#5437)
24
+ - fix(policy): verify authentication and make backfill claims atomic (#5687)
25
+ - chore(deps): patch security advisories (next 16.3.8, pnpm overrides) (#5833)
26
+ - Revert "fix(detection): classify zero-evidence requests as unknown instead of human" (#5881)
27
+ - fix(detection): classify zero-evidence requests as unknown instead of human (#5886)
28
+ - feat(nextjs): make @kya-os/checkpoint-nextjs engine-only and fix its next.js entries (#6271)
29
+ - fix(nextjs): load every entry in plain node esm (#6312)
30
+ - fix(nextjs): fail closed on edge when an enforcing cedar policy has no module (#6298)
31
+ - refactor(wasm-runtime): add make engine defaults and share it across the sdks (#6303)
32
+ - perf(sdk): load lean checkpoint-shared entries in express and next.js (#6306)
33
+ - fix(wasm-runtime): stop fetching a tenant policy that does not exist (#6301)
34
+ - fix(sdk): raise the node floor to the versions that can require an es module (#6293)
35
+ - feat(nextjs): run edge detection and cedar on one module (#6343)
36
+ - refactor(wasm-runtime): one composed-policy context for express and next.js (#6360)
37
+
38
+ ### Notes (#5387)
39
+
40
+ - Browser posture is also read from the `KYA-Posture` and
41
+ `KYA-Posture-Session` request headers, which a page on another host, or one
42
+ that blocks cookies, sends from the beacon's `onReceipt`. Each header wins
43
+ over its cookie. Needs `@kya-os/checkpoint-wasm-runtime` and
44
+ `@kya-os/checkpoint-shared` releases that carry `postureFromRequest`.
45
+
46
+ ### Notes (#5508)
47
+
48
+ - `withCheckpointApi` now reports the decision it acted on, the engine that
49
+ made it, and itself. The detection it logs carries `enforcement.action`,
50
+ the gateway's engine info under the name `checkpoint-remote`, and an `sdk`
51
+ block (package, version, and `node` or `edge`). Activity previously showed
52
+ these rows as "Unrecognized runtime" with no verdict. The `sdk` block is
53
+ omitted when the build injected no package version.
54
+
55
+ ### Notes (#5410)
56
+
57
+ #### Changed
58
+
59
+ - **Action for Next.js 15 users:** set `clientIpPolicy` on `withCheckpoint`,
60
+ `withCheckpointApi` and `createEdgeCheckpoint`. Next.js 15 removed
61
+ `request.ip`, so the default `direct` policy resolves no IP. The engine
62
+ used to fall back to `x-real-ip` or `x-forwarded-for` when a signature
63
+ failed; it no longer does (see `@kya-os/checkpoint-wasm-runtime`), so on
64
+ the default policy a request with a failed signature loses the
65
+ `vendor_ip_feed` match, the Tier-4 cloud check and reputation. On Vercel
66
+ set `{ platform: 'vercel' }`; self-hosted, use the `trusted-proxy` profile
67
+ with `trustedHops`.
68
+ - The `vercel` client-IP profile is honored only when `VERCEL=1`. Anywhere else
69
+ it resolves like `direct`, so a self-hosted app that copies a Vercel
70
+ snippet can no longer have its IP chosen by a client-sent
71
+ `x-vercel-forwarded-for` or `x-forwarded-for`.
72
+ - `trustedHops` counts the trusted proxy addresses at the right of
73
+ `x-forwarded-for`, which is one fewer than the number of proxies, and now
74
+ accepts `0` (the rightmost entry) for a single proxy; `0` needs the
75
+ `@kya-os/checkpoint-shared` release that carries this change, and resolves
76
+ no IP with an older one.
77
+ - An untrusted resolution (an `x-real-ip` or `x-forwarded-for` fallback the
78
+ selected profile does not vouch for) is no longer forwarded as the client
79
+ IP to the engine, the reporter or the API middleware.
80
+
81
+ ### Notes (#5438)
82
+
83
+ - `withCheckpointApi` answers a `rate_limited` enforce decision (the project
84
+ policy's `requestsPerMinute` throttle) with a `429`, a `Retry-After` header
85
+ and a `RATE_LIMITED` body instead of the `403` access-denied shape. It is not
86
+ turned into a redirect by `onBlock: 'redirect'`; `customBlockedResponse` and
87
+ `blockedResponse.headers` still apply. The limit is counted per client IP
88
+ the middleware relays, so set `clientIpPolicy` to the platform that fronts
89
+ your app: with the default `direct` policy on Next.js 15 no IP is relayed
90
+ and the limit is skipped.
91
+
92
+ ### Notes (#5594)
93
+
94
+ #### Added
95
+
96
+ - `getCheckpointPostureOutcome(request, { browserPosture, projectId })` returns the
97
+ browser-posture outcome for a request in a route handler or page:
98
+ `{ status, reason?, posture? }` with `status` `verified`, `absent` or `rejected`, and the
99
+ verified claims (a frozen copy) only when verified. It verifies the token from the
100
+ `KYA-Posture` headers or cookies with the same verifier and posture config
101
+ `withCheckpoint` takes, so nothing is forwarded from the middleware and no secret is
102
+ needed. It always checks, whether or not the middleware ran for the route.
103
+ `status: 'verified'` means the token signature and claims are valid, so check
104
+ `posture.verdict` before treating the visitor as human. The accessor runs the
105
+ same config validation as `withCheckpoint` (`projectId` must be the lowercase project
106
+ UUID) and throws on an invalid config. Needs a
107
+ `@kya-os/checkpoint-wasm-runtime` release that carries `postureOutcomeView`.
108
+
109
+ ### Notes (#5707)
110
+
111
+ - Policy-load timeouts and fast origin failures now follow the documented
112
+ `failOpen` and `fallbackPolicy` settings. The default remains fail-open;
113
+ `failOpen: false` with no fallback returns `503 POLICY_UNAVAILABLE`.
114
+
115
+ ### Notes (#5579)
116
+
117
+ #### Fixed
118
+
119
+ - `CheckpointApiClient.enforce` and `quickCheck` no longer send cookies,
120
+ `Authorization` or other credential-looking headers (any name containing
121
+ `authorization`, `auth`, `token`, `secret`, `password`, `api-key`,
122
+ `subscription-key` or `credential`, except `kya-` headers) to Checkpoint, so
123
+ `withCheckpointApi` and direct callers are covered alike. The only exceptions
124
+ are every `_as_beacon_session` cookie and a KYA delegation credential bearer,
125
+ which the engine verifies.
126
+
127
+ ### zero-evidence requests are `IncompleteData`, not `Human` (breaking wire change) (#5060)
128
+
129
+ - **Behavior change:** the embedded engine no longer classifies a request that carries no evidence as `Human`. For
130
+ that request `detectionDetail.detectionClass.type` is now `IncompleteData` and `detectionDetail.riskLevel` is
131
+ `medium` instead of `low`. `isAgent` stays false.
132
+ - The engine marks that verdict with `detectionDetail.metadata.detection_basis = "no_evidence"`. It is the only thing
133
+ that separates a zero-evidence request from other `IncompleteData` verdicts, and the composed-policy projection reads
134
+ it to give the visitor the category `no_evidence`.
135
+ - A request with suspicious headers is still `IncompleteData` (the engine's internal Unknown class), but its
136
+ `detectionDetail.verificationMethod` is now `none` instead of `pattern`.
137
+ - Composed rules aimed at all agents now exempt only `human` and `no_evidence` visitors, so any other `incomplete_data`
138
+ visitor is matched by them. A forged `mcp_i_handshake` or `kyaos_handshake` envelope that the engine blocks projects
139
+ as category `unknown`, not `incomplete_data`.
140
+ - For a zero-evidence request `detectionDetail.isBot` and `detectionDetail.isAiCrawler` are now absent; they were `false`.
141
+ Read a missing value as false. Its `reasons` now read `Request did not carry enough signal to classify confidently`
142
+ where they read `No known agent indicators matched`.
143
+ - A deployed rule that does not compare the category to `no_evidence` reads it as `human` because the composed-policy
144
+ compile rewrites the policy text (`withNoEvidenceExclusion` in `@kya-os/checkpoint-shared`). The dashboard serves the
145
+ stored text, so a release that predates the rewrite reads it, `@scopes` included, exactly as before.
146
+ - Composed-policy evaluation now applies that same rewrite to the policy text inside the compile, once per distinct policy
147
+ text on a cache miss and not on every request, so a custom `PolicyFetcher` is covered and text that already carries
148
+ the rewrite is unchanged. Apart from computed reads, a statement is skipped only when it compares the category to the literal `"no_evidence"`.
149
+ The rewrite takes a direct read of the category, including a parenthesized principal and a bracket key written with
150
+ escapes; whitespace between tokens is the 25 Unicode `White_Space` characters and a `//` comment ends at a line feed
151
+ 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
152
+ that carries `principal`, is left as written and sees `no_evidence`, and a `principal` that is an attribute name or
153
+ record key is never rewritten. If the engine rejects the rewritten text as invalid Cedar, the authored text is
154
+ compiled instead, a `no_evidence` visitor is still read as `human` for that policy, and the new optional
155
+ `ComposedPolicyLogger.compileFallback(projectId, error)` is called once per policy text, or `console.warn` when the
156
+ logger does not supply it. A policy nested deeper than 32 levels is refused as invalid Cedar before the engine
157
+ compiles it. Needs a `@kya-os/checkpoint-wasm-runtime` release that carries the rewrite.
158
+ - `engineInfo.version` and `engineInfo.rulesetVersion` are now `0.2.1` (they were `0.2.0`). `engineInfo.rulesetHash` is
159
+ unchanged: it hashes the bundled vendor keys, vendor feeds and user-agent pattern table, and none of them changed.
160
+ - `withCheckpoint` reports through `@kya-os/checkpoint-wasm-runtime`, whose reporter now sends `detection.detectionBasis`
161
+ to `POST /api/v1/log-detection`. Needs a `@kya-os/checkpoint-wasm-runtime` release that carries it. The
162
+ `CheckpointApiClient.logDetection` call used by `withCheckpointApi` sends the top-level `detectionBasis` that the
163
+ gateway's `/__detect/enforce` returns on the detection. It used to read `metadata.detection_basis`, which that route
164
+ does not set, so nothing was forwarded. `ApiDetectionDetail` gained the optional `detectionBasis` field. The
165
+ dashboard accepts only `no_evidence` and `posture_evidence` and stores it only on an `incomplete_data` row.
166
+ - `withCheckpoint` results (Node and Edge) never carry `Human` now. It still comes from the older
167
+ `createEdgeCheckpoint` detector in `@kya-os/checkpoint-nextjs/edge-runtime-loader`, which reports `Human` when its
168
+ WASM call or its pattern fallback finds no agent.
169
+
170
+ ### Notes (#5968)
171
+
172
+ - `resolveDelegationChallenge` is now also called for a `Block` the engine marks `consent_remediable` (a scope
173
+ shortfall against the host's required scopes, or a delegation whose own `exp` passed or whose status list says
174
+ revoked). Return context with the route's required scopes, from your route configuration and never from
175
+ `result.decision.reason.requested`, and the request gets the same Delegation challenge a first-contact `Challenge`
176
+ gets, so the agent can send the human back to consent. Return `undefined` and the request keeps its block. Every
177
+ other block still renders as before and never calls the resolver. Needs the `@kya-os/checkpoint-wasm-runtime`
178
+ release that carries the re-challenge.
179
+
180
+ ### Notes (#5652)
181
+
182
+ #### Fail-closed credential handling
183
+
184
+ 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.
185
+
186
+ #### Changed
187
+
188
+ ### Node 20.16+ or 22.3+ required; did:web and status-list fetches are hardened (breaking) (#6094)
189
+
190
+ - **BREAKING:** `engines.node` is now `^20.16.0 || >=22.3.0` (was `>=18.0.0`), so installing on older Node warns.
191
+ Node 18 and Node 20 before 20.16 are end of life and have no `process.getBuiltinModule`, which the default DID
192
+ resolver needs for its connect-time address check. There every did:web and status-list fetch is refused: a request
193
+ with a did:web identity is blocked and one whose credential has a status list gets a 503. One warning per process
194
+ names the Node version.
195
+ - **BREAKING for hosts whose only route out is a proxy:** on Node the default `didResolver` and `statusListCache`
196
+ fetch with `https.get` and `agent: false`. That ignores an undici global dispatcher
197
+ (`setGlobalDispatcher(new ProxyAgent(...))`) and Node 24's `NODE_USE_ENV_PROXY`, which global `fetch` honoured
198
+ before, so such a host fails every did:web and status-list fetch (503). Workaround: pass your proxied fetch,
199
+ `adapters: { didResolver: makeDidResolver({ fetch: proxiedFetch }), statusListCache: makeStatusListCache({ fetch: proxiedFetch }) }`
200
+ (both from `@kya-os/checkpoint-wasm-runtime/adapters`). Redirects, ports and size stay checked, but the
201
+ connect-time address check is then your job.
202
+ - The default DID resolver and status-list cache now refuse redirects, ports other than 443, bodies over 64 KiB and,
203
+ on Node, hosts that resolve to a private, loopback, link-local, CGNAT or metadata address. See the
204
+ `@kya-os/checkpoint-wasm-runtime` changelog (#3331).
205
+
206
+ ### the `agentshield_wasm` setup CLI and binary are removed (breaking) (#6084)
207
+
208
+ Shipped under a minor because nothing consumes this package yet.
209
+
210
+ #### BREAKING, removal
211
+
212
+ - **The `checkpoint-setup-edge` bin, the bundled `wasm/` files, `wasm.d.ts` and `EDGE_RUNTIME_WASM_SETUP.md`.**
213
+ The CLI copied the retired `agentshield_wasm` binary into an app for `createEdgeWasmMiddleware`, which already throws.
214
+ **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.
215
+ - **The `@kya-os/checkpoint` dependency.**
216
+ `CheckpointEvents`, the type of the `events` option, now comes from `@kya-os/checkpoint-shared`.
217
+ Import it from there if your code names it.
218
+
219
+ RELEASE ORDER: publish `@kya-os/checkpoint-shared` (which adds `CheckpointEvents`) and `@kya-os/checkpoint-wasm-runtime` first.
220
+
221
+ ### Notes (#6187)
222
+
223
+ - **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).
224
+
225
+ ### Notes (#5748)
226
+
227
+ Client-IP handling tightens after the engine stopped deriving an IP from
228
+ forwarded headers. Next.js 15 users on Vercel must now set `clientIpPolicy`.
229
+
230
+ #### Added
231
+
232
+ - OpenAI Tier-1 signing keys now rotate without an SDK release. Verification
233
+ fetches a signed key feed from `feeds.kya.vouched.id` through
234
+ `@kya-os/checkpoint-wasm-runtime`, and a request that misses on an unknown or
235
+ expired OpenAI key is answered at once while the feed refreshes in the background, so the next
236
+ request uses the new keys. This adds
237
+ outbound HTTPS from your server to that host, so allow-list it if you filter
238
+ egress. Point it elsewhere with `KYA_VENDOR_KEY_FEED_URL`. Needs a
239
+ `@kya-os/checkpoint-wasm-runtime` release that carries the feed hook; this
240
+ package needs no code change.
241
+
242
+ ### Notes (#5783)
243
+
244
+ #### Changed
245
+
246
+ - 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.
247
+
3
248
  ## 1.10.0
4
249
 
5
250
  Picks up the Zod 4 flip through its dependency ranges, plus two behaviour
package/README.md CHANGED
@@ -4,45 +4,166 @@ 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
+ tenantHost: 'demo.example',
32
+ engineWasmModule,
33
+ });
34
+ ```
35
+
36
+ ```ts
37
+ // middleware.ts: SaaS gateway
33
38
  import { withCheckpointApi } from '@kya-os/checkpoint-nextjs';
39
+
34
40
  export default withCheckpointApi({
41
+ // Honor platform headers only inside Vercel's managed runtime.
42
+ clientIpPolicy: { platform: 'vercel' },
35
43
  apiKey: process.env.CHECKPOINT_API_KEY!,
36
44
  onBlock: 'redirect',
37
45
  redirectUrl: '/blocked',
38
46
  });
39
47
  ```
40
48
 
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.
49
+ ## Runtimes and bundlers
50
+
51
+ `withCheckpoint` loads the engine's WebAssembly inside your middleware, so what works depends on the runtime and the bundler.
52
+ On Next.js, run it as Edge middleware: that works with Turbopack and webpack.
53
+
54
+ | Middleware file | Import | Turbopack (Next.js 16 default) | webpack (Next.js 15 default) |
55
+ | ------------------------------------------------------- | --------------------------------------------------- | ------------------------------ | -------------------------------------------------- |
56
+ | `middleware.ts` on the Edge runtime (recommended) | `@kya-os/checkpoint-nextjs` with `engineWasmModule` | Supported | Supported with [`unstable_allowDynamic`](#webpack) |
57
+ | `proxy.ts`, or `middleware.ts` with `runtime: 'nodejs'` | `@kya-os/checkpoint-nextjs` | Supported | Not supported yet |
58
+
59
+ `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.
60
+
61
+ ### Edge runtime
62
+
63
+ The Edge runtime does not let code compile WebAssembly from bytes, so the engine has to arrive as a compiled `WebAssembly.Module`.
64
+ Import it from `@kya-os/checkpoint-nextjs/engine-wasm` and pass it as `engineWasmModule`:
65
+
66
+ ```ts
67
+ // middleware.ts (Edge runtime)
68
+ import engineWasmModule from '@kya-os/checkpoint-nextjs/engine-wasm';
69
+ import { withCheckpoint } from '@kya-os/checkpoint-nextjs';
70
+
71
+ export default withCheckpoint({
72
+ clientIpPolicy: { platform: 'vercel' },
73
+ tenantHost: 'demo.example',
74
+ engineWasmModule,
75
+ });
76
+
77
+ export const config = {
78
+ matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
79
+ };
80
+ ```
81
+
82
+ `/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.
83
+ 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.
84
+
85
+ #### Cedar policies on the Edge runtime
86
+
87
+ To evaluate the project's Cedar policy on the Edge runtime, pass the Cedar build as `engineWasmModule`, in place of the engine-only build.
88
+ The Cedar build is the engine plus the Cedar policy evaluator, so one module runs detection and the policy:
89
+
90
+ ```ts
91
+ import engineWasmModule from '@kya-os/checkpoint-nextjs/cedar-wasm';
92
+ import { withCheckpoint } from '@kya-os/checkpoint-nextjs';
93
+
94
+ export default withCheckpoint({
95
+ tenantHost: 'demo.example',
96
+ projectId: process.env.CHECKPOINT_PROJECT_ID,
97
+ engineWasmModule,
98
+ });
99
+ ```
100
+
101
+ It is opt-in because it is larger than the engine-only build.
102
+ 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).
103
+
104
+ Without a Cedar module the project's policy is still fetched and never skipped.
105
+ A project with no Cedar policy is unaffected, and a policy in shadow mode keeps the structured decision.
106
+ A project whose Cedar policy is enforcing has every request answered 503, and the missing module is logged once.
107
+
108
+ The Edge middleware bundle, gzipped, measured in a Next.js 16 app (Turbopack) whose middleware is `withCheckpoint` alone:
109
+
110
+ | Modules | Edge bundle | Vercel Edge limit |
111
+ | ------------------------------------------------------ | ------------- | -------------------------- |
112
+ | `/engine-wasm` as `engineWasmModule` | about 0.94 MB | fits Hobby (1 MB) |
113
+ | `/cedar-wasm` as `engineWasmModule` | about 1.38 MB | fits Pro (2 MB), not Hobby |
114
+ | `/engine-wasm` plus `/cedar-wasm` as `cedarWasmModule` | about 2.13 MB | exceeds Pro |
115
+
116
+ Your own middleware code adds to these.
117
+ If the bundle does not fit your plan, use `withCheckpointApi`, which carries no WebAssembly.
118
+
119
+ ### webpack
120
+
121
+ On the Edge runtime, webpack rejects any module that contains code able to evaluate code at runtime, even when that code never runs.
122
+ Two dependencies trip the check, so allow them in the middleware config:
123
+
124
+ ```ts
125
+ export const config = {
126
+ matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
127
+ unstable_allowDynamic: [
128
+ // The Zod schema library bundled into checkpoint-shared probes for `new Function`
129
+ // support inside a try/catch (its allowsEval check).
130
+ '**/@kya-os/checkpoint-shared/dist/**',
131
+ // The engine's wasm-bindgen glue can compile WebAssembly from bytes; passing
132
+ // engineWasmModule means that path never runs.
133
+ '**/@kya-os/checkpoint-wasm-runtime/wasm/**',
134
+ ],
135
+ };
136
+ ```
137
+
138
+ `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.
139
+ Import it from `@kya-os/checkpoint-nextjs/api-middleware` and only the `checkpoint-shared` entry is needed.
140
+
141
+ ### Node.js runtime
142
+
143
+ 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)`.
144
+ 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.
145
+ `@kya-os/checkpoint-nextjs/node` is the same build.
146
+
147
+ 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.
148
+ 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.
149
+
150
+ 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.
151
+
152
+ ### Background work
153
+
154
+ 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.
155
+ `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.
156
+ If you wrap `withCheckpoint` in your own middleware, pass the event through:
157
+
158
+ ```ts
159
+ const checkpoint = withCheckpoint({ tenantHost: 'demo.example' });
160
+
161
+ export default function middleware(request: NextRequest, event: NextFetchEvent) {
162
+ return checkpoint(request, event);
163
+ }
164
+ ```
165
+
166
+ Without an event, it falls back to `waitUntil` from `@vercel/functions`, which only has an effect on Vercel.
46
167
 
47
168
  ## Installation
48
169
 
@@ -54,17 +175,23 @@ npm install @kya-os/checkpoint-nextjs
54
175
 
55
176
  ## Client-IP trust policy
56
177
 
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:
178
+ 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.
179
+
180
+ | Deployment | Configuration and result |
181
+ | --------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
182
+ | Vercel managed runtime | `{ platform: 'vercel' }` accepts Vercel's overwritten singleton address header when `VERCEL=1` |
183
+ | Legacy Next runtime with a platform-provided `request.ip` | `{ platform: 'direct' }` uses that framework address |
184
+ | Self-hosted Next behind a proxy or Cloudflare | No authenticated address is available through NextRequest; `trusted-proxy` and `cloudflare` return no address |
185
+
186
+ 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.
187
+
188
+ 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`.
59
189
 
60
- withCheckpoint({
61
- tenantHost: 'your.tenant.example',
62
- clientIpPolicy: { platform: 'vercel' },
63
- });
190
+ #### Migrate self-hosted proxy configurations
64
191
 
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.
192
+ 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.
193
+
194
+ 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
195
 
69
196
  ### Middleware Setup
70
197
 
@@ -74,6 +201,8 @@ Create `middleware.js` (or `middleware.ts`) in your project root:
74
201
  import { withCheckpointApi } from '@kya-os/checkpoint-nextjs';
75
202
 
76
203
  export default withCheckpointApi({
204
+ // Honor platform headers only inside Vercel's managed runtime.
205
+ clientIpPolicy: { platform: 'vercel' },
77
206
  apiKey: process.env.CHECKPOINT_API_KEY,
78
207
  });
79
208
 
@@ -129,8 +258,9 @@ export default withCheckpointApi({
129
258
  // Request timeout in ms. Default: 5000
130
259
  timeout: 5000,
131
260
 
132
- // Fail open (allow) on API errors. Default: true
133
- failOpen: true,
261
+ // Fail open (allow) on API errors. Default: false (503 + Retry-After).
262
+ // Requests that present a credential are answered 503 even when true.
263
+ failOpen: false,
134
264
 
135
265
  // Observability callback when an agent is detected
136
266
  onAgentDetected: async (request, decision) => {
@@ -149,6 +279,21 @@ your deployed dashboard policy in-process), and more. See the
149
279
  [middleware docs](https://kya.vouched.id/docs/enforce/middleware) for the
150
280
  full option tables for both shapes.
151
281
 
282
+ ## Failure behavior
283
+
284
+ `withCheckpoint` answers `503` (`Retry-After: 3`, `Cache-Control: no-store`)
285
+ when the verification pipeline errors; it never passes the request through or
286
+ returns a 500. If the policy API is unreachable, the last successfully fetched
287
+ policy (at most 24h old) is served; with none, the request is answered `503`
288
+ and the default policy is never substituted. The last-good copy lives in
289
+ process memory and, when a `PolicyCacheAdapter` is configured, in that adapter
290
+ (so a cold process or isolate can still serve it). A policy-origin 401/403/404
291
+ or a body that is not a policy-API response is treated like an outage:
292
+ last-good is served for up to 24h.
293
+
294
+ `withCheckpoint` itself never throws, because a Next.js middleware module that fails to load can let requests through unchecked.
295
+ 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`.
296
+
152
297
  ## Actions
153
298
 
154
299
  ### Block Agents
@@ -318,3 +463,32 @@ MIT OR Apache-2.0
318
463
 
319
464
  For opt-in classification, signed posture and scoped consent step-up, see the
320
465
  [browser integrity rollout runbook](../../docs/runbooks/browser-integrity.md).
466
+
467
+ ### Reading the browser posture outcome
468
+
469
+ With `browserPosture` configured, read the posture outcome for a request in a route
470
+ handler or page. The accessor verifies the posture token from the request's `KYA-Posture`
471
+ headers or cookies with the same verifier and the same posture config the middleware
472
+ uses, so nothing is forwarded and there is no extra secret:
473
+
474
+ ```ts
475
+ import { getCheckpointPostureOutcome } from '@kya-os/checkpoint-nextjs';
476
+ import { browserPosture, projectId } from '@/checkpoint-config';
477
+
478
+ export async function POST(request: Request) {
479
+ const outcome = await getCheckpointPostureOutcome(request, { browserPosture, projectId });
480
+ return Response.json({ posture: outcome.status, verdict: outcome.posture?.verdict });
481
+ }
482
+ ```
483
+
484
+ The result is `{ status: 'verified' | 'absent' | 'rejected', reason?, posture? }`, with
485
+ `posture` (the verified claims, as a frozen copy) only when verified. The accessor always
486
+ checks: it returns `verified`, `absent` or `rejected` for the request it is given, and does
487
+ not depend on the middleware having run or on the route matching it. `status: 'verified'`
488
+ means the token signature and claims are valid, so check `posture.verdict` before treating
489
+ the visitor as human. Given a bare `Headers` (for example `await headers()` in a server
490
+ component), pass those instead of a request. Verification is a single ES256 check, so
491
+ calling it in a handler as well as in the middleware costs little. A verified token that carries
492
+ the beacon's agent or bot verdict (`posture.detection`), or discloses automation, also
493
+ reclassifies a request the engine called human or incomplete data.
494
+ 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 { BLOCKED_PATH, VERDICT_COOKIE_NAME, acceptsHtml, classifyResponseShape, encodeVerdictCookie } from "@kya-os/checkpoint-shared/host-adapter";
2
+ import { NextResponse } from "next/server.js";
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-BdQ9R7Iw.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapt-BdQ9R7Iw.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"}