@kya-os/checkpoint-nextjs 1.7.1 → 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 +11 -11
- package/README.md +144 -251
- package/bin/setup-edge-wasm.js +9 -1
- 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 +5 -3
- package/dist/api-middleware.d.ts +5 -3
- package/dist/api-middleware.js +19 -32
- package/dist/api-middleware.mjs +20 -33
- package/dist/composed-policy.js +1 -0
- package/dist/composed-policy.mjs +2 -1
- package/dist/{config-DAwIA4DB.d.mts → config-CleTeeoW.d.mts} +32 -13
- package/dist/{config-DyU4l5er.d.ts → config-XMOIkxFN.d.ts} +32 -13
- 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 +126 -85
- package/dist/index.mjs +128 -87
- 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 +4 -40
- package/dist/middleware-edge.d.ts +4 -40
- package/dist/middleware-edge.js +148 -100
- package/dist/middleware-edge.mjs +151 -103
- package/dist/middleware-node.d.mts +15 -51
- package/dist/middleware-node.d.ts +15 -51
- package/dist/middleware-node.js +99 -56
- package/dist/middleware-node.mjs +102 -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/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 { selectBodyReadable200, 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,
|
|
@@ -148,8 +101,57 @@ var consoleComposedPolicyLogger = {
|
|
|
148
101
|
);
|
|
149
102
|
}
|
|
150
103
|
};
|
|
151
|
-
|
|
152
|
-
|
|
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
|
+
}
|
|
153
155
|
async function nextRequestToHttpLike(req, opts = {}) {
|
|
154
156
|
const url = new URL(req.url);
|
|
155
157
|
const body = await tryDrainJsonBody(req, opts);
|
|
@@ -159,7 +161,7 @@ async function nextRequestToHttpLike(req, opts = {}) {
|
|
|
159
161
|
url: url.pathname + url.search,
|
|
160
162
|
headers: headersToRecord(req.headers),
|
|
161
163
|
body,
|
|
162
|
-
remoteAddress: extractRemoteAddress(req)
|
|
164
|
+
remoteAddress: extractRemoteAddress(req, opts.clientIpPolicy ?? { platform: "direct" })
|
|
163
165
|
};
|
|
164
166
|
}
|
|
165
167
|
async function tryDrainJsonBody(req, opts) {
|
|
@@ -179,19 +181,84 @@ function headersToRecord(headers) {
|
|
|
179
181
|
});
|
|
180
182
|
return out;
|
|
181
183
|
}
|
|
182
|
-
function extractRemoteAddress(req) {
|
|
183
|
-
const xff = req.headers.get("x-forwarded-for");
|
|
184
|
-
if (xff) {
|
|
185
|
-
const first = xff.split(",")[0]?.trim();
|
|
186
|
-
if (first) return first;
|
|
187
|
-
}
|
|
184
|
+
function extractRemoteAddress(req, policy) {
|
|
188
185
|
const maybeIp = req.ip;
|
|
189
|
-
return
|
|
186
|
+
return resolveClientIp({
|
|
187
|
+
headers: req.headers,
|
|
188
|
+
frameworkAddress: maybeIp,
|
|
189
|
+
policy
|
|
190
|
+
}).ip ?? void 0;
|
|
190
191
|
}
|
|
191
192
|
|
|
192
|
-
// 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
|
+
}
|
|
193
260
|
var SDK_NAME = "@kya-os/checkpoint-nextjs";
|
|
194
|
-
var VERSION = "1.
|
|
261
|
+
var VERSION = "1.9.0";
|
|
195
262
|
function buildReporter(config, runtime = "node") {
|
|
196
263
|
if (!config.apiKey) return null;
|
|
197
264
|
return makeDetectionReporter({
|
|
@@ -205,6 +272,7 @@ function buildReporter(config, runtime = "node") {
|
|
|
205
272
|
});
|
|
206
273
|
}
|
|
207
274
|
function buildTrustedRootsResolver(config, composed) {
|
|
275
|
+
if (config.trustedDelegationRoots) return () => Promise.resolve(config.trustedDelegationRoots);
|
|
208
276
|
if (composed?.trustedDelegationRoots) {
|
|
209
277
|
return () => composed.trustedDelegationRoots();
|
|
210
278
|
}
|
|
@@ -217,10 +285,15 @@ function buildTrustedRootsResolver(config, composed) {
|
|
|
217
285
|
const projectId = config.projectId;
|
|
218
286
|
return async () => (await fetcher.getPolicy(projectId)).trustedDelegationRoots ?? [];
|
|
219
287
|
}
|
|
220
|
-
function extractReporterContext(req) {
|
|
288
|
+
function extractReporterContext(req, policy) {
|
|
289
|
+
const resolution = resolveClientIp({
|
|
290
|
+
headers: req.headers,
|
|
291
|
+
frameworkAddress: req.ip,
|
|
292
|
+
policy
|
|
293
|
+
});
|
|
221
294
|
return {
|
|
222
295
|
userAgent: req.headers.get("user-agent") ?? void 0,
|
|
223
|
-
ipAddress:
|
|
296
|
+
ipAddress: resolution.ip ?? void 0,
|
|
224
297
|
path: req.nextUrl.pathname,
|
|
225
298
|
url: req.nextUrl.href,
|
|
226
299
|
method: req.method
|
|
@@ -235,6 +308,8 @@ function buildVerifyOpts(config) {
|
|
|
235
308
|
policyEvaluator: overrides.policyEvaluator ?? makePolicyEvaluator({ dashboardUrl: config.dashboardUrl }),
|
|
236
309
|
clock: makeSystemClock(),
|
|
237
310
|
tenantHost: config.tenantHost,
|
|
311
|
+
resourceOrgDid: config.resourceOrgDid,
|
|
312
|
+
trustedDelegationRoots: config.trustedDelegationRoots,
|
|
238
313
|
enforcementMode: config.enforcementMode ?? "enforce",
|
|
239
314
|
reputationBaseline: config.reputationBaseline,
|
|
240
315
|
argusUrl: config.argusUrl,
|
|
@@ -242,42 +317,6 @@ function buildVerifyOpts(config) {
|
|
|
242
317
|
engineConfig: config.engineConfig
|
|
243
318
|
};
|
|
244
319
|
}
|
|
245
|
-
|
|
246
|
-
// src/middleware-edge.ts
|
|
247
|
-
function withCheckpoint(config) {
|
|
248
|
-
void initEngineEdge();
|
|
249
|
-
const opts = buildVerifyOpts(config);
|
|
250
|
-
const reporter = buildReporter(config, "edge");
|
|
251
|
-
const composed = buildComposedContext(config);
|
|
252
|
-
const trustedRootsResolver = buildTrustedRootsResolver(config, composed);
|
|
253
|
-
const translateOpts = { drainJsonBody: config.drainJsonBody };
|
|
254
|
-
return async function checkpointMiddlewareEdge(req, event) {
|
|
255
|
-
const httpLike = await nextRequestToHttpLike(req, translateOpts);
|
|
256
|
-
const trustedDelegationRoots = await resolveTrustedDelegationRootsForRequest(
|
|
257
|
-
trustedRootsResolver,
|
|
258
|
-
req.headers
|
|
259
|
-
);
|
|
260
|
-
const result = await verifyRequestEdge(
|
|
261
|
-
httpLike,
|
|
262
|
-
trustedDelegationRoots ? { ...opts, trustedDelegationRoots } : opts
|
|
263
|
-
);
|
|
264
|
-
await applyComposedPolicy(composed, result, req.nextUrl.pathname);
|
|
265
|
-
if (reporter) {
|
|
266
|
-
const reportPromise = reporter(result, extractReporterContext(req));
|
|
267
|
-
if (event) {
|
|
268
|
-
event.waitUntil(reportPromise);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
await dispatchOnResult(config, result, req);
|
|
272
|
-
const bodyReadable200 = selectBodyReadable200(
|
|
273
|
-
config.delegationChallengeMode ?? "spec-401",
|
|
274
|
-
req.headers,
|
|
275
|
-
result.detectionDetail.detectionClass
|
|
276
|
-
);
|
|
277
|
-
const rendered = renderDecisionAsResponse(result, { bodyReadable200 });
|
|
278
|
-
return adaptToNextResponse(rendered, req);
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
320
|
async function dispatchOnResult(config, result, req) {
|
|
282
321
|
if (!config.onResult) return;
|
|
283
322
|
try {
|
|
@@ -285,6 +324,15 @@ async function dispatchOnResult(config, result, req) {
|
|
|
285
324
|
} catch {
|
|
286
325
|
}
|
|
287
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
|
+
}
|
|
288
336
|
function buildComposedContext(config) {
|
|
289
337
|
if (config.composedPolicyEnforcer) return config.composedPolicyEnforcer;
|
|
290
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';
|
|
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';
|
|
7
6
|
import '@kya-os/checkpoint-shared';
|
|
7
|
+
import './composed-policy.mjs';
|
|
8
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';
|
|
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';
|
|
7
6
|
import '@kya-os/checkpoint-shared';
|
|
7
|
+
import './composed-policy.js';
|
|
8
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 };
|