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