@kya-os/checkpoint-shared 1.5.1 → 1.5.2
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 +120 -0
- package/dist/beacon-nonce/index.d.mts +36 -0
- package/dist/beacon-nonce/index.d.mts.map +1 -0
- package/dist/beacon-nonce/index.d.ts +36 -0
- package/dist/beacon-nonce/index.d.ts.map +1 -0
- package/dist/beacon-nonce/index.js +305 -0
- package/dist/beacon-nonce/index.mjs +294 -0
- package/dist/beacon-nonce/index.mjs.map +1 -0
- package/dist/beacon-types/index.d.mts +29 -0
- package/dist/beacon-types/index.d.mts.map +1 -1
- package/dist/beacon-types/index.d.ts +29 -0
- package/dist/beacon-types/index.d.ts.map +1 -1
- package/dist/beacon-types/index.js +36 -5
- package/dist/beacon-types/index.mjs +33 -6
- package/dist/beacon-types/index.mjs.map +1 -1
- package/dist/browser-posture-D4j2a5gi.d.ts +169 -0
- package/dist/browser-posture-D4j2a5gi.d.ts.map +1 -0
- package/dist/browser-posture-DVoHMHjY.d.mts +169 -0
- package/dist/browser-posture-DVoHMHjY.d.mts.map +1 -0
- package/dist/browser-posture-cookie.d.mts +4 -2
- package/dist/browser-posture-cookie.d.mts.map +1 -0
- package/dist/browser-posture-cookie.d.ts +4 -2
- package/dist/browser-posture-cookie.d.ts.map +1 -0
- package/dist/browser-posture-cookie.mjs.map +1 -1
- package/dist/browser-posture-proof.d.mts +18 -0
- package/dist/browser-posture-proof.d.mts.map +1 -0
- package/dist/browser-posture-proof.d.ts +18 -0
- package/dist/browser-posture-proof.d.ts.map +1 -0
- package/dist/browser-posture-proof.js +66 -0
- package/dist/browser-posture-proof.mjs +63 -0
- package/dist/browser-posture-proof.mjs.map +1 -0
- package/dist/browser-posture-report.d.mts +59 -2
- package/dist/browser-posture-report.d.mts.map +1 -1
- package/dist/browser-posture-report.d.ts +59 -2
- package/dist/browser-posture-report.d.ts.map +1 -1
- package/dist/browser-posture-report.js +1 -1
- package/dist/browser-posture-report.mjs +1 -1
- package/dist/browser-posture-report.mjs.map +1 -1
- package/dist/browser-posture.d.mts +2 -85
- package/dist/browser-posture.d.ts +2 -85
- package/dist/browser-posture.js +205 -43
- package/dist/browser-posture.mjs +194 -44
- package/dist/browser-posture.mjs.map +1 -1
- package/dist/browser.d.mts +0 -8
- package/dist/browser.d.mts.map +1 -1
- package/dist/browser.d.ts +0 -8
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +1 -1
- package/dist/browser.mjs +1 -1
- package/dist/browser.mjs.map +1 -1
- package/dist/clearance.d.mts +1 -1
- package/dist/clearance.d.ts +1 -1
- package/dist/{client-ip-HOfe6ucV.mjs → client-ip-B2Xeo-GK.mjs} +2 -2
- package/dist/{client-ip-HOfe6ucV.mjs.map → client-ip-B2Xeo-GK.mjs.map} +1 -1
- package/dist/{client-ip-1y2iXAYW.js → client-ip-CW6pRyLf.js} +1 -1
- package/dist/consent-handoff.d.mts +41 -0
- package/dist/consent-handoff.d.mts.map +1 -0
- package/dist/consent-handoff.d.ts +41 -0
- package/dist/consent-handoff.d.ts.map +1 -0
- package/dist/consent-handoff.js +1 -0
- package/dist/consent-handoff.mjs +2 -0
- package/dist/consent-handoff.mjs.map +1 -0
- package/dist/errors/index.d.mts +138 -0
- package/dist/errors/index.d.mts.map +1 -1
- package/dist/errors/index.d.ts +138 -0
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +441 -9
- package/dist/errors/index.mjs +441 -10
- package/dist/errors/index.mjs.map +1 -1
- package/dist/{external-jr_S4iSS.d.mts → external-Ct8j_hto.d.mts} +2 -2
- package/dist/{external-jr_S4iSS.d.mts.map → external-Ct8j_hto.d.mts.map} +1 -1
- package/dist/{external-jr_S4iSS.d.ts → external-Ct8j_hto.d.ts} +2 -2
- package/dist/{external-jr_S4iSS.d.ts.map → external-Ct8j_hto.d.ts.map} +1 -1
- package/dist/gateway-client-ip.d.mts +1 -1
- package/dist/gateway-client-ip.d.ts +1 -1
- package/dist/gateway-client-ip.js +1 -1
- package/dist/gateway-client-ip.mjs +1 -1
- package/dist/index.d.mts +5131 -967
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +5131 -967
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3678 -546
- package/dist/index.mjs +3446 -534
- package/dist/index.mjs.map +1 -1
- package/dist/mcpi/approval-grant/index.d.mts +1 -1
- package/dist/mcpi/approval-grant/index.d.mts.map +1 -1
- package/dist/mcpi/approval-grant/index.d.ts +1 -1
- package/dist/mcpi/approval-grant/index.d.ts.map +1 -1
- package/dist/mcpi/approval-grant/index.js +48 -48
- package/dist/mcpi/approval-grant/index.mjs +48 -48
- package/dist/mcpi/approval-grant/index.mjs.map +1 -1
- package/dist/posture-origins/index.d.mts +41 -0
- package/dist/posture-origins/index.d.mts.map +1 -0
- package/dist/posture-origins/index.d.ts +41 -0
- package/dist/posture-origins/index.d.ts.map +1 -0
- package/dist/posture-origins/index.js +441 -0
- package/dist/posture-origins/index.mjs +430 -0
- package/dist/posture-origins/index.mjs.map +1 -0
- package/dist/posture-origins-CEm83u4D.js +621 -0
- package/dist/posture-origins-Dl7i8j93.mjs +533 -0
- package/dist/posture-origins-Dl7i8j93.mjs.map +1 -0
- package/dist/rules.json +0 -1
- package/dist/signals/index.d.mts +75 -55
- package/dist/signals/index.d.mts.map +1 -1
- package/dist/signals/index.d.ts +75 -55
- package/dist/signals/index.d.ts.map +1 -1
- package/dist/signals/index.js +246 -2
- package/dist/signals/index.mjs +236 -3
- package/dist/signals/index.mjs.map +1 -1
- package/fixtures/browser-integrity/captured-java-0.2.1-missing-score.json +10 -0
- package/fixtures/browser-integrity/null-score.json +11 -0
- package/fixtures/browser-integrity/numeric-score.json +11 -0
- package/fixtures/browser-posture-claims.json +168 -0
- package/fixtures/browser-posture-headers.json +6 -0
- package/fixtures/kya-http/README.md +1 -0
- package/fixtures/kya-http/consent-handoff.codes.json +34 -0
- package/fixtures/workbench/a2a-signed-request.v1.json +255 -0
- package/fixtures/workbench/artifact-bindings.v1.json +1003 -0
- package/fixtures/workbench/delegation-management.v1.json +507 -0
- package/fixtures/workbench/didcomm-task-source.v1.json +191 -0
- package/fixtures/workbench/graph-interfaces.v1.json +1887 -0
- package/fixtures/workbench/identity-provisioning.v1.json +643 -0
- package/fixtures/workbench/linear-installation.v1.json +484 -0
- package/fixtures/workbench/management-session.v1.json +716 -0
- package/fixtures/workbench/model-credentials.v1.json +630 -0
- package/fixtures/workbench/source-claim-pooled.v1.json +50 -0
- package/fixtures/workbench/task-grant.v1.json +695 -0
- package/fixtures/workbench/task-status-projection.v1.json +591 -0
- package/fixtures/workbench/workload-enrollment.v1.json +580 -0
- package/package.json +21 -2
- package/src/data/compiled/merged-rules.json +2 -9
- package/src/data/default-rules.json +0 -1
- package/dist/browser-posture-cookie-Dmq9Brf_.d.mts +0 -5
- package/dist/browser-posture-cookie-Dmq9Brf_.d.mts.map +0 -1
- package/dist/browser-posture-cookie-Dmq9Brf_.d.ts +0 -5
- package/dist/browser-posture-cookie-Dmq9Brf_.d.ts.map +0 -1
- package/dist/browser-posture.d.mts.map +0 -1
- package/dist/browser-posture.d.ts.map +0 -1
- package/dist/patterns-CkRVOdtV.js +0 -243
- package/dist/patterns-DzkGy_qk.mjs +0 -173
- package/dist/patterns-DzkGy_qk.mjs.map +0 -1
package/dist/browser-posture.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { _ as number, c as boolean, f as guid, h as literal, i as _enum, s as array, v as object, x as string } from "./schemas-DxY-dk9y.mjs";
|
|
2
|
-
import {
|
|
1
|
+
import { C as unknown, _ as number, b as record, c as boolean, f as guid, h as literal, i as _enum, s as array, v as object, x as string } from "./schemas-DxY-dk9y.mjs";
|
|
2
|
+
import { d as VALIDATION_PATTERNS, n as parseOriginPattern, t as matchAllowedOrigin, u as UUID_PATTERN } from "./posture-origins-Dl7i8j93.mjs";
|
|
3
3
|
import { t as projectVerificationKey } from "./project-verification-key-CgSVX9_m.mjs";
|
|
4
|
-
import { SignJWT,
|
|
4
|
+
import { SignJWT, compactVerify, decodeProtectedHeader, importJWK } from "jose";
|
|
5
5
|
|
|
6
6
|
//#region src/browser-posture-cookie.ts
|
|
7
7
|
/**
|
|
@@ -29,8 +29,41 @@ function postureCookieName(projectId) {
|
|
|
29
29
|
*/
|
|
30
30
|
const POSTURE_TTL_SECONDS = 120;
|
|
31
31
|
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/browser-posture-schema.ts
|
|
34
|
+
const BrowserPostureSchema = object({
|
|
35
|
+
v: literal(1),
|
|
36
|
+
project_id: string().min(1).max(128),
|
|
37
|
+
origin: string().url(),
|
|
38
|
+
session_id: guid(),
|
|
39
|
+
binding: string().regex(/^[a-f0-9]{64}$/),
|
|
40
|
+
verdict: _enum([
|
|
41
|
+
"agent-driven",
|
|
42
|
+
"human",
|
|
43
|
+
"insufficient"
|
|
44
|
+
]),
|
|
45
|
+
score: number().min(0).max(1).nullable(),
|
|
46
|
+
scorer_version: number().int().positive().max(2147483647),
|
|
47
|
+
reasons: array(string().max(160)).max(8),
|
|
48
|
+
automation_disclosed: boolean().default(false),
|
|
49
|
+
automation_corroborated: boolean().default(false),
|
|
50
|
+
detection: object({
|
|
51
|
+
class: _enum(["ai_agent", "bot"]),
|
|
52
|
+
name: string().min(1).max(64).regex(/^[^\p{Cc}]+$/u),
|
|
53
|
+
confidence: number().int().min(0).max(100)
|
|
54
|
+
}).optional(),
|
|
55
|
+
cnf: object({ jkt: string().min(1).max(255) }).optional(),
|
|
56
|
+
iat: number().int().nonnegative(),
|
|
57
|
+
exp: number().int().positive()
|
|
58
|
+
});
|
|
59
|
+
|
|
32
60
|
//#endregion
|
|
33
61
|
//#region src/browser-posture-report.ts
|
|
62
|
+
const POSTURE_VERIFICATION_STATUSES = [
|
|
63
|
+
"verified",
|
|
64
|
+
"absent",
|
|
65
|
+
"rejected"
|
|
66
|
+
];
|
|
34
67
|
/** Audit projection: no token, cookie binding, raw counters, or credential fields. */
|
|
35
68
|
const BrowserPostureReportSchema = object({
|
|
36
69
|
projectId: string().min(1).max(128),
|
|
@@ -47,6 +80,31 @@ const BrowserPostureReportSchema = object({
|
|
|
47
80
|
expiresAt: number().int().positive(),
|
|
48
81
|
source: literal("verified-posture")
|
|
49
82
|
});
|
|
83
|
+
const BROWSER_POSTURE_REJECTION_REASONS = [
|
|
84
|
+
"malformed",
|
|
85
|
+
"unknown-key",
|
|
86
|
+
"bad-signature",
|
|
87
|
+
"invalid-claims",
|
|
88
|
+
"project-mismatch",
|
|
89
|
+
"origin-mismatch",
|
|
90
|
+
"audience-mismatch",
|
|
91
|
+
"expired",
|
|
92
|
+
"not-yet-valid",
|
|
93
|
+
"binding-mismatch",
|
|
94
|
+
"session-missing"
|
|
95
|
+
];
|
|
96
|
+
const BrowserPostureOutcomeSchema = object({
|
|
97
|
+
status: _enum(POSTURE_VERIFICATION_STATUSES),
|
|
98
|
+
reason: _enum(BROWSER_POSTURE_REJECTION_REASONS).optional()
|
|
99
|
+
}).refine((outcome) => outcome.status === "rejected" === (outcome.reason !== void 0), {
|
|
100
|
+
message: "reason is required if and only if status is rejected",
|
|
101
|
+
path: ["reason"]
|
|
102
|
+
});
|
|
103
|
+
const BROWSER_POSTURE_REASON_PATTERN = /^[a-z][a-z-]{0,31}$/;
|
|
104
|
+
const BROWSER_POSTURE_REJECTIONS_MAX_ENTRIES = 50;
|
|
105
|
+
const BROWSER_POSTURE_REJECTION_COUNT_MAX = 1e6;
|
|
106
|
+
const BrowserPostureRejectionsSchema = record(string(), unknown()).transform((counts) => Object.fromEntries(Object.entries(counts).filter((entry) => BROWSER_POSTURE_REASON_PATTERN.test(entry[0]) && typeof entry[1] === "number" && Number.isInteger(entry[1]) && entry[1] > 0).slice(0, 50).map(([reason, count]) => [reason, Math.min(count, BROWSER_POSTURE_REJECTION_COUNT_MAX)])));
|
|
107
|
+
const BrowserPostureReportIngestSchema = BrowserPostureReportSchema.extend({ score: BrowserPostureReportSchema.shape.score.default(null) });
|
|
50
108
|
function browserPostureReport(posture) {
|
|
51
109
|
return {
|
|
52
110
|
projectId: posture.project_id,
|
|
@@ -69,27 +127,43 @@ const UNSIGNED_BROWSER_AGENT = {
|
|
|
69
127
|
verificationMethod: "behavioral"
|
|
70
128
|
};
|
|
71
129
|
const behavioralConfidence = (score) => Math.min(85, Math.max(50, Math.round((score ?? .5) * 100)));
|
|
130
|
+
function postureUpgrade(posture) {
|
|
131
|
+
const { detection, reasons } = posture;
|
|
132
|
+
const verificationMethod = "behavioral";
|
|
133
|
+
if (detection) return {
|
|
134
|
+
detectionClass: detection.class,
|
|
135
|
+
isAgent: true,
|
|
136
|
+
agentName: detection.name,
|
|
137
|
+
confidence: detection.confidence,
|
|
138
|
+
verificationMethod,
|
|
139
|
+
reasons
|
|
140
|
+
};
|
|
141
|
+
if (posture.automation_disclosed) return {
|
|
142
|
+
detectionClass: "bot",
|
|
143
|
+
isAgent: true,
|
|
144
|
+
agentName: "Automation Tools",
|
|
145
|
+
confidence: 80,
|
|
146
|
+
verificationMethod,
|
|
147
|
+
reasons
|
|
148
|
+
};
|
|
149
|
+
if (posture.verdict === "agent-driven") return {
|
|
150
|
+
detectionClass: UNSIGNED_BROWSER_AGENT.detectionClass,
|
|
151
|
+
isAgent: true,
|
|
152
|
+
agentName: UNSIGNED_BROWSER_AGENT.agentType,
|
|
153
|
+
confidence: behavioralConfidence(posture.score),
|
|
154
|
+
verificationMethod,
|
|
155
|
+
reasons
|
|
156
|
+
};
|
|
157
|
+
if (posture.automation_corroborated) return {
|
|
158
|
+
detectionClass: "incomplete_data",
|
|
159
|
+
isAgent: false,
|
|
160
|
+
confidence: 40,
|
|
161
|
+
verificationMethod,
|
|
162
|
+
reasons
|
|
163
|
+
};
|
|
164
|
+
}
|
|
72
165
|
const POSTURE_ISSUER = "checkpoint:browser-posture:v1";
|
|
73
166
|
const POSTURE_TYPE = "checkpoint-posture+jwt";
|
|
74
|
-
const BrowserPostureSchema = object({
|
|
75
|
-
v: literal(1),
|
|
76
|
-
project_id: string().min(1).max(128),
|
|
77
|
-
origin: string().url(),
|
|
78
|
-
session_id: guid(),
|
|
79
|
-
binding: string().regex(/^[a-f0-9]{64}$/),
|
|
80
|
-
verdict: _enum([
|
|
81
|
-
"agent-driven",
|
|
82
|
-
"human",
|
|
83
|
-
"insufficient"
|
|
84
|
-
]),
|
|
85
|
-
score: number().min(0).max(1).nullable(),
|
|
86
|
-
scorer_version: number().int().positive().max(2147483647),
|
|
87
|
-
reasons: array(string().max(160)).max(8),
|
|
88
|
-
automation_disclosed: boolean().default(false),
|
|
89
|
-
automation_corroborated: boolean().default(false),
|
|
90
|
-
iat: number().int().nonnegative(),
|
|
91
|
-
exp: number().int().positive()
|
|
92
|
-
});
|
|
93
167
|
/** Duplicate cookies are ambiguous, so none is trusted. */
|
|
94
168
|
function readPostureCookie(header, name) {
|
|
95
169
|
const matches = (header ?? "").split(";").map((s) => s.trim()).filter((s) => s.startsWith(`${name}=`));
|
|
@@ -107,7 +181,7 @@ async function postureSessionBinding(sessionId) {
|
|
|
107
181
|
function validOrigin(origin) {
|
|
108
182
|
try {
|
|
109
183
|
const url = new URL(origin);
|
|
110
|
-
return url.protocol === "https:" && url.origin === origin;
|
|
184
|
+
return url.protocol === "https:" && url.origin === origin && /^[^.*][^*]*$/.test(url.hostname);
|
|
111
185
|
} catch {
|
|
112
186
|
return false;
|
|
113
187
|
}
|
|
@@ -122,31 +196,101 @@ async function signBrowserPosture(posture, privateKey, keyId) {
|
|
|
122
196
|
kid: keyId
|
|
123
197
|
}).setIssuer(POSTURE_ISSUER).setAudience(claims.origin).sign(key);
|
|
124
198
|
}
|
|
125
|
-
|
|
126
|
-
|
|
199
|
+
const BASE64URL = /^[A-Za-z0-9_-]+$/;
|
|
200
|
+
const rejected = (reason) => ({
|
|
201
|
+
status: "rejected",
|
|
202
|
+
reason
|
|
203
|
+
});
|
|
204
|
+
const postureOutcomeReport = (outcome) => outcome.status === "verified" ? { status: "verified" } : outcome;
|
|
205
|
+
const verifiedPosture = (outcome) => outcome.status === "verified" ? outcome.posture : void 0;
|
|
206
|
+
async function inspectBrowserPosture(token, config, projectId, browserSessionId, now = Math.floor(Date.now() / 1e3)) {
|
|
207
|
+
if (!token) return { status: "absent" };
|
|
208
|
+
if (!browserSessionId || browserSessionId.length > 255) return rejected("session-missing");
|
|
209
|
+
const parts = token.split(".");
|
|
210
|
+
if (token.length > 3800 || parts.length !== 3 || !parts.every((part) => BASE64URL.test(part)) || parts[0].length % 4 === 1) return rejected("malformed");
|
|
211
|
+
let header;
|
|
127
212
|
try {
|
|
128
|
-
|
|
129
|
-
if (!publicKey) return void 0;
|
|
130
|
-
const key = await importJWK(publicKey, "ES256");
|
|
131
|
-
const { payload, protectedHeader } = await jwtVerify(token, key, {
|
|
132
|
-
algorithms: ["ES256"],
|
|
133
|
-
issuer: POSTURE_ISSUER,
|
|
134
|
-
audience: config.origin,
|
|
135
|
-
typ: POSTURE_TYPE,
|
|
136
|
-
currentDate: /* @__PURE__ */ new Date(now * 1e3)
|
|
137
|
-
});
|
|
138
|
-
if ("crit" in protectedHeader || "b64" in protectedHeader || Array.isArray(payload.aud) && payload.aud.some((audience) => typeof audience !== "string")) return void 0;
|
|
139
|
-
const parsed = BrowserPostureSchema.safeParse(payload);
|
|
140
|
-
if (!parsed.success) return void 0;
|
|
141
|
-
const claims = parsed.data;
|
|
142
|
-
if (claims.project_id !== projectId || claims.origin !== config.origin || claims.iat > now + 5 || claims.exp <= now || claims.exp <= claims.iat || claims.exp - claims.iat > 120 || claims.binding !== await postureSessionBinding(browserSessionId)) return void 0;
|
|
143
|
-
return claims;
|
|
213
|
+
header = decodeProtectedHeader(token);
|
|
144
214
|
} catch {
|
|
145
|
-
return;
|
|
215
|
+
return rejected("malformed");
|
|
146
216
|
}
|
|
217
|
+
if (header.alg !== "ES256" || header.typ !== "checkpoint-posture+jwt" || typeof header.kid !== "string" || "crit" in header || "b64" in header) return rejected("malformed");
|
|
218
|
+
const publicKey = validOrigin(config.origin) && !config.publicKey.d && config.publicKey.kty === "EC" && config.publicKey.crv === "P-256" ? projectVerificationKey(token, config, now) : void 0;
|
|
219
|
+
const key = publicKey && await importJWK(publicKey, "ES256").catch(() => void 0);
|
|
220
|
+
if (!key) return rejected("unknown-key");
|
|
221
|
+
let signed;
|
|
222
|
+
try {
|
|
223
|
+
signed = await compactVerify(token, key, { algorithms: ["ES256"] });
|
|
224
|
+
} catch {
|
|
225
|
+
return rejected("bad-signature");
|
|
226
|
+
}
|
|
227
|
+
let json;
|
|
228
|
+
try {
|
|
229
|
+
json = JSON.parse(new TextDecoder().decode(signed.payload));
|
|
230
|
+
} catch {
|
|
231
|
+
return rejected("malformed");
|
|
232
|
+
}
|
|
233
|
+
const record$1 = record(string(), unknown()).safeParse(json);
|
|
234
|
+
if (!record$1.success) return rejected("invalid-claims");
|
|
235
|
+
const audiences = [record$1.data.aud].flat();
|
|
236
|
+
if (audiences.some((audience) => typeof audience !== "string")) return rejected("malformed");
|
|
237
|
+
const notBefore = record$1.data.nbf;
|
|
238
|
+
const parsed = BrowserPostureSchema.safeParse(record$1.data);
|
|
239
|
+
if (!parsed.success || record$1.data.iss !== "checkpoint:browser-posture:v1" || notBefore !== void 0 && typeof notBefore !== "number" || record$1.data.origin !== parsed.data.origin || !validOrigin(parsed.data.origin)) return rejected("invalid-claims");
|
|
240
|
+
const claims = parsed.data;
|
|
241
|
+
if (claims.project_id !== projectId) return rejected("project-mismatch");
|
|
242
|
+
if (claims.origin !== config.origin && !matchAllowedOrigin(claims.origin, config.origins ?? [])) return rejected("origin-mismatch");
|
|
243
|
+
if (!audiences.includes(claims.origin)) return rejected("audience-mismatch");
|
|
244
|
+
if (claims.exp <= now) return rejected("expired");
|
|
245
|
+
if (claims.iat > now + 5 || notBefore !== void 0 && notBefore > now) return rejected("not-yet-valid");
|
|
246
|
+
if (claims.exp <= claims.iat || claims.exp - claims.iat > 120) return rejected("invalid-claims");
|
|
247
|
+
if (claims.binding !== await postureSessionBinding(browserSessionId)) return rejected("binding-mismatch");
|
|
248
|
+
return {
|
|
249
|
+
status: "verified",
|
|
250
|
+
posture: claims
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
async function verifyBrowserPosture(token, config, projectId, browserSessionId, now = Math.floor(Date.now() / 1e3)) {
|
|
254
|
+
return verifiedPosture(await inspectBrowserPosture(token, config, projectId, browserSessionId, now));
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Request headers a page sends when its posture cookies cannot reach the
|
|
258
|
+
* server: a request to another host (the cookies are host-only) or a browser
|
|
259
|
+
* that blocks cookies. The page reads both values from the beacon's
|
|
260
|
+
* `onReceipt`.
|
|
261
|
+
*/
|
|
262
|
+
const POSTURE_HEADER = "kya-posture";
|
|
263
|
+
const POSTURE_SESSION_HEADER = "kya-posture-session";
|
|
264
|
+
/** The `PostureRequest` of any header store, read through its own lowercase-name getter. */
|
|
265
|
+
function postureRequestFromHeaders(get) {
|
|
266
|
+
const cookie = get("cookie");
|
|
267
|
+
return {
|
|
268
|
+
cookie: Array.isArray(cookie) ? cookie.join("; ") : cookie,
|
|
269
|
+
posture: get(POSTURE_HEADER),
|
|
270
|
+
session: get(POSTURE_SESSION_HEADER)
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* A header, when the request carries a non-empty one, wins over its cookie.
|
|
275
|
+
* A header sent twice, or joined into one comma-separated value, is ambiguous,
|
|
276
|
+
* so neither copy is trusted and the cookie is not consulted either: the page
|
|
277
|
+
* chose the header. Every runtime applies the same rule
|
|
278
|
+
* (`tests/browser-posture/vectors.json` `requests`).
|
|
279
|
+
*/
|
|
280
|
+
function postureRequestValue(header, cookieHeader, cookieName) {
|
|
281
|
+
const values = (Array.isArray(header) ? header : [header]).map((value) => value?.trim()).filter((value) => Boolean(value));
|
|
282
|
+
if (values.length === 0) return readPostureCookie(cookieHeader, cookieName);
|
|
283
|
+
return values.length === 1 && !values[0].includes(",") ? values[0] : void 0;
|
|
284
|
+
}
|
|
285
|
+
/** Read and verify posture from the `KYA-Posture` headers, falling back to the cookies. */
|
|
286
|
+
async function postureOutcomeFromRequest(request, config, projectId, now) {
|
|
287
|
+
return inspectBrowserPosture(postureRequestValue(request.posture, request.cookie, postureCookieName(projectId)), config, projectId, postureRequestValue(request.session, request.cookie, config.sessionCookieName ?? "_as_beacon_session"), now);
|
|
288
|
+
}
|
|
289
|
+
async function postureFromRequest(request, config, projectId, now) {
|
|
290
|
+
return verifiedPosture(await postureOutcomeFromRequest(request, config, projectId, now));
|
|
147
291
|
}
|
|
148
292
|
async function postureFromCookies(header, config, projectId) {
|
|
149
|
-
return
|
|
293
|
+
return postureFromRequest({ cookie: header }, config, projectId);
|
|
150
294
|
}
|
|
151
295
|
/** Exact paths or an explicit subtree ending in /*. Longest designation wins. */
|
|
152
296
|
function postureRequiredScopes(config, path) {
|
|
@@ -159,6 +303,12 @@ function postureRequiredScopes(config, path) {
|
|
|
159
303
|
function validateBrowserPostureConfig(config, projectId) {
|
|
160
304
|
if (!projectId || !VALIDATION_PATTERNS.UUID.test(projectId) || projectId !== projectId.toLowerCase()) throw new Error("Browser posture requires projectId to be the lowercase project UUID (the friendly id is not accepted)");
|
|
161
305
|
if (!validOrigin(config.origin) || !config.keyId || config.publicKey.kty !== "EC" || config.publicKey.crv !== "P-256" || !config.publicKey.x || !config.publicKey.y || config.publicKey.d) throw new Error("Browser posture requires projectId, an exact HTTPS origin, and a public ES256 key");
|
|
306
|
+
const origins = config.origins ?? [];
|
|
307
|
+
if (origins.length > 20) throw new Error(`Browser posture accepts at most ${20} additional origins`);
|
|
308
|
+
for (const entry of origins) {
|
|
309
|
+
const parsed = parseOriginPattern(entry);
|
|
310
|
+
if (!parsed.ok) throw new Error(`Invalid browser posture origin "${entry}": ${parsed.error}`);
|
|
311
|
+
}
|
|
162
312
|
const paths = /* @__PURE__ */ new Set();
|
|
163
313
|
for (const route of config.protectedRoutes ?? []) {
|
|
164
314
|
if (!/^\/(?:[^?#*\\]*)(?:\/\*)?$/.test(route.path) && route.path !== "/*") throw new Error("Invalid integrity-protected path");
|
|
@@ -172,5 +322,5 @@ function validateBrowserPostureConfig(config, projectId) {
|
|
|
172
322
|
}
|
|
173
323
|
|
|
174
324
|
//#endregion
|
|
175
|
-
export { BrowserPostureReportSchema, BrowserPostureSchema, POSTURE_ISSUER, POSTURE_TTL_SECONDS, POSTURE_TYPE, UNSIGNED_BROWSER_AGENT, behavioralConfidence, browserPostureReport, postureCookieName, postureFromCookies, postureRequiredScopes, postureSessionBinding, readPostureCookie, signBrowserPosture, validateBrowserPostureConfig, verifyBrowserPosture };
|
|
325
|
+
export { BROWSER_POSTURE_REJECTION_REASONS, BrowserPostureOutcomeSchema, BrowserPostureReportIngestSchema, BrowserPostureReportSchema, BrowserPostureSchema, POSTURE_HEADER, POSTURE_ISSUER, POSTURE_SESSION_HEADER, POSTURE_TTL_SECONDS, POSTURE_TYPE, POSTURE_VERIFICATION_STATUSES, UNSIGNED_BROWSER_AGENT, behavioralConfidence, browserPostureReport, inspectBrowserPosture, postureCookieName, postureFromCookies, postureFromRequest, postureOutcomeFromRequest, postureOutcomeReport, postureRequestFromHeaders, postureRequiredScopes, postureSessionBinding, postureUpgrade, readPostureCookie, signBrowserPosture, validateBrowserPostureConfig, verifyBrowserPosture };
|
|
176
326
|
//# sourceMappingURL=browser-posture.mjs.map
|