@kya-os/checkpoint-nextjs 1.7.0 → 1.9.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.
- package/CHANGELOG.md +30 -0
- package/EDGE_RUNTIME_WASM_SETUP.md +12 -12
- package/README.md +144 -251
- package/bin/setup-edge-wasm.js +10 -2
- package/dist/adapt.js +9 -6
- package/dist/adapt.mjs +9 -6
- package/dist/api-client.d.mts +9 -0
- package/dist/api-client.d.ts +9 -0
- package/dist/api-middleware.d.mts +12 -2
- package/dist/api-middleware.d.ts +12 -2
- package/dist/api-middleware.js +28 -31
- package/dist/api-middleware.mjs +29 -32
- package/dist/composed-policy.d.mts +7 -0
- package/dist/composed-policy.d.ts +7 -0
- package/dist/composed-policy.js +14 -2
- package/dist/composed-policy.mjs +15 -3
- package/dist/{config-_nfPN3E3.d.mts → config-CleTeeoW.d.mts} +39 -11
- package/dist/{config-kxFihzR_.d.ts → config-XMOIkxFN.d.ts} +39 -11
- package/dist/create-middleware.d.mts +1 -1
- package/dist/create-middleware.d.ts +1 -1
- package/dist/edge/index.d.mts +3 -1
- package/dist/edge/index.d.ts +3 -1
- package/dist/edge/index.js +5 -16
- package/dist/edge/index.mjs +5 -16
- package/dist/edge-runtime-loader.d.mts +3 -1
- package/dist/edge-runtime-loader.d.ts +3 -1
- package/dist/edge-runtime-loader.js +4 -16
- package/dist/edge-runtime-loader.mjs +5 -17
- package/dist/edge-wasm-middleware.d.mts +1 -1
- package/dist/edge-wasm-middleware.d.ts +1 -1
- package/dist/edge-wasm-middleware.js +1 -1
- package/dist/edge-wasm-middleware.mjs +1 -1
- package/dist/index.d.mts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +151 -84
- package/dist/index.mjs +153 -86
- package/dist/middleware-bundler.d.mts +13 -0
- package/dist/middleware-bundler.d.ts +13 -0
- package/dist/middleware-bundler.js +354 -0
- package/dist/middleware-bundler.mjs +352 -0
- package/dist/middleware-edge.d.mts +5 -41
- package/dist/middleware-edge.d.ts +5 -41
- package/dist/middleware-edge.js +161 -97
- package/dist/middleware-edge.mjs +164 -100
- package/dist/middleware-node.d.mts +16 -52
- package/dist/middleware-node.d.ts +16 -52
- package/dist/middleware-node.js +115 -56
- package/dist/middleware-node.mjs +118 -55
- package/dist/middleware.d.mts +1 -1
- package/dist/middleware.d.ts +1 -1
- package/dist/policy.js +6 -1
- package/dist/policy.mjs +6 -1
- package/dist/session-tracker.js +2 -0
- package/dist/session-tracker.mjs +2 -0
- package/dist/translate.d.mts +7 -4
- package/dist/translate.d.ts +7 -4
- package/dist/translate.js +9 -8
- package/dist/translate.mjs +9 -8
- package/dist/{types-D9RQvPNy.d.mts → types-Chgi5TFC.d.mts} +2 -2
- package/dist/{types-D9RQvPNy.d.ts → types-Chgi5TFC.d.ts} +2 -2
- package/package.json +17 -10
- package/dist/signature-verifier.d.mts +0 -33
- package/dist/signature-verifier.d.ts +0 -33
- package/dist/signature-verifier.js +0 -384
- package/dist/signature-verifier.mjs +0 -360
package/dist/middleware-edge.mjs
CHANGED
|
@@ -1,63 +1,15 @@
|
|
|
1
|
-
import { initEngineEdge,
|
|
1
|
+
import { initEngineEdge, renderDecisionAsResponse, verifyRequestEdge } from '@kya-os/checkpoint-wasm-runtime/orchestrator/edge';
|
|
2
2
|
export { initEngineEdge } from '@kya-os/checkpoint-wasm-runtime/orchestrator/edge';
|
|
3
3
|
import { initPolicyEvaluatorEdge, evaluatePolicy } from '@kya-os/checkpoint-wasm-runtime/policy-edge';
|
|
4
4
|
export { initPolicyEvaluatorEdge } from '@kya-os/checkpoint-wasm-runtime/policy-edge';
|
|
5
|
-
import { PolicyFetcher, requestCarriesDelegationProof, acceptsHtml, encodeVerdictCookie, classifyResponseShape, BLOCKED_PATH, VERDICT_COOKIE_NAME } from '@kya-os/checkpoint-shared';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import '@kya-os/checkpoint-wasm-runtime/orchestrator';
|
|
5
|
+
import { selectBodyReadable200, resolveChallengeContext, PolicyFetcher, requestCarriesDelegationProof, resolveClientIp, acceptsHtml, encodeVerdictCookie, classifyResponseShape, BLOCKED_PATH, VERDICT_COOKIE_NAME } from '@kya-os/checkpoint-shared';
|
|
6
|
+
import { applyBrowserPosture, applyBrowserIntegrityStepUp, validateBrowserIntegrityChallenge, makeComposedPolicyCache, isCredentialVerificationBlock, evaluateComposedPolicy, verifyResultToAuthorizeInput } from '@kya-os/checkpoint-wasm-runtime/composed-policy';
|
|
7
|
+
import { validateBrowserPostureConfig } from '@kya-os/checkpoint-shared/browser-posture';
|
|
9
8
|
import { makeSystemClock, makePolicyEvaluator, makeReputationOracle, makeStatusListCache, makeDidResolver } from '@kya-os/checkpoint-wasm-runtime/adapters';
|
|
10
9
|
import { makeDetectionReporter } from '@kya-os/checkpoint-wasm-runtime/reporter';
|
|
10
|
+
import { NextResponse } from 'next/server';
|
|
11
11
|
|
|
12
12
|
// src/middleware-edge.ts
|
|
13
|
-
function adaptToNextResponse(rendered, req) {
|
|
14
|
-
const clientAcceptsHtml = acceptsHtml(req.headers);
|
|
15
|
-
const verdictCookie = encodeVerdictCookie(rendered);
|
|
16
|
-
const shape = classifyResponseShape(rendered, clientAcceptsHtml);
|
|
17
|
-
switch (shape) {
|
|
18
|
-
case "pass-through": {
|
|
19
|
-
const res = NextResponse.next();
|
|
20
|
-
applyHeaders(res, rendered.headers);
|
|
21
|
-
setVerdictCookie(res, verdictCookie);
|
|
22
|
-
return res;
|
|
23
|
-
}
|
|
24
|
-
case "redirect": {
|
|
25
|
-
const target = new URL(rendered.headers.Location);
|
|
26
|
-
const res = NextResponse.redirect(target);
|
|
27
|
-
applyHeaders(res, rendered.headers);
|
|
28
|
-
setVerdictCookie(res, verdictCookie);
|
|
29
|
-
return res;
|
|
30
|
-
}
|
|
31
|
-
case "html-block": {
|
|
32
|
-
const blockedUrl = new URL(BLOCKED_PATH, req.url);
|
|
33
|
-
const res = NextResponse.rewrite(blockedUrl, { status: 200 });
|
|
34
|
-
applyHeaders(res, rendered.headers);
|
|
35
|
-
setVerdictCookie(res, verdictCookie);
|
|
36
|
-
return res;
|
|
37
|
-
}
|
|
38
|
-
case "json-block": {
|
|
39
|
-
const body = rendered.body ?? {};
|
|
40
|
-
const res = NextResponse.json(body, { status: rendered.status });
|
|
41
|
-
applyHeaders(res, rendered.headers);
|
|
42
|
-
setVerdictCookie(res, verdictCookie);
|
|
43
|
-
return res;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
function setVerdictCookie(res, value) {
|
|
48
|
-
res.cookies.set({
|
|
49
|
-
name: VERDICT_COOKIE_NAME,
|
|
50
|
-
value,
|
|
51
|
-
path: "/",
|
|
52
|
-
sameSite: "lax",
|
|
53
|
-
httpOnly: false
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
function applyHeaders(res, headers) {
|
|
57
|
-
for (const [key, value] of Object.entries(headers)) {
|
|
58
|
-
res.headers.set(key, value);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
13
|
var DEFAULT_DASHBOARD_URL = "https://kya.vouched.id";
|
|
62
14
|
var NOOP_LOGGER = {
|
|
63
15
|
shadowDivergence: () => {
|
|
@@ -72,6 +24,7 @@ function makeComposedPolicyContext(opts) {
|
|
|
72
24
|
return {
|
|
73
25
|
async apply(result, path) {
|
|
74
26
|
const structured = { decision: result.decision, acted: false };
|
|
27
|
+
if (isCredentialVerificationBlock(result.decision)) return structured;
|
|
75
28
|
const policy = await fetcher.getPolicy(projectId);
|
|
76
29
|
const outcome = await evaluateComposedPolicy({
|
|
77
30
|
cache,
|
|
@@ -102,7 +55,13 @@ function makeComposedPolicyContext(opts) {
|
|
|
102
55
|
return structured;
|
|
103
56
|
}
|
|
104
57
|
if (outcome.status === "acting") {
|
|
105
|
-
return {
|
|
58
|
+
return {
|
|
59
|
+
decision: outcome.engineDecision,
|
|
60
|
+
acted: true,
|
|
61
|
+
// Echo the SSOT revision pin with the decision it produced (#3246
|
|
62
|
+
// PR5). Conditional spread: absent upstream stays absent here.
|
|
63
|
+
...policy.policySourceHash ? { composedBlobHash: policy.policySourceHash } : {}
|
|
64
|
+
};
|
|
106
65
|
}
|
|
107
66
|
return structured;
|
|
108
67
|
},
|
|
@@ -122,7 +81,12 @@ async function applyComposedPolicy(context, result, path) {
|
|
|
122
81
|
if (!context) return;
|
|
123
82
|
try {
|
|
124
83
|
const outcome = await context.apply(result, path);
|
|
125
|
-
if (outcome.acted)
|
|
84
|
+
if (outcome.acted) {
|
|
85
|
+
result.decision = outcome.decision;
|
|
86
|
+
if (outcome.composedBlobHash) {
|
|
87
|
+
result.composedBlobHash = outcome.composedBlobHash;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
126
90
|
} catch {
|
|
127
91
|
}
|
|
128
92
|
}
|
|
@@ -137,8 +101,57 @@ var consoleComposedPolicyLogger = {
|
|
|
137
101
|
);
|
|
138
102
|
}
|
|
139
103
|
};
|
|
140
|
-
|
|
141
|
-
|
|
104
|
+
function adaptToNextResponse(rendered, req) {
|
|
105
|
+
const clientAcceptsHtml = acceptsHtml(req.headers);
|
|
106
|
+
const verdictCookie = encodeVerdictCookie(rendered);
|
|
107
|
+
const shape = classifyResponseShape(rendered, clientAcceptsHtml);
|
|
108
|
+
switch (shape) {
|
|
109
|
+
case "pass-through": {
|
|
110
|
+
const res = NextResponse.next();
|
|
111
|
+
applyHeaders(res, rendered);
|
|
112
|
+
setVerdictCookie(res, verdictCookie);
|
|
113
|
+
return res;
|
|
114
|
+
}
|
|
115
|
+
case "redirect": {
|
|
116
|
+
const target = new URL(rendered.headers.Location);
|
|
117
|
+
const res = NextResponse.redirect(target);
|
|
118
|
+
applyHeaders(res, rendered);
|
|
119
|
+
setVerdictCookie(res, verdictCookie);
|
|
120
|
+
return res;
|
|
121
|
+
}
|
|
122
|
+
case "html-block": {
|
|
123
|
+
const blockedUrl = new URL(BLOCKED_PATH, req.url);
|
|
124
|
+
const res = NextResponse.rewrite(blockedUrl, { status: 200 });
|
|
125
|
+
applyHeaders(res, rendered);
|
|
126
|
+
setVerdictCookie(res, verdictCookie);
|
|
127
|
+
return res;
|
|
128
|
+
}
|
|
129
|
+
case "json-block": {
|
|
130
|
+
const body = rendered.body ?? {};
|
|
131
|
+
const res = NextResponse.json(body, { status: rendered.status });
|
|
132
|
+
applyHeaders(res, rendered);
|
|
133
|
+
setVerdictCookie(res, verdictCookie);
|
|
134
|
+
return res;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function setVerdictCookie(res, value) {
|
|
139
|
+
res.cookies.set({
|
|
140
|
+
name: VERDICT_COOKIE_NAME,
|
|
141
|
+
value,
|
|
142
|
+
path: "/",
|
|
143
|
+
sameSite: "lax",
|
|
144
|
+
httpOnly: false
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
function applyHeaders(res, rendered) {
|
|
148
|
+
for (const [key, value] of Object.entries(rendered.headers)) {
|
|
149
|
+
res.headers.set(key, value);
|
|
150
|
+
}
|
|
151
|
+
for (const [key, value] of rendered.headerEntries ?? []) {
|
|
152
|
+
res.headers.append(key, value);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
142
155
|
async function nextRequestToHttpLike(req, opts = {}) {
|
|
143
156
|
const url = new URL(req.url);
|
|
144
157
|
const body = await tryDrainJsonBody(req, opts);
|
|
@@ -148,7 +161,7 @@ async function nextRequestToHttpLike(req, opts = {}) {
|
|
|
148
161
|
url: url.pathname + url.search,
|
|
149
162
|
headers: headersToRecord(req.headers),
|
|
150
163
|
body,
|
|
151
|
-
remoteAddress: extractRemoteAddress(req)
|
|
164
|
+
remoteAddress: extractRemoteAddress(req, opts.clientIpPolicy ?? { platform: "direct" })
|
|
152
165
|
};
|
|
153
166
|
}
|
|
154
167
|
async function tryDrainJsonBody(req, opts) {
|
|
@@ -168,19 +181,84 @@ function headersToRecord(headers) {
|
|
|
168
181
|
});
|
|
169
182
|
return out;
|
|
170
183
|
}
|
|
171
|
-
function extractRemoteAddress(req) {
|
|
172
|
-
const xff = req.headers.get("x-forwarded-for");
|
|
173
|
-
if (xff) {
|
|
174
|
-
const first = xff.split(",")[0]?.trim();
|
|
175
|
-
if (first) return first;
|
|
176
|
-
}
|
|
184
|
+
function extractRemoteAddress(req, policy) {
|
|
177
185
|
const maybeIp = req.ip;
|
|
178
|
-
return
|
|
186
|
+
return resolveClientIp({
|
|
187
|
+
headers: req.headers,
|
|
188
|
+
frameworkAddress: maybeIp,
|
|
189
|
+
policy
|
|
190
|
+
}).ip ?? void 0;
|
|
179
191
|
}
|
|
180
192
|
|
|
181
|
-
// src/middleware-
|
|
193
|
+
// src/middleware-core.ts
|
|
194
|
+
function makeNextMiddleware(verifyRequest, renderDecisionAsResponse2, config, host) {
|
|
195
|
+
if (config.browserPosture) validateBrowserPostureConfig(config.browserPosture, config.projectId);
|
|
196
|
+
if (config.browserPosture?.protectedRoutes?.length && !config.resolveDelegationChallenge) {
|
|
197
|
+
throw new Error(
|
|
198
|
+
"browserPosture.protectedRoutes requires resolveDelegationChallenge (see createBrowserIntegrityChallengeResolver)"
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
const opts = buildVerifyOpts(config);
|
|
202
|
+
const reporter = buildReporter(config, host.runtime);
|
|
203
|
+
const composed = host.buildComposedContext(config);
|
|
204
|
+
const trustedRootsResolver = buildTrustedRootsResolver(config, composed);
|
|
205
|
+
const translateOpts = {
|
|
206
|
+
drainJsonBody: config.drainJsonBody,
|
|
207
|
+
clientIpPolicy: config.clientIpPolicy
|
|
208
|
+
};
|
|
209
|
+
return async function checkpointMiddleware(req, event) {
|
|
210
|
+
const httpLike = await nextRequestToHttpLike(req, translateOpts);
|
|
211
|
+
const trustedDelegationRoots = await resolveTrustedDelegationRootsForRequest(
|
|
212
|
+
trustedRootsResolver,
|
|
213
|
+
req.headers
|
|
214
|
+
);
|
|
215
|
+
const result = await verifyRequest(
|
|
216
|
+
httpLike,
|
|
217
|
+
trustedDelegationRoots ? { ...opts, trustedDelegationRoots } : opts
|
|
218
|
+
);
|
|
219
|
+
await applyBrowserPosture(
|
|
220
|
+
result,
|
|
221
|
+
req.headers.get("cookie"),
|
|
222
|
+
config.browserPosture,
|
|
223
|
+
config.projectId
|
|
224
|
+
);
|
|
225
|
+
await applyComposedPolicy(composed, result, req.nextUrl.pathname);
|
|
226
|
+
applyBrowserIntegrityStepUp(result, config.browserPosture, req.nextUrl.pathname);
|
|
227
|
+
if (reporter) {
|
|
228
|
+
const reportPromise = reporter(
|
|
229
|
+
result,
|
|
230
|
+
extractReporterContext(req, config.clientIpPolicy ?? { platform: "direct" })
|
|
231
|
+
);
|
|
232
|
+
if (event) {
|
|
233
|
+
event.waitUntil(reportPromise);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
await dispatchOnResult(config, result, req);
|
|
237
|
+
const bodyReadable200 = selectBodyReadable200(
|
|
238
|
+
config.delegationChallengeMode ?? "negotiated",
|
|
239
|
+
req.headers,
|
|
240
|
+
result.detectionDetail.detectionClass,
|
|
241
|
+
result.detectionDetail.isAgent
|
|
242
|
+
);
|
|
243
|
+
const challengeContextRequested = result.enforcementMode === "enforce" && result.decision.kind === "Challenge" && config.resolveDelegationChallenge !== void 0;
|
|
244
|
+
const delegationChallenge = challengeContextRequested ? await resolveChallengeContext(
|
|
245
|
+
config.resolveDelegationChallenge,
|
|
246
|
+
{ result, request: req },
|
|
247
|
+
{
|
|
248
|
+
timeoutMs: config.delegationChallengeTimeoutMs,
|
|
249
|
+
onFailure: config.onDelegationChallengeFailure
|
|
250
|
+
}
|
|
251
|
+
) : void 0;
|
|
252
|
+
const rendered = renderDecisionAsResponse2(result, {
|
|
253
|
+
bodyReadable200,
|
|
254
|
+
delegationChallenge: validateBrowserIntegrityChallenge(result, delegationChallenge),
|
|
255
|
+
challengeContextRequested
|
|
256
|
+
});
|
|
257
|
+
return adaptToNextResponse(rendered, req);
|
|
258
|
+
};
|
|
259
|
+
}
|
|
182
260
|
var SDK_NAME = "@kya-os/checkpoint-nextjs";
|
|
183
|
-
var VERSION = "1.
|
|
261
|
+
var VERSION = "1.9.0";
|
|
184
262
|
function buildReporter(config, runtime = "node") {
|
|
185
263
|
if (!config.apiKey) return null;
|
|
186
264
|
return makeDetectionReporter({
|
|
@@ -194,6 +272,7 @@ function buildReporter(config, runtime = "node") {
|
|
|
194
272
|
});
|
|
195
273
|
}
|
|
196
274
|
function buildTrustedRootsResolver(config, composed) {
|
|
275
|
+
if (config.trustedDelegationRoots) return () => Promise.resolve(config.trustedDelegationRoots);
|
|
197
276
|
if (composed?.trustedDelegationRoots) {
|
|
198
277
|
return () => composed.trustedDelegationRoots();
|
|
199
278
|
}
|
|
@@ -206,10 +285,15 @@ function buildTrustedRootsResolver(config, composed) {
|
|
|
206
285
|
const projectId = config.projectId;
|
|
207
286
|
return async () => (await fetcher.getPolicy(projectId)).trustedDelegationRoots ?? [];
|
|
208
287
|
}
|
|
209
|
-
function extractReporterContext(req) {
|
|
288
|
+
function extractReporterContext(req, policy) {
|
|
289
|
+
const resolution = resolveClientIp({
|
|
290
|
+
headers: req.headers,
|
|
291
|
+
frameworkAddress: req.ip,
|
|
292
|
+
policy
|
|
293
|
+
});
|
|
210
294
|
return {
|
|
211
295
|
userAgent: req.headers.get("user-agent") ?? void 0,
|
|
212
|
-
ipAddress:
|
|
296
|
+
ipAddress: resolution.ip ?? void 0,
|
|
213
297
|
path: req.nextUrl.pathname,
|
|
214
298
|
url: req.nextUrl.href,
|
|
215
299
|
method: req.method
|
|
@@ -224,6 +308,8 @@ function buildVerifyOpts(config) {
|
|
|
224
308
|
policyEvaluator: overrides.policyEvaluator ?? makePolicyEvaluator({ dashboardUrl: config.dashboardUrl }),
|
|
225
309
|
clock: makeSystemClock(),
|
|
226
310
|
tenantHost: config.tenantHost,
|
|
311
|
+
resourceOrgDid: config.resourceOrgDid,
|
|
312
|
+
trustedDelegationRoots: config.trustedDelegationRoots,
|
|
227
313
|
enforcementMode: config.enforcementMode ?? "enforce",
|
|
228
314
|
reputationBaseline: config.reputationBaseline,
|
|
229
315
|
argusUrl: config.argusUrl,
|
|
@@ -231,37 +317,6 @@ function buildVerifyOpts(config) {
|
|
|
231
317
|
engineConfig: config.engineConfig
|
|
232
318
|
};
|
|
233
319
|
}
|
|
234
|
-
|
|
235
|
-
// src/middleware-edge.ts
|
|
236
|
-
function withCheckpoint(config) {
|
|
237
|
-
void initEngineEdge();
|
|
238
|
-
const opts = buildVerifyOpts(config);
|
|
239
|
-
const reporter = buildReporter(config, "edge");
|
|
240
|
-
const composed = buildComposedContext(config);
|
|
241
|
-
const trustedRootsResolver = buildTrustedRootsResolver(config, composed);
|
|
242
|
-
const translateOpts = { drainJsonBody: config.drainJsonBody };
|
|
243
|
-
return async function checkpointMiddlewareEdge(req, event) {
|
|
244
|
-
const httpLike = await nextRequestToHttpLike(req, translateOpts);
|
|
245
|
-
const trustedDelegationRoots = await resolveTrustedDelegationRootsForRequest(
|
|
246
|
-
trustedRootsResolver,
|
|
247
|
-
req.headers
|
|
248
|
-
);
|
|
249
|
-
const result = await verifyRequestEdge(
|
|
250
|
-
httpLike,
|
|
251
|
-
trustedDelegationRoots ? { ...opts, trustedDelegationRoots } : opts
|
|
252
|
-
);
|
|
253
|
-
await applyComposedPolicy(composed, result, req.nextUrl.pathname);
|
|
254
|
-
if (reporter) {
|
|
255
|
-
const reportPromise = reporter(result, extractReporterContext(req));
|
|
256
|
-
if (event) {
|
|
257
|
-
event.waitUntil(reportPromise);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
await dispatchOnResult(config, result, req);
|
|
261
|
-
const rendered = renderDecisionAsResponse(result);
|
|
262
|
-
return adaptToNextResponse(rendered, req);
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
320
|
async function dispatchOnResult(config, result, req) {
|
|
266
321
|
if (!config.onResult) return;
|
|
267
322
|
try {
|
|
@@ -269,6 +324,15 @@ async function dispatchOnResult(config, result, req) {
|
|
|
269
324
|
} catch {
|
|
270
325
|
}
|
|
271
326
|
}
|
|
327
|
+
|
|
328
|
+
// src/middleware-edge.ts
|
|
329
|
+
function withCheckpoint(config) {
|
|
330
|
+
void initEngineEdge();
|
|
331
|
+
return makeNextMiddleware(verifyRequestEdge, renderDecisionAsResponse, config, {
|
|
332
|
+
runtime: "edge",
|
|
333
|
+
buildComposedContext
|
|
334
|
+
});
|
|
335
|
+
}
|
|
272
336
|
function buildComposedContext(config) {
|
|
273
337
|
if (config.composedPolicyEnforcer) return config.composedPolicyEnforcer;
|
|
274
338
|
if (!config.projectId || !config.cedarWasmModule) return null;
|
|
@@ -1,63 +1,27 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import { ComposedPolicyContext, TrustedDelegationRootsResolver } from './composed-policy.mjs';
|
|
7
|
-
import '@kya-os/checkpoint-wasm-runtime/composed-policy';
|
|
1
|
+
import * as next_server from 'next/server';
|
|
2
|
+
import { C as CheckpointConfig } from './config-CleTeeoW.mjs';
|
|
3
|
+
import '@kya-os/checkpoint-shared/browser-posture';
|
|
4
|
+
import '@kya-os/checkpoint-wasm-runtime/adapters';
|
|
5
|
+
import '@kya-os/checkpoint-wasm-runtime/engine';
|
|
8
6
|
import '@kya-os/checkpoint-shared';
|
|
7
|
+
import './composed-policy.mjs';
|
|
8
|
+
import '@kya-os/checkpoint-wasm-runtime/composed-policy';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* Every verification decision flows through the Rust `kya-os-engine`
|
|
15
|
-
* via WASM. The TS layer translates request shape, calls
|
|
16
|
-
* `verifyRequest`, and translates the verdict to `NextResponse`. No
|
|
17
|
-
* verification logic lives in this file.
|
|
11
|
+
* Shared Next.js request pipeline. Node, bundler and Edge hosts inject their
|
|
12
|
+
* engine and policy-context factories; runtime-specific WASM initialization
|
|
13
|
+
* stays in each host entry. Public withCheckpoint exports live there too.
|
|
18
14
|
*/
|
|
19
|
-
|
|
15
|
+
|
|
20
16
|
/**
|
|
21
17
|
* Installed SDK version, self-reported to the detection reporter so the
|
|
22
18
|
* dashboard can version-gate "composed policy enforces here". MUST equal
|
|
23
19
|
* `package.json` version — pinned by a unit test (the old hardcoded `0.1.0` had
|
|
24
20
|
* drifted). Re-exported as `VERSION` from the package index.
|
|
25
21
|
*/
|
|
26
|
-
declare const VERSION = "1.
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
|
|
30
|
-
* pinning is a security concern INDEPENDENT of composed Cedar enforcement, so it
|
|
31
|
-
* must resolve wherever a `projectId` exists — including Edge setups that never
|
|
32
|
-
* wire `cedarWasmModule` (where `buildComposedContext` returns null). Prefers the
|
|
33
|
-
* composed context's accessor (reuses its cached fetcher / honors an injected
|
|
34
|
-
* enforcer); otherwise falls back to a `projectId`-only policy fetch. Returns
|
|
35
|
-
* `null` when no source is configured (no roots → engine open default).
|
|
36
|
-
*/
|
|
37
|
-
declare function buildTrustedRootsResolver(config: CheckpointConfig, composed: ComposedPolicyContext | null): TrustedDelegationRootsResolver | null;
|
|
38
|
-
/**
|
|
39
|
-
* Pull the request context the dashboard's `/api/v1/log-detection`
|
|
40
|
-
* endpoint expects out of a `NextRequest`. Works under both Node and
|
|
41
|
-
* Edge runtimes — no runtime-specific APIs.
|
|
42
|
-
*/
|
|
43
|
-
declare function extractReporterContext(req: NextRequest): ReporterContext;
|
|
44
|
-
/**
|
|
45
|
-
* Compose adapter defaults with caller-supplied overrides. Factored
|
|
46
|
-
* out so the Edge entry (which uses the same composition) can reuse
|
|
47
|
-
* the shape.
|
|
48
|
-
*/
|
|
49
|
-
declare function buildVerifyOpts(config: CheckpointConfig): {
|
|
50
|
-
didResolver: _kya_os_checkpoint_wasm_runtime_adapters.DidResolverAdapter;
|
|
51
|
-
statusListCache: _kya_os_checkpoint_wasm_runtime_adapters.StatusListCacheAdapter;
|
|
52
|
-
reputationOracle: _kya_os_checkpoint_wasm_runtime_adapters.ReputationOracleAdapter;
|
|
53
|
-
policyEvaluator: _kya_os_checkpoint_wasm_runtime_adapters.PolicyEvaluatorAdapter;
|
|
54
|
-
clock: _kya_os_checkpoint_wasm_runtime_adapters.ClockAdapter;
|
|
55
|
-
tenantHost: string;
|
|
56
|
-
enforcementMode: _kya_os_checkpoint_wasm_runtime_engine.EnforcementMode;
|
|
57
|
-
reputationBaseline: number | undefined;
|
|
58
|
-
argusUrl: string | undefined;
|
|
59
|
-
legacyEnvelopeFallback: boolean;
|
|
60
|
-
engineConfig: _kya_os_checkpoint_wasm_runtime_engine.EngineConfig | undefined;
|
|
61
|
-
};
|
|
22
|
+
declare const VERSION = "1.9.0";
|
|
23
|
+
|
|
24
|
+
/** Node host with native filesystem WASM loading. */
|
|
25
|
+
declare function withCheckpoint(config: CheckpointConfig): (req: next_server.NextRequest, event?: Pick<next_server.NextFetchEvent, "waitUntil">) => Promise<next_server.NextResponse>;
|
|
62
26
|
|
|
63
|
-
export { CheckpointConfig, VERSION,
|
|
27
|
+
export { CheckpointConfig, VERSION, withCheckpoint };
|
|
@@ -1,63 +1,27 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import { ComposedPolicyContext, TrustedDelegationRootsResolver } from './composed-policy.js';
|
|
7
|
-
import '@kya-os/checkpoint-wasm-runtime/composed-policy';
|
|
1
|
+
import * as next_server from 'next/server';
|
|
2
|
+
import { C as CheckpointConfig } from './config-XMOIkxFN.js';
|
|
3
|
+
import '@kya-os/checkpoint-shared/browser-posture';
|
|
4
|
+
import '@kya-os/checkpoint-wasm-runtime/adapters';
|
|
5
|
+
import '@kya-os/checkpoint-wasm-runtime/engine';
|
|
8
6
|
import '@kya-os/checkpoint-shared';
|
|
7
|
+
import './composed-policy.js';
|
|
8
|
+
import '@kya-os/checkpoint-wasm-runtime/composed-policy';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* Every verification decision flows through the Rust `kya-os-engine`
|
|
15
|
-
* via WASM. The TS layer translates request shape, calls
|
|
16
|
-
* `verifyRequest`, and translates the verdict to `NextResponse`. No
|
|
17
|
-
* verification logic lives in this file.
|
|
11
|
+
* Shared Next.js request pipeline. Node, bundler and Edge hosts inject their
|
|
12
|
+
* engine and policy-context factories; runtime-specific WASM initialization
|
|
13
|
+
* stays in each host entry. Public withCheckpoint exports live there too.
|
|
18
14
|
*/
|
|
19
|
-
|
|
15
|
+
|
|
20
16
|
/**
|
|
21
17
|
* Installed SDK version, self-reported to the detection reporter so the
|
|
22
18
|
* dashboard can version-gate "composed policy enforces here". MUST equal
|
|
23
19
|
* `package.json` version — pinned by a unit test (the old hardcoded `0.1.0` had
|
|
24
20
|
* drifted). Re-exported as `VERSION` from the package index.
|
|
25
21
|
*/
|
|
26
|
-
declare const VERSION = "1.
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
|
|
30
|
-
* pinning is a security concern INDEPENDENT of composed Cedar enforcement, so it
|
|
31
|
-
* must resolve wherever a `projectId` exists — including Edge setups that never
|
|
32
|
-
* wire `cedarWasmModule` (where `buildComposedContext` returns null). Prefers the
|
|
33
|
-
* composed context's accessor (reuses its cached fetcher / honors an injected
|
|
34
|
-
* enforcer); otherwise falls back to a `projectId`-only policy fetch. Returns
|
|
35
|
-
* `null` when no source is configured (no roots → engine open default).
|
|
36
|
-
*/
|
|
37
|
-
declare function buildTrustedRootsResolver(config: CheckpointConfig, composed: ComposedPolicyContext | null): TrustedDelegationRootsResolver | null;
|
|
38
|
-
/**
|
|
39
|
-
* Pull the request context the dashboard's `/api/v1/log-detection`
|
|
40
|
-
* endpoint expects out of a `NextRequest`. Works under both Node and
|
|
41
|
-
* Edge runtimes — no runtime-specific APIs.
|
|
42
|
-
*/
|
|
43
|
-
declare function extractReporterContext(req: NextRequest): ReporterContext;
|
|
44
|
-
/**
|
|
45
|
-
* Compose adapter defaults with caller-supplied overrides. Factored
|
|
46
|
-
* out so the Edge entry (which uses the same composition) can reuse
|
|
47
|
-
* the shape.
|
|
48
|
-
*/
|
|
49
|
-
declare function buildVerifyOpts(config: CheckpointConfig): {
|
|
50
|
-
didResolver: _kya_os_checkpoint_wasm_runtime_adapters.DidResolverAdapter;
|
|
51
|
-
statusListCache: _kya_os_checkpoint_wasm_runtime_adapters.StatusListCacheAdapter;
|
|
52
|
-
reputationOracle: _kya_os_checkpoint_wasm_runtime_adapters.ReputationOracleAdapter;
|
|
53
|
-
policyEvaluator: _kya_os_checkpoint_wasm_runtime_adapters.PolicyEvaluatorAdapter;
|
|
54
|
-
clock: _kya_os_checkpoint_wasm_runtime_adapters.ClockAdapter;
|
|
55
|
-
tenantHost: string;
|
|
56
|
-
enforcementMode: _kya_os_checkpoint_wasm_runtime_engine.EnforcementMode;
|
|
57
|
-
reputationBaseline: number | undefined;
|
|
58
|
-
argusUrl: string | undefined;
|
|
59
|
-
legacyEnvelopeFallback: boolean;
|
|
60
|
-
engineConfig: _kya_os_checkpoint_wasm_runtime_engine.EngineConfig | undefined;
|
|
61
|
-
};
|
|
22
|
+
declare const VERSION = "1.9.0";
|
|
23
|
+
|
|
24
|
+
/** Node host with native filesystem WASM loading. */
|
|
25
|
+
declare function withCheckpoint(config: CheckpointConfig): (req: next_server.NextRequest, event?: Pick<next_server.NextFetchEvent, "waitUntil">) => Promise<next_server.NextResponse>;
|
|
62
26
|
|
|
63
|
-
export { CheckpointConfig, VERSION,
|
|
27
|
+
export { CheckpointConfig, VERSION, withCheckpoint };
|