@kya-os/checkpoint-shared 1.9.0 → 1.11.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 +113 -0
- package/README.md +1 -1
- package/dist/base64url-BbVG8f-v.js +65 -0
- package/dist/base64url-D2MvsR20.mjs +49 -0
- package/dist/base64url-D2MvsR20.mjs.map +1 -0
- package/dist/beacon-forward-secret/index.d.mts +4 -0
- package/dist/beacon-forward-secret/index.d.mts.map +1 -0
- package/dist/beacon-forward-secret/index.d.ts +4 -0
- package/dist/beacon-forward-secret/index.d.ts.map +1 -0
- package/dist/beacon-forward-secret/index.js +15 -0
- package/dist/beacon-forward-secret/index.mjs +15 -0
- package/dist/beacon-forward-secret/index.mjs.map +1 -0
- package/dist/beacon-types/index.d.mts +53 -1
- package/dist/beacon-types/index.d.mts.map +1 -1
- package/dist/beacon-types/index.d.ts +53 -1
- package/dist/beacon-types/index.d.ts.map +1 -1
- package/dist/beacon-types/index.js +86 -1
- package/dist/beacon-types/index.mjs +77 -2
- package/dist/beacon-types/index.mjs.map +1 -1
- package/dist/{browser-posture-5fPrsxx7.d.mts → browser-posture-WPk0kl9u.d.mts} +18 -1
- package/dist/browser-posture-WPk0kl9u.d.mts.map +1 -0
- package/dist/{browser-posture-CCR1kh5e.d.ts → browser-posture-_y6BcdXw.d.ts} +18 -1
- package/dist/browser-posture-_y6BcdXw.d.ts.map +1 -0
- package/dist/browser-posture-cookie.mjs.map +1 -1
- package/dist/browser-posture-proof-verifier.js +136 -5
- package/dist/browser-posture-proof-verifier.mjs +134 -2
- package/dist/browser-posture-proof-verifier.mjs.map +1 -0
- package/dist/browser-posture-proof.d.mts +1 -1
- package/dist/browser-posture-proof.d.ts +1 -1
- package/dist/browser-posture-proof.js +1 -1
- package/dist/browser-posture-proof.mjs +1 -1
- package/dist/browser-posture-report.d.mts +17 -0
- package/dist/browser-posture-report.d.mts.map +1 -1
- package/dist/browser-posture-report.d.ts +17 -0
- package/dist/browser-posture-report.d.ts.map +1 -1
- package/dist/browser-posture.d.mts +1 -1
- package/dist/browser-posture.d.ts +1 -1
- package/dist/browser-posture.js +53 -5
- package/dist/browser-posture.mjs +53 -5
- package/dist/browser-posture.mjs.map +1 -1
- package/dist/browser.d.mts +10 -0
- package/dist/browser.d.mts.map +1 -1
- package/dist/browser.d.ts +10 -0
- 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/canonical-signer/index.d.mts.map +1 -1
- package/dist/canonical-signer/index.d.ts.map +1 -1
- package/dist/canonical-signer/index.js +0 -4
- package/dist/canonical-signer/index.mjs +0 -4
- package/dist/canonical-signer/index.mjs.map +1 -1
- package/dist/{client-ip-B7w-uHfS.d.ts → client-ip-8KneiMK0.d.mts} +12 -2
- package/dist/{client-ip-B7w-uHfS.d.mts.map → client-ip-8KneiMK0.d.mts.map} +1 -1
- package/dist/{client-ip-B7w-uHfS.d.mts → client-ip-8KneiMK0.d.ts} +12 -2
- package/dist/{client-ip-B7w-uHfS.d.ts.map → client-ip-8KneiMK0.d.ts.map} +1 -1
- package/dist/{client-ip-B8wFzJ5f.js → client-ip-BEmLC4I4.js} +71 -0
- package/dist/{client-ip-DIJyr6px.mjs → client-ip-DlHx7GGh.mjs} +61 -2
- package/dist/client-ip-DlHx7GGh.mjs.map +1 -0
- package/dist/client-ip.d.mts +2 -2
- package/dist/client-ip.d.ts +2 -2
- package/dist/client-ip.js +3 -1
- package/dist/client-ip.mjs +2 -2
- package/dist/deploy/index.d.mts +1 -0
- package/dist/deploy/index.d.mts.map +1 -1
- package/dist/deploy/index.d.ts +1 -0
- package/dist/deploy/index.d.ts.map +1 -1
- package/dist/deploy/index.js +14 -2
- package/dist/deploy/index.mjs +14 -2
- package/dist/deploy/index.mjs.map +1 -1
- package/dist/{detection-reason-mapping-CQexNvR7.d.ts → detection-reason-mapping-BemDaDED.d.mts} +5 -2
- package/dist/detection-reason-mapping-BemDaDED.d.mts.map +1 -0
- package/dist/{detection-reason-mapping-CQexNvR7.d.mts → detection-reason-mapping-BemDaDED.d.ts} +5 -2
- package/dist/detection-reason-mapping-BemDaDED.d.ts.map +1 -0
- package/dist/{detection-reason-mapping-B9RSkOs8.js → detection-reason-mapping-BxYaQ8kb.js} +33 -8
- package/dist/{detection-reason-mapping-BGymWIPl.mjs → detection-reason-mapping-j-7bXsVb.mjs} +29 -10
- package/dist/detection-reason-mapping-j-7bXsVb.mjs.map +1 -0
- package/dist/errors/index.d.mts +4 -0
- package/dist/errors/index.d.mts.map +1 -1
- package/dist/errors/index.d.ts +4 -0
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +24 -8
- package/dist/errors/index.mjs +24 -8
- package/dist/errors/index.mjs.map +1 -1
- package/dist/{fetcher-D2vjr7jB.d.mts → fetcher-CTKz07jg.d.mts} +13 -3
- package/dist/fetcher-CTKz07jg.d.mts.map +1 -0
- package/dist/{fetcher-C8qvwdnA.d.ts → fetcher-DCr920hx.d.ts} +13 -3
- package/dist/fetcher-DCr920hx.d.ts.map +1 -0
- package/dist/gateway-client-ip.js +1 -1
- package/dist/gateway-client-ip.mjs +1 -1
- package/dist/host-adapter/index.d.mts +1 -1
- package/dist/host-adapter/index.d.ts +1 -1
- package/dist/identity-cookie/index.d.mts +14 -0
- package/dist/identity-cookie/index.d.mts.map +1 -0
- package/dist/identity-cookie/index.d.ts +14 -0
- package/dist/identity-cookie/index.d.ts.map +1 -0
- package/dist/identity-cookie/index.js +45 -0
- package/dist/identity-cookie/index.mjs +43 -0
- package/dist/identity-cookie/index.mjs.map +1 -0
- package/dist/{index-DnFsmr_o.d.ts → index-Cdv_FH0H.d.ts} +2 -2
- package/dist/{index-DnFsmr_o.d.ts.map → index-Cdv_FH0H.d.ts.map} +1 -1
- package/dist/{index-rvw5Bz-r.d.mts → index-DL_dmQBY.d.mts} +2 -2
- package/dist/{index-rvw5Bz-r.d.mts.map → index-DL_dmQBY.d.mts.map} +1 -1
- package/dist/index.d.mts +641 -169
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +641 -169
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +819 -210
- package/dist/index.mjs +765 -200
- package/dist/index.mjs.map +1 -1
- package/dist/kya-http.d.mts +2 -2
- package/dist/kya-http.d.ts +2 -2
- package/dist/kya-http.js +7 -2
- package/dist/kya-http.mjs +2 -2
- package/dist/mcpi/dashboard-config/index.mjs.map +1 -1
- package/dist/patterns-CdTh7LU2.d.mts +35 -0
- package/dist/patterns-CdTh7LU2.d.mts.map +1 -0
- package/dist/patterns-CdTh7LU2.d.ts +35 -0
- package/dist/patterns-CdTh7LU2.d.ts.map +1 -0
- package/dist/{patterns-CiMpbdAF.js → patterns-CnNxRnaK.js} +3 -130
- package/dist/{patterns-D4OAsNQY.mjs → patterns-CpRk9R3M.mjs} +5 -96
- package/dist/patterns-CpRk9R3M.mjs.map +1 -0
- package/dist/patterns.d.mts +2 -2
- package/dist/patterns.d.ts +2 -2
- package/dist/patterns.js +1 -7
- package/dist/patterns.mjs +2 -2
- package/dist/policy/fetcher.d.mts +2 -2
- package/dist/policy/fetcher.d.ts +2 -2
- package/dist/policy/fetcher.js +100 -8
- package/dist/policy/fetcher.mjs +99 -9
- package/dist/policy/fetcher.mjs.map +1 -1
- package/dist/policy/schemas.d.mts +1 -1
- package/dist/policy/schemas.d.ts +1 -1
- package/dist/proxy-assertion-mapping-BVwXVSMZ.mjs +81 -0
- package/dist/proxy-assertion-mapping-BVwXVSMZ.mjs.map +1 -0
- package/dist/proxy-assertion-mapping-BxhENrcY.d.mts +70 -0
- package/dist/proxy-assertion-mapping-BxhENrcY.d.mts.map +1 -0
- package/dist/proxy-assertion-mapping-D64AyZfG.js +85 -0
- package/dist/proxy-assertion-mapping-DhAynFqG.d.ts +70 -0
- package/dist/proxy-assertion-mapping-DhAynFqG.d.ts.map +1 -0
- package/dist/proxy-assertions.d.mts +2 -0
- package/dist/proxy-assertions.d.ts +2 -0
- package/dist/proxy-assertions.js +4 -0
- package/dist/proxy-assertions.mjs +3 -0
- package/dist/reason-codes.d.mts +2 -2
- package/dist/reason-codes.d.ts +2 -2
- package/dist/reason-codes.js +3 -2
- package/dist/reason-codes.mjs +2 -2
- package/dist/{registered-sid-D6KCaT1E.d.ts → registered-sid-BgDhdj2l.d.mts} +24 -2
- package/dist/registered-sid-BgDhdj2l.d.mts.map +1 -0
- package/dist/{registered-sid-D6KCaT1E.d.mts → registered-sid-BgDhdj2l.d.ts} +24 -2
- package/dist/registered-sid-BgDhdj2l.d.ts.map +1 -0
- package/dist/{registered-sid-DVGTSH0L.js → registered-sid-DG1tSSvl.js} +162 -4
- package/dist/{registered-sid-26hNxp6t.mjs → registered-sid-D__xiDPu.mjs} +134 -6
- package/dist/registered-sid-D__xiDPu.mjs.map +1 -0
- package/dist/{schemas-m-GqyfyO.d.mts → schemas-BhC88D1-.d.mts} +5 -5
- package/dist/{schemas-m-GqyfyO.d.mts.map → schemas-BhC88D1-.d.mts.map} +1 -1
- package/dist/{schemas-CGKHzcMV.d.ts → schemas-DZa1ouGs.d.ts} +5 -5
- package/dist/{schemas-CGKHzcMV.d.ts.map → schemas-DZa1ouGs.d.ts.map} +1 -1
- package/dist/signals/index.d.mts.map +1 -1
- package/dist/signals/index.d.ts.map +1 -1
- package/dist/signals/index.js +4 -0
- package/dist/signals/index.mjs +4 -0
- package/dist/signals/index.mjs.map +1 -1
- package/dist/timezone-country-B6PkDyNP.d.mts +15 -0
- package/dist/timezone-country-B6PkDyNP.d.mts.map +1 -0
- package/dist/timezone-country-B6PkDyNP.d.ts +15 -0
- package/dist/timezone-country-B6PkDyNP.d.ts.map +1 -0
- package/dist/timezone-country-CROxU2Tl.js +505 -0
- package/dist/timezone-country-CrrnkOdy.mjs +489 -0
- package/dist/timezone-country-CrrnkOdy.mjs.map +1 -0
- package/dist/timezone-country.d.mts +2 -0
- package/dist/timezone-country.d.ts +2 -0
- package/dist/timezone-country.js +6 -0
- package/dist/timezone-country.mjs +3 -0
- package/dist/tool-protection/index.mjs.map +1 -1
- package/fixtures/detection/cloudflare-alias-parity.json +383 -0
- package/fixtures/detection/reason-codes.json +3 -1
- package/fixtures/detection/signal-exposure-example.json +1 -1
- package/fixtures/iana-tzdata/backward +375 -0
- package/fixtures/iana-tzdata/renamed-zones.json +21 -0
- package/fixtures/iana-tzdata/version +1 -0
- package/fixtures/iana-tzdata/zone.tab +448 -0
- package/fixtures/workbench/management-session.v1.json +20 -0
- package/fixtures/workbench/model-credentials.v1.json +8 -0
- package/fixtures/workbench/task-grant.v1.json +37 -0
- package/package.json +25 -3
- package/src/data/compiled/merged-rules.json +9 -7
- package/dist/browser-posture-5fPrsxx7.d.mts.map +0 -1
- package/dist/browser-posture-CCR1kh5e.d.ts.map +0 -1
- package/dist/browser-posture-proof-verifier-DvsOmFrM.js +0 -202
- package/dist/browser-posture-proof-verifier-I0HP2Ics.mjs +0 -180
- package/dist/browser-posture-proof-verifier-I0HP2Ics.mjs.map +0 -1
- package/dist/client-ip-DIJyr6px.mjs.map +0 -1
- package/dist/detection-reason-mapping-BGymWIPl.mjs.map +0 -1
- package/dist/detection-reason-mapping-CQexNvR7.d.mts.map +0 -1
- package/dist/detection-reason-mapping-CQexNvR7.d.ts.map +0 -1
- package/dist/fetcher-C8qvwdnA.d.ts.map +0 -1
- package/dist/fetcher-D2vjr7jB.d.mts.map +0 -1
- package/dist/patterns-Bp40cwh2.d.mts +0 -110
- package/dist/patterns-Bp40cwh2.d.mts.map +0 -1
- package/dist/patterns-Bp40cwh2.d.ts +0 -110
- package/dist/patterns-Bp40cwh2.d.ts.map +0 -1
- package/dist/patterns-D4OAsNQY.mjs.map +0 -1
- package/dist/registered-sid-26hNxp6t.mjs.map +0 -1
- package/dist/registered-sid-D6KCaT1E.d.mts.map +0 -1
- package/dist/registered-sid-D6KCaT1E.d.ts.map +0 -1
|
@@ -1,7 +1,138 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const
|
|
2
|
+
const require_base64url = require('./base64url-BbVG8f-v.js');
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
//#region src/browser-posture-proof-verifier.ts
|
|
5
|
+
const POSTURE_PROOF_TYPE = "dpop+jwt";
|
|
6
|
+
const DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS = 60;
|
|
7
|
+
const MALFORMED = {
|
|
8
|
+
verified: false,
|
|
9
|
+
reason: "malformed"
|
|
10
|
+
};
|
|
11
|
+
const BAD_SIGNATURE = {
|
|
12
|
+
verified: false,
|
|
13
|
+
reason: "bad-signature"
|
|
14
|
+
};
|
|
15
|
+
const KEY_ALGORITHM = {
|
|
16
|
+
name: "ECDSA",
|
|
17
|
+
namedCurve: "P-256"
|
|
18
|
+
};
|
|
19
|
+
const SIGNATURE_ALGORITHM = {
|
|
20
|
+
name: "ECDSA",
|
|
21
|
+
hash: "SHA-256"
|
|
22
|
+
};
|
|
23
|
+
const TAB_OR_NEWLINE = /[\t\n\r]/g;
|
|
24
|
+
const encoder = new TextEncoder();
|
|
25
|
+
function isNonEmptyString(value) {
|
|
26
|
+
return typeof value === "string" && value !== "";
|
|
27
|
+
}
|
|
28
|
+
async function thumbprint(x, y) {
|
|
29
|
+
if (!isNonEmptyString(x) || !isNonEmptyString(y)) throw new TypeError("incomplete EC key");
|
|
30
|
+
const digest = await crypto.subtle.digest("SHA-256", encoder.encode(JSON.stringify({
|
|
31
|
+
crv: "P-256",
|
|
32
|
+
kty: "EC",
|
|
33
|
+
x,
|
|
34
|
+
y
|
|
35
|
+
})));
|
|
36
|
+
return require_base64url.bytesToBase64Url(new Uint8Array(digest));
|
|
37
|
+
}
|
|
38
|
+
function importKey({ alg: _alg, use: _use, ...jwk }) {
|
|
39
|
+
return crypto.subtle.importKey("jwk", jwk, KEY_ALGORITHM, jwk.ext ?? false, jwk.key_ops ?? ["verify"]);
|
|
40
|
+
}
|
|
41
|
+
function boundedText(value, maxCodePoints) {
|
|
42
|
+
return typeof value === "string" && value !== "" && Array.from(value).length <= maxCodePoints;
|
|
43
|
+
}
|
|
44
|
+
function parsableUrl(value) {
|
|
45
|
+
try {
|
|
46
|
+
return Boolean(new URL(value));
|
|
47
|
+
} catch {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function criticalParametersAccepted({ crit, b64 }) {
|
|
52
|
+
if (crit === void 0) return true;
|
|
53
|
+
return Array.isArray(crit) && crit.length > 0 && crit.every((name) => name === "b64") && b64 === true;
|
|
54
|
+
}
|
|
55
|
+
function currentClaimSet(payload, now) {
|
|
56
|
+
if (typeof payload !== "object" || payload === null || Array.isArray(payload)) return void 0;
|
|
57
|
+
const { iat, nbf, exp } = payload;
|
|
58
|
+
if (iat !== void 0 && typeof iat !== "number") return void 0;
|
|
59
|
+
if (nbf !== void 0 && (typeof nbf !== "number" || nbf > now)) return void 0;
|
|
60
|
+
if (exp !== void 0 && (typeof exp !== "number" || exp <= now)) return void 0;
|
|
61
|
+
return payload;
|
|
62
|
+
}
|
|
63
|
+
function proofClaims(claims) {
|
|
64
|
+
const { jti, htm, htu, iat } = claims;
|
|
65
|
+
if (!boundedText(jti, 255) || !boundedText(htm, 16)) return void 0;
|
|
66
|
+
if (typeof iat !== "number" || !Number.isSafeInteger(iat) || iat < 0) return void 0;
|
|
67
|
+
if (typeof htu !== "string" || !parsableUrl(htu.trim())) return void 0;
|
|
68
|
+
return {
|
|
69
|
+
jti,
|
|
70
|
+
htm,
|
|
71
|
+
htu: htu.trim().replace(TAB_OR_NEWLINE, ""),
|
|
72
|
+
iat
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
async function signedClaims(segments, header, key, now) {
|
|
76
|
+
if (segments.length !== 3 || segments.some((segment) => segment.includes("=")) || !criticalParametersAccepted(header)) return;
|
|
77
|
+
try {
|
|
78
|
+
return await crypto.subtle.verify(SIGNATURE_ALGORITHM, key, require_base64url.base64UrlToBytes(segments[2]), encoder.encode(`${segments[0]}.${segments[1]}`)) ? currentClaimSet(JSON.parse(require_base64url.base64UrlToString(segments[1])), Math.floor(now)) : void 0;
|
|
79
|
+
} catch {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async function verifyBrowserPostureProofKey(proofJws, request, expectedJkt, now = Math.floor(Date.now() / 1e3), maxAgeSeconds = 60) {
|
|
84
|
+
if (typeof proofJws !== "string" || proofJws === "" || proofJws.length > 2e3) return MALFORMED;
|
|
85
|
+
const segments = proofJws.split(".");
|
|
86
|
+
let header;
|
|
87
|
+
let jkt;
|
|
88
|
+
let key;
|
|
89
|
+
try {
|
|
90
|
+
header = JSON.parse(require_base64url.base64UrlToString(segments[0]));
|
|
91
|
+
if (header.typ !== "dpop+jwt" || header.alg !== "ES256" || !header.jwk || header.jwk.kty !== "EC" || header.jwk.crv !== "P-256" || header.jwk.d) return MALFORMED;
|
|
92
|
+
jkt = await thumbprint(header.jwk.x, header.jwk.y);
|
|
93
|
+
if (expectedJkt !== void 0 && jkt !== expectedJkt) return {
|
|
94
|
+
verified: false,
|
|
95
|
+
reason: "jkt-mismatch"
|
|
96
|
+
};
|
|
97
|
+
key = await importKey(header.jwk);
|
|
98
|
+
} catch {
|
|
99
|
+
return MALFORMED;
|
|
100
|
+
}
|
|
101
|
+
const payload = await signedClaims(segments, header, key, now);
|
|
102
|
+
if (!payload) return BAD_SIGNATURE;
|
|
103
|
+
const claims = proofClaims(payload);
|
|
104
|
+
if (!claims) return {
|
|
105
|
+
verified: false,
|
|
106
|
+
reason: "invalid-claims"
|
|
107
|
+
};
|
|
108
|
+
const acceptedUrls = typeof request.url === "string" ? [request.url] : request.url;
|
|
109
|
+
if (claims.htm.toUpperCase() !== request.method.toUpperCase() || !acceptedUrls.includes(claims.htu)) return {
|
|
110
|
+
verified: false,
|
|
111
|
+
reason: "htu-mismatch"
|
|
112
|
+
};
|
|
113
|
+
if (Math.abs(now - claims.iat) > maxAgeSeconds) return {
|
|
114
|
+
verified: false,
|
|
115
|
+
reason: "stale-iat"
|
|
116
|
+
};
|
|
117
|
+
return {
|
|
118
|
+
verified: true,
|
|
119
|
+
claims,
|
|
120
|
+
jkt
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
async function browserPostureKeyThumbprint(jwk) {
|
|
124
|
+
if (typeof jwk !== "object" || jwk === null) return void 0;
|
|
125
|
+
const { kty, crv, x, y, d } = jwk;
|
|
126
|
+
if (kty !== "EC" || crv !== "P-256" || typeof x !== "string" || typeof y !== "string" || d) return;
|
|
127
|
+
try {
|
|
128
|
+
return await thumbprint(x, y);
|
|
129
|
+
} catch {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
//#endregion
|
|
135
|
+
exports.DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS = DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS;
|
|
136
|
+
exports.POSTURE_PROOF_TYPE = POSTURE_PROOF_TYPE;
|
|
137
|
+
exports.browserPostureKeyThumbprint = browserPostureKeyThumbprint;
|
|
138
|
+
exports.verifyBrowserPostureProofKey = verifyBrowserPostureProofKey;
|
|
@@ -1,3 +1,135 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as base64UrlToString, r as bytesToBase64Url, t as base64UrlToBytes } from "./base64url-D2MvsR20.mjs";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
//#region src/browser-posture-proof-verifier.ts
|
|
4
|
+
const POSTURE_PROOF_TYPE = "dpop+jwt";
|
|
5
|
+
const DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS = 60;
|
|
6
|
+
const MALFORMED = {
|
|
7
|
+
verified: false,
|
|
8
|
+
reason: "malformed"
|
|
9
|
+
};
|
|
10
|
+
const BAD_SIGNATURE = {
|
|
11
|
+
verified: false,
|
|
12
|
+
reason: "bad-signature"
|
|
13
|
+
};
|
|
14
|
+
const KEY_ALGORITHM = {
|
|
15
|
+
name: "ECDSA",
|
|
16
|
+
namedCurve: "P-256"
|
|
17
|
+
};
|
|
18
|
+
const SIGNATURE_ALGORITHM = {
|
|
19
|
+
name: "ECDSA",
|
|
20
|
+
hash: "SHA-256"
|
|
21
|
+
};
|
|
22
|
+
const TAB_OR_NEWLINE = /[\t\n\r]/g;
|
|
23
|
+
const encoder = new TextEncoder();
|
|
24
|
+
function isNonEmptyString(value) {
|
|
25
|
+
return typeof value === "string" && value !== "";
|
|
26
|
+
}
|
|
27
|
+
async function thumbprint(x, y) {
|
|
28
|
+
if (!isNonEmptyString(x) || !isNonEmptyString(y)) throw new TypeError("incomplete EC key");
|
|
29
|
+
const digest = await crypto.subtle.digest("SHA-256", encoder.encode(JSON.stringify({
|
|
30
|
+
crv: "P-256",
|
|
31
|
+
kty: "EC",
|
|
32
|
+
x,
|
|
33
|
+
y
|
|
34
|
+
})));
|
|
35
|
+
return bytesToBase64Url(new Uint8Array(digest));
|
|
36
|
+
}
|
|
37
|
+
function importKey({ alg: _alg, use: _use, ...jwk }) {
|
|
38
|
+
return crypto.subtle.importKey("jwk", jwk, KEY_ALGORITHM, jwk.ext ?? false, jwk.key_ops ?? ["verify"]);
|
|
39
|
+
}
|
|
40
|
+
function boundedText(value, maxCodePoints) {
|
|
41
|
+
return typeof value === "string" && value !== "" && Array.from(value).length <= maxCodePoints;
|
|
42
|
+
}
|
|
43
|
+
function parsableUrl(value) {
|
|
44
|
+
try {
|
|
45
|
+
return Boolean(new URL(value));
|
|
46
|
+
} catch {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function criticalParametersAccepted({ crit, b64 }) {
|
|
51
|
+
if (crit === void 0) return true;
|
|
52
|
+
return Array.isArray(crit) && crit.length > 0 && crit.every((name) => name === "b64") && b64 === true;
|
|
53
|
+
}
|
|
54
|
+
function currentClaimSet(payload, now) {
|
|
55
|
+
if (typeof payload !== "object" || payload === null || Array.isArray(payload)) return void 0;
|
|
56
|
+
const { iat, nbf, exp } = payload;
|
|
57
|
+
if (iat !== void 0 && typeof iat !== "number") return void 0;
|
|
58
|
+
if (nbf !== void 0 && (typeof nbf !== "number" || nbf > now)) return void 0;
|
|
59
|
+
if (exp !== void 0 && (typeof exp !== "number" || exp <= now)) return void 0;
|
|
60
|
+
return payload;
|
|
61
|
+
}
|
|
62
|
+
function proofClaims(claims) {
|
|
63
|
+
const { jti, htm, htu, iat } = claims;
|
|
64
|
+
if (!boundedText(jti, 255) || !boundedText(htm, 16)) return void 0;
|
|
65
|
+
if (typeof iat !== "number" || !Number.isSafeInteger(iat) || iat < 0) return void 0;
|
|
66
|
+
if (typeof htu !== "string" || !parsableUrl(htu.trim())) return void 0;
|
|
67
|
+
return {
|
|
68
|
+
jti,
|
|
69
|
+
htm,
|
|
70
|
+
htu: htu.trim().replace(TAB_OR_NEWLINE, ""),
|
|
71
|
+
iat
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
async function signedClaims(segments, header, key, now) {
|
|
75
|
+
if (segments.length !== 3 || segments.some((segment) => segment.includes("=")) || !criticalParametersAccepted(header)) return;
|
|
76
|
+
try {
|
|
77
|
+
return await crypto.subtle.verify(SIGNATURE_ALGORITHM, key, base64UrlToBytes(segments[2]), encoder.encode(`${segments[0]}.${segments[1]}`)) ? currentClaimSet(JSON.parse(base64UrlToString(segments[1])), Math.floor(now)) : void 0;
|
|
78
|
+
} catch {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async function verifyBrowserPostureProofKey(proofJws, request, expectedJkt, now = Math.floor(Date.now() / 1e3), maxAgeSeconds = 60) {
|
|
83
|
+
if (typeof proofJws !== "string" || proofJws === "" || proofJws.length > 2e3) return MALFORMED;
|
|
84
|
+
const segments = proofJws.split(".");
|
|
85
|
+
let header;
|
|
86
|
+
let jkt;
|
|
87
|
+
let key;
|
|
88
|
+
try {
|
|
89
|
+
header = JSON.parse(base64UrlToString(segments[0]));
|
|
90
|
+
if (header.typ !== "dpop+jwt" || header.alg !== "ES256" || !header.jwk || header.jwk.kty !== "EC" || header.jwk.crv !== "P-256" || header.jwk.d) return MALFORMED;
|
|
91
|
+
jkt = await thumbprint(header.jwk.x, header.jwk.y);
|
|
92
|
+
if (expectedJkt !== void 0 && jkt !== expectedJkt) return {
|
|
93
|
+
verified: false,
|
|
94
|
+
reason: "jkt-mismatch"
|
|
95
|
+
};
|
|
96
|
+
key = await importKey(header.jwk);
|
|
97
|
+
} catch {
|
|
98
|
+
return MALFORMED;
|
|
99
|
+
}
|
|
100
|
+
const payload = await signedClaims(segments, header, key, now);
|
|
101
|
+
if (!payload) return BAD_SIGNATURE;
|
|
102
|
+
const claims = proofClaims(payload);
|
|
103
|
+
if (!claims) return {
|
|
104
|
+
verified: false,
|
|
105
|
+
reason: "invalid-claims"
|
|
106
|
+
};
|
|
107
|
+
const acceptedUrls = typeof request.url === "string" ? [request.url] : request.url;
|
|
108
|
+
if (claims.htm.toUpperCase() !== request.method.toUpperCase() || !acceptedUrls.includes(claims.htu)) return {
|
|
109
|
+
verified: false,
|
|
110
|
+
reason: "htu-mismatch"
|
|
111
|
+
};
|
|
112
|
+
if (Math.abs(now - claims.iat) > maxAgeSeconds) return {
|
|
113
|
+
verified: false,
|
|
114
|
+
reason: "stale-iat"
|
|
115
|
+
};
|
|
116
|
+
return {
|
|
117
|
+
verified: true,
|
|
118
|
+
claims,
|
|
119
|
+
jkt
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
async function browserPostureKeyThumbprint(jwk) {
|
|
123
|
+
if (typeof jwk !== "object" || jwk === null) return void 0;
|
|
124
|
+
const { kty, crv, x, y, d } = jwk;
|
|
125
|
+
if (kty !== "EC" || crv !== "P-256" || typeof x !== "string" || typeof y !== "string" || d) return;
|
|
126
|
+
try {
|
|
127
|
+
return await thumbprint(x, y);
|
|
128
|
+
} catch {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
//#endregion
|
|
134
|
+
export { DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS, POSTURE_PROOF_TYPE, browserPostureKeyThumbprint, verifyBrowserPostureProofKey };
|
|
135
|
+
//# sourceMappingURL=browser-posture-proof-verifier.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-posture-proof-verifier.mjs","names":[],"sources":["../src/browser-posture-proof-verifier.ts"],"sourcesContent":["import { base64UrlToBytes, base64UrlToString, bytesToBase64Url } from './utils/base64url';\n\nexport const POSTURE_PROOF_TYPE = 'dpop+jwt';\nexport const DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS = 60;\n\nexport interface BrowserPostureProof {\n jti: string;\n htm: string;\n htu: string;\n iat: number;\n}\n\nexport type BrowserPostureProofFailure =\n | 'malformed'\n | 'jkt-mismatch'\n | 'bad-signature'\n | 'invalid-claims'\n | 'htu-mismatch'\n | 'stale-iat';\n\nexport type BrowserPostureProofResult =\n | { verified: true; claims: BrowserPostureProof; jkt: string }\n | { verified: false; reason: BrowserPostureProofFailure };\n\ninterface ProofHeader {\n typ?: unknown;\n alg?: unknown;\n crit?: unknown;\n b64?: unknown;\n jwk?: ProofKey;\n}\n\ninterface ProofKey {\n kty?: unknown;\n crv?: unknown;\n x?: unknown;\n y?: unknown;\n d?: unknown;\n alg?: unknown;\n use?: unknown;\n ext?: boolean;\n key_ops?: KeyUsage[];\n}\n\nconst MALFORMED: BrowserPostureProofResult = { verified: false, reason: 'malformed' };\nconst BAD_SIGNATURE: BrowserPostureProofResult = { verified: false, reason: 'bad-signature' };\nconst KEY_ALGORITHM = { name: 'ECDSA', namedCurve: 'P-256' } as const;\nconst SIGNATURE_ALGORITHM = { name: 'ECDSA', hash: 'SHA-256' } as const;\nconst TAB_OR_NEWLINE = /[\\t\\n\\r]/g;\nconst encoder = new TextEncoder();\n\nfunction isNonEmptyString(value: unknown): value is string {\n return typeof value === 'string' && value !== '';\n}\n\nasync function thumbprint(x: unknown, y: unknown): Promise<string> {\n if (!isNonEmptyString(x) || !isNonEmptyString(y)) throw new TypeError('incomplete EC key');\n const digest = await crypto.subtle.digest(\n 'SHA-256',\n encoder.encode(JSON.stringify({ crv: 'P-256', kty: 'EC', x, y }))\n );\n return bytesToBase64Url(new Uint8Array(digest));\n}\n\nfunction importKey({ alg: _alg, use: _use, ...jwk }: ProofKey): Promise<CryptoKey> {\n return crypto.subtle.importKey(\n 'jwk',\n jwk as JsonWebKey,\n KEY_ALGORITHM,\n jwk.ext ?? false,\n jwk.key_ops ?? ['verify']\n );\n}\n\nfunction boundedText(value: unknown, maxCodePoints: number): value is string {\n return typeof value === 'string' && value !== '' && Array.from(value).length <= maxCodePoints;\n}\n\nfunction parsableUrl(value: string): boolean {\n try {\n return Boolean(new URL(value));\n } catch {\n return false;\n }\n}\n\nfunction criticalParametersAccepted({ crit, b64 }: ProofHeader): boolean {\n if (crit === undefined) return true;\n return (\n Array.isArray(crit) && crit.length > 0 && crit.every((name) => name === 'b64') && b64 === true\n );\n}\n\nfunction currentClaimSet(payload: unknown, now: number): Record<string, unknown> | undefined {\n if (typeof payload !== 'object' || payload === null || Array.isArray(payload)) return undefined;\n const { iat, nbf, exp } = payload as Record<string, unknown>;\n if (iat !== undefined && typeof iat !== 'number') return undefined;\n if (nbf !== undefined && (typeof nbf !== 'number' || nbf > now)) return undefined;\n if (exp !== undefined && (typeof exp !== 'number' || exp <= now)) return undefined;\n return payload as Record<string, unknown>;\n}\n\nfunction proofClaims(claims: Record<string, unknown>): BrowserPostureProof | undefined {\n const { jti, htm, htu, iat } = claims;\n if (!boundedText(jti, 255) || !boundedText(htm, 16)) return undefined;\n if (typeof iat !== 'number' || !Number.isSafeInteger(iat) || iat < 0) return undefined;\n if (typeof htu !== 'string' || !parsableUrl(htu.trim())) return undefined;\n return { jti, htm, htu: htu.trim().replace(TAB_OR_NEWLINE, ''), iat };\n}\n\nasync function signedClaims(\n segments: string[],\n header: ProofHeader,\n key: CryptoKey,\n now: number\n): Promise<Record<string, unknown> | undefined> {\n if (\n segments.length !== 3 ||\n segments.some((segment) => segment.includes('=')) ||\n !criticalParametersAccepted(header)\n ) {\n return undefined;\n }\n try {\n const verified = await crypto.subtle.verify(\n SIGNATURE_ALGORITHM,\n key,\n base64UrlToBytes(segments[2]),\n encoder.encode(`${segments[0]}.${segments[1]}`)\n );\n return verified\n ? currentClaimSet(JSON.parse(base64UrlToString(segments[1])), Math.floor(now))\n : undefined;\n } catch {\n return undefined;\n }\n}\n\nexport async function verifyBrowserPostureProofKey(\n proofJws: string | undefined,\n request: { method: string; url: string | readonly string[] },\n expectedJkt?: string,\n now = Math.floor(Date.now() / 1000),\n maxAgeSeconds = DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS\n): Promise<BrowserPostureProofResult> {\n if (typeof proofJws !== 'string' || proofJws === '' || proofJws.length > 2000) return MALFORMED;\n const segments = proofJws.split('.');\n let header: ProofHeader;\n let jkt: string;\n let key: CryptoKey;\n try {\n header = JSON.parse(base64UrlToString(segments[0]));\n if (\n header.typ !== POSTURE_PROOF_TYPE ||\n header.alg !== 'ES256' ||\n !header.jwk ||\n header.jwk.kty !== 'EC' ||\n header.jwk.crv !== 'P-256' ||\n header.jwk.d\n )\n return MALFORMED;\n jkt = await thumbprint(header.jwk.x, header.jwk.y);\n if (expectedJkt !== undefined && jkt !== expectedJkt) {\n return { verified: false, reason: 'jkt-mismatch' };\n }\n key = await importKey(header.jwk);\n } catch {\n return MALFORMED;\n }\n const payload = await signedClaims(segments, header, key, now);\n if (!payload) return BAD_SIGNATURE;\n const claims = proofClaims(payload);\n if (!claims) return { verified: false, reason: 'invalid-claims' };\n const acceptedUrls = typeof request.url === 'string' ? [request.url] : request.url;\n if (\n claims.htm.toUpperCase() !== request.method.toUpperCase() ||\n !acceptedUrls.includes(claims.htu)\n ) {\n return { verified: false, reason: 'htu-mismatch' };\n }\n if (Math.abs(now - claims.iat) > maxAgeSeconds) return { verified: false, reason: 'stale-iat' };\n return { verified: true, claims, jkt };\n}\n\nexport async function browserPostureKeyThumbprint(jwk: unknown): Promise<string | undefined> {\n if (typeof jwk !== 'object' || jwk === null) return undefined;\n const { kty, crv, x, y, d } = jwk as Record<string, unknown>;\n if (kty !== 'EC' || crv !== 'P-256' || typeof x !== 'string' || typeof y !== 'string' || d) {\n return undefined;\n }\n try {\n return await thumbprint(x, y);\n } catch {\n return undefined;\n }\n}\n"],"mappings":"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"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BrowserPostureProof, BrowserPostureProofFailure, BrowserPostureProofResult, DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS, POSTURE_PROOF_TYPE, browserPostureKeyThumbprint, verifyBrowserPostureProofKey } from "./browser-posture-proof-verifier.mjs";
|
|
2
2
|
import { A as ZodString, B as $strip, T as ZodObject, t as external_d_exports, w as ZodNumber } from "./external-m3Kmafwj.mjs";
|
|
3
|
-
import { N as BrowserPosture } from "./browser-posture-
|
|
3
|
+
import { N as BrowserPosture } from "./browser-posture-WPk0kl9u.mjs";
|
|
4
4
|
//#region src/browser-posture-proof.d.ts
|
|
5
5
|
export declare const BrowserPostureProofSchema: ZodObject<{
|
|
6
6
|
jti: ZodString;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { A as ZodString, B as $strip, T as ZodObject, t as external_d_exports, w as ZodNumber } from "./external-m3Kmafwj.js";
|
|
2
2
|
import { BrowserPostureProof, BrowserPostureProofFailure, BrowserPostureProofResult, DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS, POSTURE_PROOF_TYPE, browserPostureKeyThumbprint, verifyBrowserPostureProofKey } from "./browser-posture-proof-verifier.js";
|
|
3
|
-
import { N as BrowserPosture } from "./browser-posture-
|
|
3
|
+
import { N as BrowserPosture } from "./browser-posture-_y6BcdXw.js";
|
|
4
4
|
//#region src/browser-posture-proof.d.ts
|
|
5
5
|
export declare const BrowserPostureProofSchema: ZodObject<{
|
|
6
6
|
jti: ZodString;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_schemas = require('./schemas-BlScS1it.js');
|
|
3
|
-
const require_browser_posture_proof_verifier = require('./browser-posture-proof-verifier
|
|
3
|
+
const require_browser_posture_proof_verifier = require('./browser-posture-proof-verifier.js');
|
|
4
4
|
|
|
5
5
|
//#region src/browser-posture-proof.ts
|
|
6
6
|
const BrowserPostureProofSchema = require_schemas.object({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { S as string, _ as number, v as object } from "./schemas-IHAhH3gV.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS, POSTURE_PROOF_TYPE, browserPostureKeyThumbprint, verifyBrowserPostureProofKey } from "./browser-posture-proof-verifier.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/browser-posture-proof.ts
|
|
5
5
|
const BrowserPostureProofSchema = object({
|
|
@@ -27,6 +27,23 @@ declare const BrowserPostureSchema: z.ZodObject<{
|
|
|
27
27
|
cnf: z.ZodOptional<z.ZodObject<{
|
|
28
28
|
jkt: z.ZodString;
|
|
29
29
|
}, z.core.$strip>>;
|
|
30
|
+
network: z.ZodOptional<z.ZodObject<{
|
|
31
|
+
reflexive_ip: z.ZodOptional<z.ZodString>;
|
|
32
|
+
ip_masked: z.ZodOptional<z.ZodBoolean>;
|
|
33
|
+
timezone: z.ZodOptional<z.ZodString>;
|
|
34
|
+
languages: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
35
|
+
rtt_ms: z.ZodOptional<z.ZodNumber>;
|
|
36
|
+
serving_region: z.ZodOptional<z.ZodString>;
|
|
37
|
+
}, z.core.$strip>>;
|
|
38
|
+
environment: z.ZodOptional<z.ZodObject<{
|
|
39
|
+
incognito: z.ZodOptional<z.ZodBoolean>;
|
|
40
|
+
privacy_settings: z.ZodOptional<z.ZodBoolean>;
|
|
41
|
+
virtual_machine: z.ZodOptional<z.ZodBoolean>;
|
|
42
|
+
developer_tools: z.ZodOptional<z.ZodBoolean>;
|
|
43
|
+
tampering: z.ZodOptional<z.ZodBoolean>;
|
|
44
|
+
anti_detect: z.ZodOptional<z.ZodBoolean>;
|
|
45
|
+
os_mismatch: z.ZodOptional<z.ZodBoolean>;
|
|
46
|
+
}, z.core.$strip>>;
|
|
30
47
|
iat: z.ZodNumber;
|
|
31
48
|
exp: z.ZodNumber;
|
|
32
49
|
}, z.core.$strip>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser-posture-report.d.mts","names":[],"sources":["../src/browser-posture-schema.ts","../src/browser-posture-report.ts"],"mappings":";;cAEa,sBAAoB,EAAA
|
|
1
|
+
{"version":3,"file":"browser-posture-report.d.mts","names":[],"sources":["../src/browser-posture-schema.ts","../src/browser-posture-report.ts"],"mappings":";;cAEa,sBAAoB,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgE/B,EAAA,KAAA;KAGU,iBAAiB,EAAE,aAAa;;;qBClE/B;YACD,oCAAoC;qBAGnC,4BAA0B,EAAA;;;;;;;;;;;;;;GAWrC,EAAA,KAAA;qBAEW;YAaD,wCAAwC;qBAEvC,6BAA2B,EAAA;;;;;;;;;;;;;;;;;;;GAQpC,EAAA,KAAA;YACQ,wBAAwB,EAAE,aAAa;qBAEtC,gCAA8B;qBAC9B;qBACA;qBAEA,gCAA8B,EAAA,QAAA,EAAA,UAAA,EAAA,WAAA,EAAA,aAAA,EAAA;;GAkBxC;YACS,2BAA2B,EAAE,aAAa;qBAEzC,kCAAgC,EAAA;;;;;;;;;;;;;;GAE3C,EAAA,KAAA;wBAEc,qBAAqB,SAAS"}
|
|
@@ -27,6 +27,23 @@ declare const BrowserPostureSchema: z.ZodObject<{
|
|
|
27
27
|
cnf: z.ZodOptional<z.ZodObject<{
|
|
28
28
|
jkt: z.ZodString;
|
|
29
29
|
}, z.core.$strip>>;
|
|
30
|
+
network: z.ZodOptional<z.ZodObject<{
|
|
31
|
+
reflexive_ip: z.ZodOptional<z.ZodString>;
|
|
32
|
+
ip_masked: z.ZodOptional<z.ZodBoolean>;
|
|
33
|
+
timezone: z.ZodOptional<z.ZodString>;
|
|
34
|
+
languages: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
35
|
+
rtt_ms: z.ZodOptional<z.ZodNumber>;
|
|
36
|
+
serving_region: z.ZodOptional<z.ZodString>;
|
|
37
|
+
}, z.core.$strip>>;
|
|
38
|
+
environment: z.ZodOptional<z.ZodObject<{
|
|
39
|
+
incognito: z.ZodOptional<z.ZodBoolean>;
|
|
40
|
+
privacy_settings: z.ZodOptional<z.ZodBoolean>;
|
|
41
|
+
virtual_machine: z.ZodOptional<z.ZodBoolean>;
|
|
42
|
+
developer_tools: z.ZodOptional<z.ZodBoolean>;
|
|
43
|
+
tampering: z.ZodOptional<z.ZodBoolean>;
|
|
44
|
+
anti_detect: z.ZodOptional<z.ZodBoolean>;
|
|
45
|
+
os_mismatch: z.ZodOptional<z.ZodBoolean>;
|
|
46
|
+
}, z.core.$strip>>;
|
|
30
47
|
iat: z.ZodNumber;
|
|
31
48
|
exp: z.ZodNumber;
|
|
32
49
|
}, z.core.$strip>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser-posture-report.d.ts","names":[],"sources":["../src/browser-posture-schema.ts","../src/browser-posture-report.ts"],"mappings":";;cAEa,sBAAoB,EAAA
|
|
1
|
+
{"version":3,"file":"browser-posture-report.d.ts","names":[],"sources":["../src/browser-posture-schema.ts","../src/browser-posture-report.ts"],"mappings":";;cAEa,sBAAoB,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgE/B,EAAA,KAAA;KAGU,iBAAiB,EAAE,aAAa;;;qBClE/B;YACD,oCAAoC;qBAGnC,4BAA0B,EAAA;;;;;;;;;;;;;;GAWrC,EAAA,KAAA;qBAEW;YAaD,wCAAwC;qBAEvC,6BAA2B,EAAA;;;;;;;;;;;;;;;;;;;GAQpC,EAAA,KAAA;YACQ,wBAAwB,EAAE,aAAa;qBAEtC,gCAA8B;qBAC9B;qBACA;qBAEA,gCAA8B,EAAA,QAAA,EAAA,UAAA,EAAA,WAAA,EAAA,aAAA,EAAA;;GAkBxC;YACS,2BAA2B,EAAE,aAAa;qBAEzC,kCAAgC,EAAA;;;;;;;;;;;;;;GAE3C,EAAA,KAAA;wBAEc,qBAAqB,SAAS"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as POSTURE_VERIFICATION_STATUSES, C as verifyBrowserPosture, D as BrowserPostureRejectionReason, E as BrowserPostureOutcomeSchema, F as POSTURE_TTL_SECONDS, I as postureCookieName, M as browserPostureReport, N as BrowserPosture, O as BrowserPostureReportIngestSchema, P as BrowserPostureSchema, S as validateBrowserPostureConfig, T as BrowserPostureOutcome, _ as postureRequiredScopes, a as POSTURE_SESSION_HEADER, b as readPostureCookie, c as PostureVerification, d as inspectBrowserPosture, f as postureFromCookies, g as postureRequestFromHeaders, h as postureOutcomeReport, i as POSTURE_ISSUER, j as PostureVerificationStatus, k as BrowserPostureReportSchema, l as UNSIGNED_BROWSER_AGENT, m as postureOutcomeFromRequest, n as JWK, o as POSTURE_TYPE, p as postureFromRequest, r as POSTURE_HEADER, s as PostureRequest, t as BrowserPostureConfig, u as behavioralConfidence, v as postureSessionBinding, w as BROWSER_POSTURE_REJECTION_REASONS, x as signBrowserPosture, y as postureUpgrade } from "./browser-posture-
|
|
1
|
+
import { A as POSTURE_VERIFICATION_STATUSES, C as verifyBrowserPosture, D as BrowserPostureRejectionReason, E as BrowserPostureOutcomeSchema, F as POSTURE_TTL_SECONDS, I as postureCookieName, M as browserPostureReport, N as BrowserPosture, O as BrowserPostureReportIngestSchema, P as BrowserPostureSchema, S as validateBrowserPostureConfig, T as BrowserPostureOutcome, _ as postureRequiredScopes, a as POSTURE_SESSION_HEADER, b as readPostureCookie, c as PostureVerification, d as inspectBrowserPosture, f as postureFromCookies, g as postureRequestFromHeaders, h as postureOutcomeReport, i as POSTURE_ISSUER, j as PostureVerificationStatus, k as BrowserPostureReportSchema, l as UNSIGNED_BROWSER_AGENT, m as postureOutcomeFromRequest, n as JWK, o as POSTURE_TYPE, p as postureFromRequest, r as POSTURE_HEADER, s as PostureRequest, t as BrowserPostureConfig, u as behavioralConfidence, v as postureSessionBinding, w as BROWSER_POSTURE_REJECTION_REASONS, x as signBrowserPosture, y as postureUpgrade } from "./browser-posture-WPk0kl9u.mjs";
|
|
2
2
|
export { BROWSER_POSTURE_REJECTION_REASONS, type BrowserPosture, BrowserPostureConfig, type BrowserPostureOutcome, BrowserPostureOutcomeSchema, type BrowserPostureRejectionReason, BrowserPostureReportIngestSchema, BrowserPostureReportSchema, BrowserPostureSchema, type JWK, POSTURE_HEADER, POSTURE_ISSUER, POSTURE_SESSION_HEADER, POSTURE_TTL_SECONDS, POSTURE_TYPE, POSTURE_VERIFICATION_STATUSES, PostureRequest, PostureVerification, type PostureVerificationStatus, UNSIGNED_BROWSER_AGENT, behavioralConfidence, browserPostureReport, inspectBrowserPosture, postureCookieName, postureFromCookies, postureFromRequest, postureOutcomeFromRequest, postureOutcomeReport, postureRequestFromHeaders, postureRequiredScopes, postureSessionBinding, postureUpgrade, readPostureCookie, signBrowserPosture, validateBrowserPostureConfig, verifyBrowserPosture };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as POSTURE_VERIFICATION_STATUSES, C as verifyBrowserPosture, D as BrowserPostureRejectionReason, E as BrowserPostureOutcomeSchema, F as POSTURE_TTL_SECONDS, I as postureCookieName, M as browserPostureReport, N as BrowserPosture, O as BrowserPostureReportIngestSchema, P as BrowserPostureSchema, S as validateBrowserPostureConfig, T as BrowserPostureOutcome, _ as postureRequiredScopes, a as POSTURE_SESSION_HEADER, b as readPostureCookie, c as PostureVerification, d as inspectBrowserPosture, f as postureFromCookies, g as postureRequestFromHeaders, h as postureOutcomeReport, i as POSTURE_ISSUER, j as PostureVerificationStatus, k as BrowserPostureReportSchema, l as UNSIGNED_BROWSER_AGENT, m as postureOutcomeFromRequest, n as JWK, o as POSTURE_TYPE, p as postureFromRequest, r as POSTURE_HEADER, s as PostureRequest, t as BrowserPostureConfig, u as behavioralConfidence, v as postureSessionBinding, w as BROWSER_POSTURE_REJECTION_REASONS, x as signBrowserPosture, y as postureUpgrade } from "./browser-posture-
|
|
1
|
+
import { A as POSTURE_VERIFICATION_STATUSES, C as verifyBrowserPosture, D as BrowserPostureRejectionReason, E as BrowserPostureOutcomeSchema, F as POSTURE_TTL_SECONDS, I as postureCookieName, M as browserPostureReport, N as BrowserPosture, O as BrowserPostureReportIngestSchema, P as BrowserPostureSchema, S as validateBrowserPostureConfig, T as BrowserPostureOutcome, _ as postureRequiredScopes, a as POSTURE_SESSION_HEADER, b as readPostureCookie, c as PostureVerification, d as inspectBrowserPosture, f as postureFromCookies, g as postureRequestFromHeaders, h as postureOutcomeReport, i as POSTURE_ISSUER, j as PostureVerificationStatus, k as BrowserPostureReportSchema, l as UNSIGNED_BROWSER_AGENT, m as postureOutcomeFromRequest, n as JWK, o as POSTURE_TYPE, p as postureFromRequest, r as POSTURE_HEADER, s as PostureRequest, t as BrowserPostureConfig, u as behavioralConfidence, v as postureSessionBinding, w as BROWSER_POSTURE_REJECTION_REASONS, x as signBrowserPosture, y as postureUpgrade } from "./browser-posture-_y6BcdXw.js";
|
|
2
2
|
export { BROWSER_POSTURE_REJECTION_REASONS, type BrowserPosture, BrowserPostureConfig, type BrowserPostureOutcome, BrowserPostureOutcomeSchema, type BrowserPostureRejectionReason, BrowserPostureReportIngestSchema, BrowserPostureReportSchema, BrowserPostureSchema, type JWK, POSTURE_HEADER, POSTURE_ISSUER, POSTURE_SESSION_HEADER, POSTURE_TTL_SECONDS, POSTURE_TYPE, POSTURE_VERIFICATION_STATUSES, PostureRequest, PostureVerification, type PostureVerificationStatus, UNSIGNED_BROWSER_AGENT, behavioralConfidence, browserPostureReport, inspectBrowserPosture, postureCookieName, postureFromCookies, postureFromRequest, postureOutcomeFromRequest, postureOutcomeReport, postureRequestFromHeaders, postureRequiredScopes, postureSessionBinding, postureUpgrade, readPostureCookie, signBrowserPosture, validateBrowserPostureConfig, verifyBrowserPosture };
|
package/dist/browser-posture.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_schemas = require('./schemas-BlScS1it.js');
|
|
3
|
-
const require_patterns = require('./patterns-
|
|
3
|
+
const require_patterns = require('./patterns-CnNxRnaK.js');
|
|
4
4
|
const require_posture_origins = require('./posture-origins-Ci6k4Zh1.js');
|
|
5
5
|
const require_project_verification_key = require('./project-verification-key-B-L3D2nC.js');
|
|
6
6
|
let jose = require("jose");
|
|
@@ -55,6 +55,23 @@ const BrowserPostureSchema = require_schemas.object({
|
|
|
55
55
|
confidence: require_schemas.number().int().min(0).max(100)
|
|
56
56
|
}).optional(),
|
|
57
57
|
cnf: require_schemas.object({ jkt: require_schemas.string().min(1).max(255) }).optional(),
|
|
58
|
+
network: require_schemas.object({
|
|
59
|
+
reflexive_ip: require_schemas.string().min(2).max(45).optional(),
|
|
60
|
+
ip_masked: require_schemas.boolean().optional(),
|
|
61
|
+
timezone: require_schemas.string().min(1).max(64).optional(),
|
|
62
|
+
languages: require_schemas.array(require_schemas.string().min(1).max(35)).max(5).optional(),
|
|
63
|
+
rtt_ms: require_schemas.number().int().min(0).max(6e4).optional(),
|
|
64
|
+
serving_region: require_schemas.string().min(1).max(32).optional()
|
|
65
|
+
}).optional(),
|
|
66
|
+
environment: require_schemas.object({
|
|
67
|
+
incognito: require_schemas.boolean().optional(),
|
|
68
|
+
privacy_settings: require_schemas.boolean().optional(),
|
|
69
|
+
virtual_machine: require_schemas.boolean().optional(),
|
|
70
|
+
developer_tools: require_schemas.boolean().optional(),
|
|
71
|
+
tampering: require_schemas.boolean().optional(),
|
|
72
|
+
anti_detect: require_schemas.boolean().optional(),
|
|
73
|
+
os_mismatch: require_schemas.boolean().optional()
|
|
74
|
+
}).optional(),
|
|
58
75
|
iat: require_schemas.number().int().nonnegative(),
|
|
59
76
|
exp: require_schemas.number().int().positive()
|
|
60
77
|
});
|
|
@@ -294,9 +311,39 @@ async function postureFromRequest(request, config, projectId, now) {
|
|
|
294
311
|
async function postureFromCookies(header, config, projectId) {
|
|
295
312
|
return postureFromRequest({ cookie: header }, config, projectId);
|
|
296
313
|
}
|
|
297
|
-
/**
|
|
314
|
+
/**
|
|
315
|
+
* A path the way routers commonly match one: letter case and trailing
|
|
316
|
+
* slashes do not change which handler serves a request (Express routes are
|
|
317
|
+
* case-insensitive and non-strict by default), so they cannot change which
|
|
318
|
+
* designation covers it either. Folding them can only add a step-up.
|
|
319
|
+
*/
|
|
320
|
+
function routeKey(path) {
|
|
321
|
+
let end = path.length;
|
|
322
|
+
while (end > 0 && path.charCodeAt(end - 1) === 47) end--;
|
|
323
|
+
return end === 0 ? "/" : path.slice(0, end).toLowerCase();
|
|
324
|
+
}
|
|
325
|
+
/** The key a designation is matched and deduplicated by. */
|
|
326
|
+
function designationKey(path) {
|
|
327
|
+
return path.endsWith("/*") ? `${routeKey(path.slice(0, -2))}/*` : routeKey(path);
|
|
328
|
+
}
|
|
329
|
+
/** More specific first: the longer path, then an exact path before its own subtree. */
|
|
330
|
+
function bySpecificity(a, b) {
|
|
331
|
+
const length = (path) => routeKey(path.endsWith("/*") ? path.slice(0, -2) : path).length;
|
|
332
|
+
const subtree = (path) => path.endsWith("/*") ? 1 : 0;
|
|
333
|
+
return length(b.path) - length(a.path) || subtree(a.path) - subtree(b.path);
|
|
334
|
+
}
|
|
335
|
+
function designationCovers(designation, path) {
|
|
336
|
+
const key = routeKey(path);
|
|
337
|
+
if (!designation.endsWith("/*")) return key === routeKey(designation);
|
|
338
|
+
const root = routeKey(designation.slice(0, -2));
|
|
339
|
+
return root === "/" || key === root || key.startsWith(`${root}/`);
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Exact paths or an explicit subtree ending in /*, matched without letter
|
|
343
|
+
* case or trailing slashes. The most specific designation wins.
|
|
344
|
+
*/
|
|
298
345
|
function postureRequiredScopes(config, path) {
|
|
299
|
-
const route = [...config.protectedRoutes ?? []].sort(
|
|
346
|
+
const route = [...config.protectedRoutes ?? []].sort(bySpecificity).find((r) => designationCovers(r.path, path));
|
|
300
347
|
if (!route) return void 0;
|
|
301
348
|
if (!route.scopes.length || route.scopes.length > 50 || route.scopes.some((s) => s.length > 200 || !/^[\x21\x23-\x5b\x5d-\x7e]+$/.test(s)) || new Set(route.scopes).size !== route.scopes.length) throw new Error("Integrity-protected routes require explicit, unique scopes");
|
|
302
349
|
return route.scopes;
|
|
@@ -314,8 +361,9 @@ function validateBrowserPostureConfig(config, projectId) {
|
|
|
314
361
|
const paths = /* @__PURE__ */ new Set();
|
|
315
362
|
for (const route of config.protectedRoutes ?? []) {
|
|
316
363
|
if (!/^\/(?:[^?#*\\]*)(?:\/\*)?$/.test(route.path) && route.path !== "/*") throw new Error("Invalid integrity-protected path");
|
|
317
|
-
|
|
318
|
-
paths.
|
|
364
|
+
const key = designationKey(route.path);
|
|
365
|
+
if (paths.has(key)) throw new Error("Duplicate integrity-protected path");
|
|
366
|
+
paths.add(key);
|
|
319
367
|
postureRequiredScopes({
|
|
320
368
|
...config,
|
|
321
369
|
protectedRoutes: [route]
|
package/dist/browser-posture.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { S as string, _ as number, b as record, c as array, f as guid, h as literal, i as _enum, l as boolean, v as object, w as unknown } from "./schemas-IHAhH3gV.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { n as VALIDATION_PATTERNS, t as UUID_PATTERN } from "./patterns-CpRk9R3M.mjs";
|
|
3
3
|
import { n as matchAllowedOrigin, r as parseOriginPattern } from "./posture-origins-DGyS4Vuk.mjs";
|
|
4
4
|
import { t as projectVerificationKey } from "./project-verification-key-CWXdu3-n.mjs";
|
|
5
5
|
import { SignJWT, compactVerify, decodeProtectedHeader, importJWK } from "jose";
|
|
@@ -54,6 +54,23 @@ const BrowserPostureSchema = object({
|
|
|
54
54
|
confidence: number().int().min(0).max(100)
|
|
55
55
|
}).optional(),
|
|
56
56
|
cnf: object({ jkt: string().min(1).max(255) }).optional(),
|
|
57
|
+
network: object({
|
|
58
|
+
reflexive_ip: string().min(2).max(45).optional(),
|
|
59
|
+
ip_masked: boolean().optional(),
|
|
60
|
+
timezone: string().min(1).max(64).optional(),
|
|
61
|
+
languages: array(string().min(1).max(35)).max(5).optional(),
|
|
62
|
+
rtt_ms: number().int().min(0).max(6e4).optional(),
|
|
63
|
+
serving_region: string().min(1).max(32).optional()
|
|
64
|
+
}).optional(),
|
|
65
|
+
environment: object({
|
|
66
|
+
incognito: boolean().optional(),
|
|
67
|
+
privacy_settings: boolean().optional(),
|
|
68
|
+
virtual_machine: boolean().optional(),
|
|
69
|
+
developer_tools: boolean().optional(),
|
|
70
|
+
tampering: boolean().optional(),
|
|
71
|
+
anti_detect: boolean().optional(),
|
|
72
|
+
os_mismatch: boolean().optional()
|
|
73
|
+
}).optional(),
|
|
57
74
|
iat: number().int().nonnegative(),
|
|
58
75
|
exp: number().int().positive()
|
|
59
76
|
});
|
|
@@ -293,9 +310,39 @@ async function postureFromRequest(request, config, projectId, now) {
|
|
|
293
310
|
async function postureFromCookies(header, config, projectId) {
|
|
294
311
|
return postureFromRequest({ cookie: header }, config, projectId);
|
|
295
312
|
}
|
|
296
|
-
/**
|
|
313
|
+
/**
|
|
314
|
+
* A path the way routers commonly match one: letter case and trailing
|
|
315
|
+
* slashes do not change which handler serves a request (Express routes are
|
|
316
|
+
* case-insensitive and non-strict by default), so they cannot change which
|
|
317
|
+
* designation covers it either. Folding them can only add a step-up.
|
|
318
|
+
*/
|
|
319
|
+
function routeKey(path) {
|
|
320
|
+
let end = path.length;
|
|
321
|
+
while (end > 0 && path.charCodeAt(end - 1) === 47) end--;
|
|
322
|
+
return end === 0 ? "/" : path.slice(0, end).toLowerCase();
|
|
323
|
+
}
|
|
324
|
+
/** The key a designation is matched and deduplicated by. */
|
|
325
|
+
function designationKey(path) {
|
|
326
|
+
return path.endsWith("/*") ? `${routeKey(path.slice(0, -2))}/*` : routeKey(path);
|
|
327
|
+
}
|
|
328
|
+
/** More specific first: the longer path, then an exact path before its own subtree. */
|
|
329
|
+
function bySpecificity(a, b) {
|
|
330
|
+
const length = (path) => routeKey(path.endsWith("/*") ? path.slice(0, -2) : path).length;
|
|
331
|
+
const subtree = (path) => path.endsWith("/*") ? 1 : 0;
|
|
332
|
+
return length(b.path) - length(a.path) || subtree(a.path) - subtree(b.path);
|
|
333
|
+
}
|
|
334
|
+
function designationCovers(designation, path) {
|
|
335
|
+
const key = routeKey(path);
|
|
336
|
+
if (!designation.endsWith("/*")) return key === routeKey(designation);
|
|
337
|
+
const root = routeKey(designation.slice(0, -2));
|
|
338
|
+
return root === "/" || key === root || key.startsWith(`${root}/`);
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Exact paths or an explicit subtree ending in /*, matched without letter
|
|
342
|
+
* case or trailing slashes. The most specific designation wins.
|
|
343
|
+
*/
|
|
297
344
|
function postureRequiredScopes(config, path) {
|
|
298
|
-
const route = [...config.protectedRoutes ?? []].sort(
|
|
345
|
+
const route = [...config.protectedRoutes ?? []].sort(bySpecificity).find((r) => designationCovers(r.path, path));
|
|
299
346
|
if (!route) return void 0;
|
|
300
347
|
if (!route.scopes.length || route.scopes.length > 50 || route.scopes.some((s) => s.length > 200 || !/^[\x21\x23-\x5b\x5d-\x7e]+$/.test(s)) || new Set(route.scopes).size !== route.scopes.length) throw new Error("Integrity-protected routes require explicit, unique scopes");
|
|
301
348
|
return route.scopes;
|
|
@@ -313,8 +360,9 @@ function validateBrowserPostureConfig(config, projectId) {
|
|
|
313
360
|
const paths = /* @__PURE__ */ new Set();
|
|
314
361
|
for (const route of config.protectedRoutes ?? []) {
|
|
315
362
|
if (!/^\/(?:[^?#*\\]*)(?:\/\*)?$/.test(route.path) && route.path !== "/*") throw new Error("Invalid integrity-protected path");
|
|
316
|
-
|
|
317
|
-
paths.
|
|
363
|
+
const key = designationKey(route.path);
|
|
364
|
+
if (paths.has(key)) throw new Error("Duplicate integrity-protected path");
|
|
365
|
+
paths.add(key);
|
|
318
366
|
postureRequiredScopes({
|
|
319
367
|
...config,
|
|
320
368
|
protectedRoutes: [route]
|