@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/index.mjs
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { renderDecisionAsResponse, verifyRequest } from '@kya-os/checkpoint-wasm-runtime/orchestrator';
|
|
2
|
+
import { validateBrowserPostureConfig } from '@kya-os/checkpoint-shared/browser-posture';
|
|
3
|
+
import { applyBrowserPosture, applyBrowserIntegrityStepUp, validateBrowserIntegrityChallenge, makeComposedPolicyCache, isCredentialVerificationBlock, evaluateComposedPolicy, verifyResultToAuthorizeInput } from '@kya-os/checkpoint-wasm-runtime/composed-policy';
|
|
2
4
|
import { makeSystemClock, makePolicyEvaluator, makeReputationOracle, makeStatusListCache, makeDidResolver } from '@kya-os/checkpoint-wasm-runtime/adapters';
|
|
3
5
|
import { makeDetectionReporter } from '@kya-os/checkpoint-wasm-runtime/reporter';
|
|
4
|
-
import { selectBodyReadable200,
|
|
6
|
+
import { selectBodyReadable200, isKnownAiCrawler, createEvaluationContext, evaluatePolicy, ENFORCEMENT_ACTIONS, PolicyConfigSchema, DEFAULT_POLICY, matchPath, resolveChallengeContext, resolveClientIp, createPolicyFetcher, PolicyFetcher, requestCarriesDelegationProof, acceptsHtml, encodeVerdictCookie, classifyResponseShape, BLOCKED_PATH, VERDICT_COOKIE_NAME } from '@kya-os/checkpoint-shared';
|
|
5
7
|
export { DEFAULT_POLICY, ENFORCEMENT_ACTIONS, createEvaluationContext, evaluatePolicy } from '@kya-os/checkpoint-shared';
|
|
6
8
|
import { NextResponse } from 'next/server';
|
|
7
|
-
import {
|
|
9
|
+
import { waitUntil } from '@vercel/functions';
|
|
8
10
|
|
|
9
11
|
// src/middleware-node.ts
|
|
10
12
|
function adaptToNextResponse(rendered, req) {
|
|
@@ -14,28 +16,28 @@ function adaptToNextResponse(rendered, req) {
|
|
|
14
16
|
switch (shape) {
|
|
15
17
|
case "pass-through": {
|
|
16
18
|
const res = NextResponse.next();
|
|
17
|
-
applyHeaders(res, rendered
|
|
19
|
+
applyHeaders(res, rendered);
|
|
18
20
|
setVerdictCookie(res, verdictCookie);
|
|
19
21
|
return res;
|
|
20
22
|
}
|
|
21
23
|
case "redirect": {
|
|
22
24
|
const target = new URL(rendered.headers.Location);
|
|
23
25
|
const res = NextResponse.redirect(target);
|
|
24
|
-
applyHeaders(res, rendered
|
|
26
|
+
applyHeaders(res, rendered);
|
|
25
27
|
setVerdictCookie(res, verdictCookie);
|
|
26
28
|
return res;
|
|
27
29
|
}
|
|
28
30
|
case "html-block": {
|
|
29
31
|
const blockedUrl = new URL(BLOCKED_PATH, req.url);
|
|
30
32
|
const res = NextResponse.rewrite(blockedUrl, { status: 200 });
|
|
31
|
-
applyHeaders(res, rendered
|
|
33
|
+
applyHeaders(res, rendered);
|
|
32
34
|
setVerdictCookie(res, verdictCookie);
|
|
33
35
|
return res;
|
|
34
36
|
}
|
|
35
37
|
case "json-block": {
|
|
36
38
|
const body = rendered.body ?? {};
|
|
37
39
|
const res = NextResponse.json(body, { status: rendered.status });
|
|
38
|
-
applyHeaders(res, rendered
|
|
40
|
+
applyHeaders(res, rendered);
|
|
39
41
|
setVerdictCookie(res, verdictCookie);
|
|
40
42
|
return res;
|
|
41
43
|
}
|
|
@@ -50,10 +52,13 @@ function setVerdictCookie(res, value) {
|
|
|
50
52
|
httpOnly: false
|
|
51
53
|
});
|
|
52
54
|
}
|
|
53
|
-
function applyHeaders(res,
|
|
54
|
-
for (const [key, value] of Object.entries(headers)) {
|
|
55
|
+
function applyHeaders(res, rendered) {
|
|
56
|
+
for (const [key, value] of Object.entries(rendered.headers)) {
|
|
55
57
|
res.headers.set(key, value);
|
|
56
58
|
}
|
|
59
|
+
for (const [key, value] of rendered.headerEntries ?? []) {
|
|
60
|
+
res.headers.append(key, value);
|
|
61
|
+
}
|
|
57
62
|
}
|
|
58
63
|
var DEFAULT_DASHBOARD_URL = "https://kya.vouched.id";
|
|
59
64
|
var NOOP_LOGGER = {
|
|
@@ -69,6 +74,7 @@ function makeComposedPolicyContext(opts) {
|
|
|
69
74
|
return {
|
|
70
75
|
async apply(result, path) {
|
|
71
76
|
const structured = { decision: result.decision, acted: false };
|
|
77
|
+
if (isCredentialVerificationBlock(result.decision)) return structured;
|
|
72
78
|
const policy = await fetcher.getPolicy(projectId);
|
|
73
79
|
const outcome = await evaluateComposedPolicy({
|
|
74
80
|
cache,
|
|
@@ -145,8 +151,6 @@ var consoleComposedPolicyLogger = {
|
|
|
145
151
|
);
|
|
146
152
|
}
|
|
147
153
|
};
|
|
148
|
-
|
|
149
|
-
// src/translate.ts
|
|
150
154
|
async function nextRequestToHttpLike(req, opts = {}) {
|
|
151
155
|
const url = new URL(req.url);
|
|
152
156
|
const body = await tryDrainJsonBody(req, opts);
|
|
@@ -156,7 +160,7 @@ async function nextRequestToHttpLike(req, opts = {}) {
|
|
|
156
160
|
url: url.pathname + url.search,
|
|
157
161
|
headers: headersToRecord(req.headers),
|
|
158
162
|
body,
|
|
159
|
-
remoteAddress: extractRemoteAddress(req)
|
|
163
|
+
remoteAddress: extractRemoteAddress(req, opts.clientIpPolicy ?? { platform: "direct" })
|
|
160
164
|
};
|
|
161
165
|
}
|
|
162
166
|
async function tryDrainJsonBody(req, opts) {
|
|
@@ -176,52 +180,84 @@ function headersToRecord(headers) {
|
|
|
176
180
|
});
|
|
177
181
|
return out;
|
|
178
182
|
}
|
|
179
|
-
function extractRemoteAddress(req) {
|
|
180
|
-
const xff = req.headers.get("x-forwarded-for");
|
|
181
|
-
if (xff) {
|
|
182
|
-
const first = xff.split(",")[0]?.trim();
|
|
183
|
-
if (first) return first;
|
|
184
|
-
}
|
|
183
|
+
function extractRemoteAddress(req, policy) {
|
|
185
184
|
const maybeIp = req.ip;
|
|
186
|
-
return
|
|
185
|
+
return resolveClientIp({
|
|
186
|
+
headers: req.headers,
|
|
187
|
+
frameworkAddress: maybeIp,
|
|
188
|
+
policy
|
|
189
|
+
}).ip ?? void 0;
|
|
187
190
|
}
|
|
188
191
|
|
|
189
|
-
// src/middleware-
|
|
190
|
-
function
|
|
192
|
+
// src/middleware-core.ts
|
|
193
|
+
function makeNextMiddleware(verifyRequest2, renderDecisionAsResponse2, config, host) {
|
|
194
|
+
if (config.browserPosture) validateBrowserPostureConfig(config.browserPosture, config.projectId);
|
|
195
|
+
if (config.browserPosture?.protectedRoutes?.length && !config.resolveDelegationChallenge) {
|
|
196
|
+
throw new Error(
|
|
197
|
+
"browserPosture.protectedRoutes requires resolveDelegationChallenge (see createBrowserIntegrityChallengeResolver)"
|
|
198
|
+
);
|
|
199
|
+
}
|
|
191
200
|
const opts = buildVerifyOpts(config);
|
|
192
|
-
const reporter = buildReporter(config);
|
|
193
|
-
const composed = buildComposedContext(config);
|
|
201
|
+
const reporter = buildReporter(config, host.runtime);
|
|
202
|
+
const composed = host.buildComposedContext(config);
|
|
194
203
|
const trustedRootsResolver = buildTrustedRootsResolver(config, composed);
|
|
195
|
-
const translateOpts = {
|
|
204
|
+
const translateOpts = {
|
|
205
|
+
drainJsonBody: config.drainJsonBody,
|
|
206
|
+
clientIpPolicy: config.clientIpPolicy
|
|
207
|
+
};
|
|
196
208
|
return async function checkpointMiddleware(req, event) {
|
|
197
209
|
const httpLike = await nextRequestToHttpLike(req, translateOpts);
|
|
198
210
|
const trustedDelegationRoots = await resolveTrustedDelegationRootsForRequest(
|
|
199
211
|
trustedRootsResolver,
|
|
200
212
|
req.headers
|
|
201
213
|
);
|
|
202
|
-
const result = await
|
|
214
|
+
const result = await verifyRequest2(
|
|
203
215
|
httpLike,
|
|
204
216
|
trustedDelegationRoots ? { ...opts, trustedDelegationRoots } : opts
|
|
205
217
|
);
|
|
218
|
+
await applyBrowserPosture(
|
|
219
|
+
result,
|
|
220
|
+
req.headers.get("cookie"),
|
|
221
|
+
config.browserPosture,
|
|
222
|
+
config.projectId
|
|
223
|
+
);
|
|
206
224
|
await applyComposedPolicy(composed, result, req.nextUrl.pathname);
|
|
225
|
+
applyBrowserIntegrityStepUp(result, config.browserPosture, req.nextUrl.pathname);
|
|
207
226
|
if (reporter) {
|
|
208
|
-
const reportPromise = reporter(
|
|
227
|
+
const reportPromise = reporter(
|
|
228
|
+
result,
|
|
229
|
+
extractReporterContext(req, config.clientIpPolicy ?? { platform: "direct" })
|
|
230
|
+
);
|
|
209
231
|
if (event) {
|
|
210
232
|
event.waitUntil(reportPromise);
|
|
211
233
|
}
|
|
212
234
|
}
|
|
213
235
|
await dispatchOnResult(config, result, req);
|
|
214
236
|
const bodyReadable200 = selectBodyReadable200(
|
|
215
|
-
config.delegationChallengeMode ?? "
|
|
237
|
+
config.delegationChallengeMode ?? "negotiated",
|
|
216
238
|
req.headers,
|
|
217
|
-
result.detectionDetail.detectionClass
|
|
239
|
+
result.detectionDetail.detectionClass,
|
|
240
|
+
result.detectionDetail.isAgent
|
|
218
241
|
);
|
|
219
|
-
const
|
|
242
|
+
const challengeContextRequested = result.enforcementMode === "enforce" && result.decision.kind === "Challenge" && config.resolveDelegationChallenge !== void 0;
|
|
243
|
+
const delegationChallenge = challengeContextRequested ? await resolveChallengeContext(
|
|
244
|
+
config.resolveDelegationChallenge,
|
|
245
|
+
{ result, request: req },
|
|
246
|
+
{
|
|
247
|
+
timeoutMs: config.delegationChallengeTimeoutMs,
|
|
248
|
+
onFailure: config.onDelegationChallengeFailure
|
|
249
|
+
}
|
|
250
|
+
) : void 0;
|
|
251
|
+
const rendered = renderDecisionAsResponse2(result, {
|
|
252
|
+
bodyReadable200,
|
|
253
|
+
delegationChallenge: validateBrowserIntegrityChallenge(result, delegationChallenge),
|
|
254
|
+
challengeContextRequested
|
|
255
|
+
});
|
|
220
256
|
return adaptToNextResponse(rendered, req);
|
|
221
257
|
};
|
|
222
258
|
}
|
|
223
259
|
var SDK_NAME = "@kya-os/checkpoint-nextjs";
|
|
224
|
-
var VERSION = "1.
|
|
260
|
+
var VERSION = "1.9.0";
|
|
225
261
|
function buildReporter(config, runtime = "node") {
|
|
226
262
|
if (!config.apiKey) return null;
|
|
227
263
|
return makeDetectionReporter({
|
|
@@ -235,6 +271,7 @@ function buildReporter(config, runtime = "node") {
|
|
|
235
271
|
});
|
|
236
272
|
}
|
|
237
273
|
function buildTrustedRootsResolver(config, composed) {
|
|
274
|
+
if (config.trustedDelegationRoots) return () => Promise.resolve(config.trustedDelegationRoots);
|
|
238
275
|
if (composed?.trustedDelegationRoots) {
|
|
239
276
|
return () => composed.trustedDelegationRoots();
|
|
240
277
|
}
|
|
@@ -247,33 +284,15 @@ function buildTrustedRootsResolver(config, composed) {
|
|
|
247
284
|
const projectId = config.projectId;
|
|
248
285
|
return async () => (await fetcher.getPolicy(projectId)).trustedDelegationRoots ?? [];
|
|
249
286
|
}
|
|
250
|
-
function
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
fetcher: new PolicyFetcher({
|
|
256
|
-
apiBaseUrl: config.dashboardUrl ?? config.baseUrl ?? DEFAULT_DASHBOARD_URL,
|
|
257
|
-
apiKey: config.apiKey,
|
|
258
|
-
cacheTtlSeconds: config.policyCacheTtlSeconds
|
|
259
|
-
}),
|
|
260
|
-
// LAZY dynamic import — NOT a top-level `import` — so the node-only
|
|
261
|
-
// `./policy` glue (`createRequire`/`fs` at module load) is never pulled into
|
|
262
|
-
// the Edge bundle. `middleware-edge.ts` imports helpers from this file, so a
|
|
263
|
-
// top-level `./policy` import would surface as a side-effect import in the
|
|
264
|
-
// edge bundle and boot-fail on Vercel edge. The import is cached after first
|
|
265
|
-
// call; the core's single-flight cache wraps the (now async) compile.
|
|
266
|
-
compile: async (_language, source) => {
|
|
267
|
-
const { createPolicyEvaluator } = await import('@kya-os/checkpoint-wasm-runtime/policy');
|
|
268
|
-
return createPolicyEvaluator(source);
|
|
269
|
-
},
|
|
270
|
-
logger: config.debug ? consoleComposedPolicyLogger : void 0
|
|
287
|
+
function extractReporterContext(req, policy) {
|
|
288
|
+
const resolution = resolveClientIp({
|
|
289
|
+
headers: req.headers,
|
|
290
|
+
frameworkAddress: req.ip,
|
|
291
|
+
policy
|
|
271
292
|
});
|
|
272
|
-
}
|
|
273
|
-
function extractReporterContext(req) {
|
|
274
293
|
return {
|
|
275
294
|
userAgent: req.headers.get("user-agent") ?? void 0,
|
|
276
|
-
ipAddress:
|
|
295
|
+
ipAddress: resolution.ip ?? void 0,
|
|
277
296
|
path: req.nextUrl.pathname,
|
|
278
297
|
url: req.nextUrl.href,
|
|
279
298
|
method: req.method
|
|
@@ -288,6 +307,8 @@ function buildVerifyOpts(config) {
|
|
|
288
307
|
policyEvaluator: overrides.policyEvaluator ?? makePolicyEvaluator({ dashboardUrl: config.dashboardUrl }),
|
|
289
308
|
clock: makeSystemClock(),
|
|
290
309
|
tenantHost: config.tenantHost,
|
|
310
|
+
resourceOrgDid: config.resourceOrgDid,
|
|
311
|
+
trustedDelegationRoots: config.trustedDelegationRoots,
|
|
291
312
|
enforcementMode: config.enforcementMode ?? "enforce",
|
|
292
313
|
reputationBaseline: config.reputationBaseline,
|
|
293
314
|
argusUrl: config.argusUrl,
|
|
@@ -302,6 +323,33 @@ async function dispatchOnResult(config, result, req) {
|
|
|
302
323
|
} catch {
|
|
303
324
|
}
|
|
304
325
|
}
|
|
326
|
+
function buildComposedContext(config) {
|
|
327
|
+
if (config.composedPolicyEnforcer) return config.composedPolicyEnforcer;
|
|
328
|
+
if (!config.projectId) return null;
|
|
329
|
+
return makeComposedPolicyContext({
|
|
330
|
+
projectId: config.projectId,
|
|
331
|
+
fetcher: new PolicyFetcher({
|
|
332
|
+
apiBaseUrl: config.dashboardUrl ?? config.baseUrl ?? DEFAULT_DASHBOARD_URL,
|
|
333
|
+
apiKey: config.apiKey,
|
|
334
|
+
cacheTtlSeconds: config.policyCacheTtlSeconds
|
|
335
|
+
}),
|
|
336
|
+
// Load the Node policy compiler only on first use. This module is imported
|
|
337
|
+
// exclusively by the Node and bundler hosts, never by the Edge pipeline.
|
|
338
|
+
compile: async (_language, source) => {
|
|
339
|
+
const { createPolicyEvaluator } = await import('@kya-os/checkpoint-wasm-runtime/policy');
|
|
340
|
+
return createPolicyEvaluator(source);
|
|
341
|
+
},
|
|
342
|
+
logger: config.debug ? consoleComposedPolicyLogger : void 0
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// src/middleware-node.ts
|
|
347
|
+
function withCheckpoint(config) {
|
|
348
|
+
return makeNextMiddleware(verifyRequest, renderDecisionAsResponse, config, {
|
|
349
|
+
runtime: "node",
|
|
350
|
+
buildComposedContext
|
|
351
|
+
});
|
|
352
|
+
}
|
|
305
353
|
var MIGRATION_ERROR = "@kya-os/checkpoint-nextjs's `createAgentShieldMiddleware` / `agentShield` were deleted in Phase D (engine consolidation). The 600-line TS pattern matcher that backed them is gone. Migrate to `withCheckpoint` from `@kya-os/checkpoint-nextjs` (Node runtime) or `@kya-os/checkpoint-nextjs/edge` (Edge runtime). See packages/checkpoint-nextjs/CHANGELOG.md (1.0.0) for the recipe.";
|
|
306
354
|
function createAgentShieldMiddleware(_config = {}) {
|
|
307
355
|
throw new Error(MIGRATION_ERROR);
|
|
@@ -540,21 +588,9 @@ function resetCheckpointApiClient() {
|
|
|
540
588
|
var AgentShieldClient = CheckpointApiClient;
|
|
541
589
|
var getAgentShieldClient = getCheckpointApiClient;
|
|
542
590
|
var resetAgentShieldClient = resetCheckpointApiClient;
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
const forwardedFor = request.headers.get("x-forwarded-for");
|
|
547
|
-
if (forwardedFor) {
|
|
548
|
-
const ip = forwardedFor.split(",")[0]?.trim();
|
|
549
|
-
if (ip) return ip;
|
|
550
|
-
}
|
|
551
|
-
const realIp = request.headers.get("x-real-ip");
|
|
552
|
-
if (realIp) return realIp;
|
|
553
|
-
const cfIp = request.headers.get("cf-connecting-ip");
|
|
554
|
-
if (cfIp) return cfIp;
|
|
555
|
-
const clientIp = request.headers.get("x-client-ip");
|
|
556
|
-
if (clientIp) return clientIp;
|
|
557
|
-
return void 0;
|
|
591
|
+
function getClientIp(request, policy = { platform: "direct" }) {
|
|
592
|
+
const frameworkAddress = request.ip;
|
|
593
|
+
return resolveClientIp({ headers: request.headers, frameworkAddress, policy }).ip ?? void 0;
|
|
558
594
|
}
|
|
559
595
|
function safeHostname(url) {
|
|
560
596
|
try {
|
|
@@ -565,7 +601,7 @@ function safeHostname(url) {
|
|
|
565
601
|
}
|
|
566
602
|
|
|
567
603
|
// src/responses/agent-instruction.ts
|
|
568
|
-
var MCP_I_DOCS_URL = "https://
|
|
604
|
+
var MCP_I_DOCS_URL = "https://kya.vouched.id/docs/enforce/kya-os-enforcement";
|
|
569
605
|
var DEFAULT_CONNECT_PATH = "/connect";
|
|
570
606
|
function buildAgentInstructionResponse(request, decision, redirectUrl, options) {
|
|
571
607
|
const resolved = resolveUrl(redirectUrl ?? DEFAULT_CONNECT_PATH, request.url);
|
|
@@ -620,9 +656,6 @@ It only takes a moment and you won't need to do it again. Once you're done, ask
|
|
|
620
656
|
};
|
|
621
657
|
const bodyReadable200 = options?.bodyReadable200 ?? false;
|
|
622
658
|
const response = NextResponse.json(body, { status: bodyReadable200 ? 200 : 401 });
|
|
623
|
-
if (!bodyReadable200) {
|
|
624
|
-
response.headers.set("WWW-Authenticate", `KYA realm="api", authorization_uri="${authUrl}"`);
|
|
625
|
-
}
|
|
626
659
|
response.headers.set(
|
|
627
660
|
"Link",
|
|
628
661
|
`<${authUrl}>; rel="kya-authorize", <${MCP_I_DOCS_URL}>; rel="help"`
|
|
@@ -642,8 +675,6 @@ function resolveUrl(target, baseUrl) {
|
|
|
642
675
|
return new URL(DEFAULT_CONNECT_PATH, baseUrl);
|
|
643
676
|
}
|
|
644
677
|
}
|
|
645
|
-
|
|
646
|
-
// src/api-middleware.ts
|
|
647
678
|
function shouldSkipPath(path, skipPaths) {
|
|
648
679
|
return skipPaths.some((pattern) => matchPath(path, pattern));
|
|
649
680
|
}
|
|
@@ -741,7 +772,7 @@ function withCheckpointApi(config = {}) {
|
|
|
741
772
|
try {
|
|
742
773
|
const client2 = getClient();
|
|
743
774
|
const userAgent = request.headers.get("user-agent") || void 0;
|
|
744
|
-
const ipAddress = getClientIp(request);
|
|
775
|
+
const ipAddress = getClientIp(request, config.clientIpPolicy);
|
|
745
776
|
const result = await client2.enforce({
|
|
746
777
|
headers: Object.fromEntries(request.headers.entries()),
|
|
747
778
|
userAgent,
|
|
@@ -780,14 +811,16 @@ function withCheckpointApi(config = {}) {
|
|
|
780
811
|
});
|
|
781
812
|
}
|
|
782
813
|
if (client2.isUsingEdge() && result.data.detection) {
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
814
|
+
waitUntil(
|
|
815
|
+
client2.logDetection({
|
|
816
|
+
detection: result.data.detection,
|
|
817
|
+
context: { userAgent, ipAddress, path, url: request.url, method: request.method }
|
|
818
|
+
}).catch((err) => {
|
|
819
|
+
if (config.debug) {
|
|
820
|
+
console.error("[Checkpoint] Log detection failed:", err);
|
|
821
|
+
}
|
|
822
|
+
})
|
|
823
|
+
);
|
|
791
824
|
}
|
|
792
825
|
if (decision.isAgent && config.onAgentDetected) {
|
|
793
826
|
try {
|
|
@@ -816,9 +849,10 @@ function withCheckpointApi(config = {}) {
|
|
|
816
849
|
}
|
|
817
850
|
const targetUrl = config.redirectUrl || decision.redirectUrl;
|
|
818
851
|
const bodyReadable200 = selectBodyReadable200(
|
|
819
|
-
config.delegationChallengeMode ?? "
|
|
852
|
+
config.delegationChallengeMode ?? "negotiated",
|
|
820
853
|
request.headers,
|
|
821
|
-
result.data.detection?.detectionClass
|
|
854
|
+
result.data.detection?.detectionClass,
|
|
855
|
+
result.data.detection?.isAgent ?? false
|
|
822
856
|
);
|
|
823
857
|
return buildAgentInstructionResponse(request, decision, targetUrl, {
|
|
824
858
|
bodyReadable200
|
|
@@ -1010,6 +1044,8 @@ var StatelessSessionChecker = class {
|
|
|
1010
1044
|
return null;
|
|
1011
1045
|
}
|
|
1012
1046
|
}
|
|
1047
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- published
|
|
1048
|
+
// signature; narrowing it is a breaking change, deferred to a major.
|
|
1013
1049
|
static setHeaders(response, session) {
|
|
1014
1050
|
try {
|
|
1015
1051
|
if (response.setHeader) {
|
|
@@ -1034,7 +1070,12 @@ function createContextFromDetection(detection, request) {
|
|
|
1034
1070
|
riskLevel: detection.riskLevel,
|
|
1035
1071
|
path: request.nextUrl.pathname,
|
|
1036
1072
|
method: request.method,
|
|
1037
|
-
|
|
1073
|
+
// Cryptographic-signature methods only, mirroring the composed-policy
|
|
1074
|
+
// VERIFIED_VERIFICATION_METHODS allowlist (checkpoint-wasm-runtime):
|
|
1075
|
+
// 'signature' (bare RFC 9421 keyid) and 'tier1_rfc9421' (RFC 9421 vendor-key
|
|
1076
|
+
// / Web Bot Auth, #4804) are the same crypto class; kya-http/kya-http-delegated
|
|
1077
|
+
// are the draft-kya-http-02 §4.3 request-signature methods.
|
|
1078
|
+
signatureVerified: detection.verificationMethod === "signature" || detection.verificationMethod === "tier1_rfc9421" || detection.verificationMethod === "kya-http" || detection.verificationMethod === "kya-http-delegated",
|
|
1038
1079
|
isAuthenticated: false,
|
|
1039
1080
|
// TODO: integrate with auth
|
|
1040
1081
|
userAgent: request.headers.get("user-agent") || void 0
|
|
@@ -0,0 +1,13 @@
|
|
|
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';
|
|
6
|
+
import '@kya-os/checkpoint-shared';
|
|
7
|
+
import './composed-policy.mjs';
|
|
8
|
+
import '@kya-os/checkpoint-wasm-runtime/composed-policy';
|
|
9
|
+
|
|
10
|
+
/** Next.js server bundlers import the WASM asset rather than relocating a Node fs read. */
|
|
11
|
+
declare function withCheckpoint(config: CheckpointConfig): (req: next_server.NextRequest, event?: Pick<next_server.NextFetchEvent, "waitUntil">) => Promise<next_server.NextResponse>;
|
|
12
|
+
|
|
13
|
+
export { CheckpointConfig, withCheckpoint };
|
|
@@ -0,0 +1,13 @@
|
|
|
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';
|
|
6
|
+
import '@kya-os/checkpoint-shared';
|
|
7
|
+
import './composed-policy.js';
|
|
8
|
+
import '@kya-os/checkpoint-wasm-runtime/composed-policy';
|
|
9
|
+
|
|
10
|
+
/** Next.js server bundlers import the WASM asset rather than relocating a Node fs read. */
|
|
11
|
+
declare function withCheckpoint(config: CheckpointConfig): (req: next_server.NextRequest, event?: Pick<next_server.NextFetchEvent, "waitUntil">) => Promise<next_server.NextResponse>;
|
|
12
|
+
|
|
13
|
+
export { CheckpointConfig, withCheckpoint };
|