@kya-os/checkpoint-nextjs 1.0.0 → 1.1.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 (91) hide show
  1. package/CHANGELOG.md +165 -0
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/adapt.js +0 -2
  4. package/dist/adapt.mjs +0 -2
  5. package/dist/api-client.js +38 -24
  6. package/dist/api-client.mjs +38 -24
  7. package/dist/api-middleware.js +48 -28
  8. package/dist/api-middleware.mjs +48 -28
  9. package/dist/create-middleware.d.mts +1 -1
  10. package/dist/create-middleware.d.ts +1 -1
  11. package/dist/create-middleware.js +0 -2
  12. package/dist/create-middleware.mjs +0 -2
  13. package/dist/edge/index.d.mts +1 -1
  14. package/dist/edge/index.d.ts +1 -1
  15. package/dist/edge/index.js +4 -6
  16. package/dist/edge/index.mjs +4 -6
  17. package/dist/edge-runtime-loader.js +7 -2
  18. package/dist/edge-runtime-loader.mjs +7 -2
  19. package/dist/edge-wasm-middleware.js +0 -2
  20. package/dist/edge-wasm-middleware.mjs +0 -2
  21. package/dist/index.d.mts +1 -1
  22. package/dist/index.d.ts +1 -1
  23. package/dist/index.js +77 -42
  24. package/dist/index.mjs +77 -42
  25. package/dist/middleware-edge.js +17 -10
  26. package/dist/middleware-edge.mjs +17 -10
  27. package/dist/middleware-node.d.mts +36 -0
  28. package/dist/middleware-node.d.ts +36 -0
  29. package/dist/middleware-node.js +17 -10
  30. package/dist/middleware-node.mjs +17 -10
  31. package/dist/middleware.d.mts +1 -1
  32. package/dist/middleware.d.ts +1 -1
  33. package/dist/middleware.js +0 -2
  34. package/dist/middleware.mjs +0 -2
  35. package/dist/nodejs-wasm-loader.js +0 -2
  36. package/dist/nodejs-wasm-loader.mjs +0 -2
  37. package/dist/policy.js +10 -6
  38. package/dist/policy.mjs +10 -6
  39. package/dist/session-tracker.js +1 -3
  40. package/dist/session-tracker.mjs +1 -3
  41. package/dist/signature-verifier.js +0 -2
  42. package/dist/signature-verifier.mjs +0 -2
  43. package/dist/translate.d.mts +36 -9
  44. package/dist/translate.d.ts +36 -9
  45. package/dist/translate.js +13 -8
  46. package/dist/translate.mjs +13 -8
  47. package/dist/{types-C-xCUNTr.d.mts → types-D9RQvPNy.d.mts} +1 -1
  48. package/dist/{types-C-xCUNTr.d.ts → types-D9RQvPNy.d.ts} +1 -1
  49. package/dist/wasm-middleware.d.mts +29 -10
  50. package/dist/wasm-middleware.d.ts +29 -10
  51. package/dist/wasm-middleware.js +0 -2
  52. package/dist/wasm-middleware.mjs +0 -2
  53. package/dist/wasm-setup.js +0 -2
  54. package/dist/wasm-setup.mjs +0 -2
  55. package/package.json +3 -3
  56. package/dist/adapt.js.map +0 -1
  57. package/dist/adapt.mjs.map +0 -1
  58. package/dist/api-client.js.map +0 -1
  59. package/dist/api-client.mjs.map +0 -1
  60. package/dist/api-middleware.js.map +0 -1
  61. package/dist/api-middleware.mjs.map +0 -1
  62. package/dist/create-middleware.js.map +0 -1
  63. package/dist/create-middleware.mjs.map +0 -1
  64. package/dist/edge/index.js.map +0 -1
  65. package/dist/edge/index.mjs.map +0 -1
  66. package/dist/edge-runtime-loader.js.map +0 -1
  67. package/dist/edge-runtime-loader.mjs.map +0 -1
  68. package/dist/edge-wasm-middleware.js.map +0 -1
  69. package/dist/edge-wasm-middleware.mjs.map +0 -1
  70. package/dist/index.js.map +0 -1
  71. package/dist/index.mjs.map +0 -1
  72. package/dist/middleware-edge.js.map +0 -1
  73. package/dist/middleware-edge.mjs.map +0 -1
  74. package/dist/middleware-node.js.map +0 -1
  75. package/dist/middleware-node.mjs.map +0 -1
  76. package/dist/middleware.js.map +0 -1
  77. package/dist/middleware.mjs.map +0 -1
  78. package/dist/nodejs-wasm-loader.js.map +0 -1
  79. package/dist/nodejs-wasm-loader.mjs.map +0 -1
  80. package/dist/policy.js.map +0 -1
  81. package/dist/policy.mjs.map +0 -1
  82. package/dist/session-tracker.js.map +0 -1
  83. package/dist/session-tracker.mjs.map +0 -1
  84. package/dist/signature-verifier.js.map +0 -1
  85. package/dist/signature-verifier.mjs.map +0 -1
  86. package/dist/translate.js.map +0 -1
  87. package/dist/translate.mjs.map +0 -1
  88. package/dist/wasm-middleware.js.map +0 -1
  89. package/dist/wasm-middleware.mjs.map +0 -1
  90. package/dist/wasm-setup.js.map +0 -1
  91. package/dist/wasm-setup.mjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,170 @@
1
1
  # @kya-os/checkpoint-nextjs
2
2
 
3
+ ## 1.1.0 — 2026-05-17
4
+
5
+ Closes [SDK-Envelope-Plumbing-1 (#2594)](https://github.com/Know-That-Ai/agent-shield/issues/2594).
6
+ Wires MCP-I envelope verification through Next.js middleware — Bench-Before-After-1's
7
+ `verified_mcp_i` traffic case was provably blocked by SDK glue (not engine
8
+ capability — the engine verifies at 47µs Criterion local p50). All three transports
9
+ the orchestrator supports now work from a Next.js consumer.
10
+
11
+ ### New config (additive — no breaking changes)
12
+
13
+ - `CheckpointConfig.legacyEnvelopeFallback?: boolean` (default `false`) — accept
14
+ envelopes via the legacy `KYA-Delegation` HTTP header alongside the canonical
15
+ body form. Use for agents that pre-date Envelope-1 (#2537).
16
+ - `CheckpointConfig.drainJsonBody?: boolean` (default `true`) — read the request
17
+ body when `content-type` is `application/json` so the orchestrator can extract
18
+ `_meta.proof.jws`. The translator uses `req.clone()` to preserve the original
19
+ stream for downstream handlers. Set `false` for streaming-sensitive routes
20
+ that can't tolerate the clone overhead; in that case route envelopes through
21
+ the `KYA-Delegation` header transport instead.
22
+
23
+ ### New supported transports
24
+
25
+ | Transport | Form | Config required |
26
+ | ------------------------------------- | ------------------------------------------------- | ----------------------------------------- |
27
+ | Canonical body (spec form) | `_meta.proof.jws` field in a JSON request body | none — `drainJsonBody` defaults to `true` |
28
+ | Legacy header (Envelope-1 transition) | `KYA-Delegation` HTTP header carrying compact JWS | `legacyEnvelopeFallback: true` |
29
+
30
+ Both transports work end-to-end against the Rust `kya-os-engine` via WASM,
31
+ including DID resolution (did:web + did:key), Ed25519 signature verification,
32
+ JCS canonicalization, policy + reputation checks. See the engine's Criterion
33
+ suite at `rust/crates/kya-os-engine/benches/bouncer_verify.rs` for the per-stage
34
+ cost breakdown.
35
+
36
+ ### Factory clarity
37
+
38
+ `createCheckpointWasmMiddleware` JSDoc updated to clearly document it as
39
+ **pattern-detection only** (no envelope verification). Customers needing
40
+ verification are pointed to `withCheckpoint` (the orchestrator-capable factory)
41
+ in the JSDoc + example block.
42
+
43
+ ### Bench-Before-After-1 follow-up
44
+
45
+ This release unblocks the verified_mcp_i measurement deferred in
46
+ `docs/benchmarks/bench-before-after-1.md` §3.7. After upgrading
47
+ `sites/nextjs-checkpoint/` to 1.1.0 and redeploying bench-new, sub-phase 3 will
48
+ be re-run with the actual verify-success path exercised. The §3.8 "Verify-success
49
+ measurement" section will then be appended to the report.
50
+
51
+ ### Migration
52
+
53
+ No code changes required for existing 1.0.x consumers — both new fields are
54
+ optional with safe defaults. Consumers wanting envelope verification should:
55
+
56
+ ```diff
57
+ export default withCheckpoint({
58
+ tenantHost: 'acme.checkpoint.example',
59
+ + // Accept legacy KYA-Delegation-header envelopes (Envelope-1 transition)
60
+ + legacyEnvelopeFallback: true,
61
+ // drainJsonBody defaults to true; canonical _meta.proof.jws body works out of the box
62
+ });
63
+ ```
64
+
65
+ The body-drain default of `true` is a meaningful behavior change for streaming
66
+ middlewares — those should explicitly set `drainJsonBody: false`. Reason for
67
+ defaulting on: the alternative (silent fall-through to PlainHttp for every JSON
68
+ request) is the bug `#2594` was filed to fix; a config default that preserves
69
+ the bug isn't a fix.
70
+
71
+ ---
72
+
73
+ ## 1.0.1 — 2026-05-17
74
+
75
+ Security + rename-completeness patch on top of 1.0.0. **All 1.0.0 users
76
+ should upgrade.**
77
+
78
+ ### Security fixes (from #2587)
79
+
80
+ - **`withCheckpointApi` fail-open bypass via observability callback.**
81
+ Severity: HIGH. The `onAgentDetected` callback was awaited inside the
82
+ outer middleware fail-open `try/catch`. A throwing callback (telemetry
83
+ flap, logging backend down, downstream timeout) would bubble up to the
84
+ fail-open path and return `NextResponse.next()` (200) **even when the
85
+ API had already returned `decision.action === 'block'`**. An attacker
86
+ who could induce failures in a customer's observability layer could
87
+ bypass enforcement. Fix: local `try/catch` around the callback so
88
+ enforcement continues regardless. Regression test added.
89
+ - **`getCheckpointApiClient` shared singleton across distinct configs.**
90
+ Severity: HIGH for multi-tenant deploys (single Next.js app hosting
91
+ middleware for several customer routes). The first call's
92
+ `apiKey`/`baseUrl` were cached and reused for all subsequent calls
93
+ even when callers passed different configs — leaking audit/billing
94
+ into the wrong account and evaluating requests against the wrong
95
+ policy. Fix: config-keyed cache, distinct configs → distinct clients.
96
+ Regression test added.
97
+
98
+ **Cross-version advisory:** Bug 1 (`await config.onAgentDetected(...)`
99
+ inside the fail-open `try/catch`) **also exists in `withAgentShield` in
100
+ `@kya-os/agentshield-nextjs@0.3.x`** (verified at
101
+ `packages/agentshield-nextjs/src/api-middleware.ts:403-405` pre-rename).
102
+ Anyone still on the legacy SDK is exposed to the same fail-open bypass.
103
+ Recommended migration: upgrade to `@kya-os/checkpoint-nextjs@1.0.1`.
104
+
105
+ ### Rename-completeness (no behavior change)
106
+
107
+ The 1.0.0 rename from `agentshield` → `checkpoint` left stragglers in
108
+ log strings and runtime env-var lookups. Cleaning these up so the
109
+ package no longer reads any `AGENTSHIELD_*` env var at runtime:
110
+
111
+ - Log prefix `[AgentShield]` → `[Checkpoint]` across api-client,
112
+ api-middleware, policy, edge, storage, and the WASM setup guide.
113
+ - Runtime env vars renamed:
114
+ - `AGENTSHIELD_API_URL` → `CHECKPOINT_API_URL`
115
+ - `AGENTSHIELD_USE_EDGE` → `CHECKPOINT_USE_EDGE`
116
+ - `AGENTSHIELD_DEBUG` → `CHECKPOINT_DEBUG`
117
+ - `AGENTSHIELD_SECRET` → `CHECKPOINT_SECRET`
118
+ - Error message: `"AgentShield API key is required..."` →
119
+ `"Checkpoint API key is required..."` (the `CHECKPOINT_API_KEY` env
120
+ var name in that message is unchanged — it was already correct in
121
+ 1.0.0).
122
+ - Docs (`QUICKSTART.md`, `SESSION_TRACKING_GUIDE.md`) aligned with
123
+ source: `AGENTSHIELD_API_KEY` and `AGENTSHIELD_SECRET` references
124
+ swapped for the `CHECKPOINT_*` forms the source actually reads.
125
+
126
+ #### Breaking-in-a-patch caveat (intentional)
127
+
128
+ Per-spirit-of-semver this is technically a breaking config change. We're
129
+ shipping it as a 1.0.x patch because:
130
+
131
+ 1. `@kya-os/checkpoint-nextjs@1.0.0` shipped on 2026-05-15 — a two-day
132
+ migration window with effectively no adopters yet at scale.
133
+ 2. The 1.0.0 release notes already documented `CHECKPOINT_API_KEY` as
134
+ the canonical env-var name; the leftover `AGENTSHIELD_*` lookups
135
+ were an oversight, not a documented API.
136
+ 3. Customers actively reading the docs as written were already setting
137
+ `CHECKPOINT_*` env vars; the change makes the package read what the
138
+ docs say.
139
+
140
+ If you have `AGENTSHIELD_API_URL` / `AGENTSHIELD_USE_EDGE` /
141
+ `AGENTSHIELD_DEBUG` / `AGENTSHIELD_SECRET` in your env, rename them to
142
+ the `CHECKPOINT_*` equivalents on upgrade.
143
+
144
+ #### Deliberately NOT renamed (would break live sessions)
145
+
146
+ - Cookie name `__agentshield_session` — renaming would invalidate every
147
+ customer's live agent-detection sessions on deploy.
148
+ - Encryption-key fallback `'agentshield-default-key'` — same reason
149
+ (would silently fail to decrypt sessions encrypted with the old
150
+ default).
151
+
152
+ These are tracked for a future major and not in scope here.
153
+
154
+ ### Migration
155
+
156
+ ```diff
157
+ - AGENTSHIELD_API_URL=https://detect.checkpoint-gateway.ai
158
+ + CHECKPOINT_API_URL=https://detect.checkpoint-gateway.ai
159
+
160
+ - AGENTSHIELD_SECRET=my-encryption-key
161
+ + CHECKPOINT_SECRET=my-encryption-key
162
+ ```
163
+
164
+ No code changes required.
165
+
166
+ ---
167
+
3
168
  ## 1.0.0 — 2026-05-15
4
169
 
5
170
  E-tracks Phase D — package rename + engine refactor + dual-runtime support.