@kya-os/checkpoint-shared 1.5.2 → 1.6.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 +98 -1
- package/dist/beacon-types/index.d.mts +12 -1
- package/dist/beacon-types/index.d.mts.map +1 -1
- package/dist/beacon-types/index.d.ts +12 -1
- package/dist/beacon-types/index.d.ts.map +1 -1
- package/dist/beacon-types/index.js +18 -1
- package/dist/beacon-types/index.mjs +18 -2
- package/dist/beacon-types/index.mjs.map +1 -1
- package/dist/{browser-posture-DVoHMHjY.d.mts → browser-posture-BuChqmH5.d.mts} +2 -2
- package/dist/{browser-posture-DVoHMHjY.d.mts.map → browser-posture-BuChqmH5.d.mts.map} +1 -1
- package/dist/{browser-posture-D4j2a5gi.d.ts → browser-posture-DIaVLuW3.d.ts} +2 -2
- package/dist/{browser-posture-D4j2a5gi.d.ts.map → browser-posture-DIaVLuW3.d.ts.map} +1 -1
- package/dist/browser-posture-proof.d.mts +2 -2
- package/dist/browser-posture-proof.d.ts +2 -2
- package/dist/browser-posture-proof.js +1 -1
- package/dist/browser-posture-proof.mjs +1 -1
- package/dist/browser-posture.d.mts +1 -1
- package/dist/browser-posture.d.ts +1 -1
- package/dist/browser-posture.js +3 -3
- package/dist/browser-posture.mjs +3 -3
- package/dist/browser-posture.mjs.map +1 -1
- package/dist/clearance.d.mts +1 -1
- package/dist/clearance.d.ts +1 -1
- package/dist/clearance.js +2 -2
- package/dist/clearance.mjs +2 -2
- package/dist/errors/index.d.mts +17 -0
- package/dist/errors/index.d.mts.map +1 -1
- package/dist/errors/index.d.ts +17 -0
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +75 -3
- package/dist/errors/index.mjs +75 -3
- package/dist/errors/index.mjs.map +1 -1
- package/dist/{external-Ct8j_hto.d.ts → external-B7WI9FyQ.d.mts} +2 -2
- package/dist/{external-Ct8j_hto.d.mts.map → external-B7WI9FyQ.d.mts.map} +1 -1
- package/dist/{external-Ct8j_hto.d.mts → external-B7WI9FyQ.d.ts} +2 -2
- package/dist/{external-Ct8j_hto.d.ts.map → external-B7WI9FyQ.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 +811 -132
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +811 -132
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1945 -145
- package/dist/index.mjs +1891 -145
- package/dist/index.mjs.map +1 -1
- package/dist/mcpi/approval-grant/index.d.mts.map +1 -1
- package/dist/mcpi/approval-grant/index.d.ts.map +1 -1
- package/dist/mcpi/approval-grant/index.js +10 -1
- package/dist/mcpi/approval-grant/index.mjs +10 -1
- package/dist/mcpi/approval-grant/index.mjs.map +1 -1
- package/dist/mcpi/dashboard-config/index.d.mts +3 -2
- package/dist/mcpi/dashboard-config/index.d.mts.map +1 -1
- package/dist/mcpi/dashboard-config/index.d.ts +3 -2
- package/dist/mcpi/dashboard-config/index.d.ts.map +1 -1
- package/dist/{posture-origins-CEm83u4D.js → posture-origins-LFkX80oF.js} +6 -0
- package/dist/{posture-origins-Dl7i8j93.mjs → posture-origins-Pn-ii-Pp.mjs} +2 -2
- package/dist/{posture-origins-Dl7i8j93.mjs.map → posture-origins-Pn-ii-Pp.mjs.map} +1 -1
- package/dist/{project-verification-key-CgSVX9_m.mjs → project-verification-key-66N4edKn.mjs} +2 -2
- package/dist/{project-verification-key-CgSVX9_m.mjs.map → project-verification-key-66N4edKn.mjs.map} +1 -1
- package/dist/{project-verification-key-C3L5rd8a.js → project-verification-key-BccT12tQ.js} +1 -1
- package/dist/{schemas-DxY-dk9y.mjs → schemas-7qodsG-Z.mjs} +49 -2
- package/dist/schemas-7qodsG-Z.mjs.map +1 -0
- package/dist/{schemas-BmjNLAE7.js → schemas-YhagYDx_.js} +59 -0
- package/fixtures/cli-registration.v2.json +115 -0
- package/fixtures/detection/reason-codes.json +1 -1
- package/fixtures/kya-http/README.md +34 -26
- package/fixtures/kya-http/protected-resource-metadata.full.json +14 -5
- package/fixtures/kya-http/protected-resource-metadata.invalid-issuer.json +51 -0
- package/fixtures/kya-http/protected-resource-metadata.no-issuer.json +32 -0
- package/fixtures/reviewer-grant-revocation.v1.json +285 -0
- package/package.json +4 -4
- package/dist/schemas-DxY-dk9y.mjs.map +0 -1
- package/fixtures/kya-http/protected-resource-metadata.global.json +0 -28
package/dist/index.js
CHANGED
|
@@ -27,8 +27,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
}) : target, mod));
|
|
28
28
|
|
|
29
29
|
//#endregion
|
|
30
|
-
const require_schemas = require('./schemas-
|
|
31
|
-
const require_posture_origins = require('./posture-origins-
|
|
30
|
+
const require_schemas = require('./schemas-YhagYDx_.js');
|
|
31
|
+
const require_posture_origins = require('./posture-origins-LFkX80oF.js');
|
|
32
32
|
const require_client_ip = require('./client-ip-CW6pRyLf.js');
|
|
33
33
|
let _noble_hashes_sha2_js = require("@noble/hashes/sha2.js");
|
|
34
34
|
let _noble_hashes_utils_js = require("@noble/hashes/utils.js");
|
|
@@ -67,6 +67,112 @@ function date(params) {
|
|
|
67
67
|
return require_schemas._coercedDate(require_schemas.ZodDate, params);
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region src/core/network-assertions.ts
|
|
72
|
+
const ProxyCollectionStateSchema = require_schemas._enum([
|
|
73
|
+
"current",
|
|
74
|
+
"unavailable",
|
|
75
|
+
"stale",
|
|
76
|
+
"unsupported",
|
|
77
|
+
"conflicting",
|
|
78
|
+
"insufficient_support"
|
|
79
|
+
]);
|
|
80
|
+
const epochSeconds = require_schemas.number().int().min(0).max(253402300799);
|
|
81
|
+
const percentage = require_schemas.number().int().min(0).max(100);
|
|
82
|
+
/** Source assertions describe request egress membership, never a visitor identity or fraud verdict. */
|
|
83
|
+
const ProxyAssertionSchema = require_schemas.object({
|
|
84
|
+
kind: require_schemas.string().min(1),
|
|
85
|
+
source: require_schemas.string().min(1),
|
|
86
|
+
subjectScope: require_schemas.literal("request_egress"),
|
|
87
|
+
membership: require_schemas._enum([
|
|
88
|
+
"present",
|
|
89
|
+
"absent",
|
|
90
|
+
"unknown"
|
|
91
|
+
]),
|
|
92
|
+
evidenceGrade: require_schemas._enum(["confirmed", "vendor_reported"]),
|
|
93
|
+
collectionState: ProxyCollectionStateSchema,
|
|
94
|
+
/** Unix seconds supplied by the source. Reader fetch time is not source observation time. */
|
|
95
|
+
observedAt: epochSeconds.nullable(),
|
|
96
|
+
expiresAt: epochSeconds.nullable(),
|
|
97
|
+
membershipConfidence: percentage.nullable(),
|
|
98
|
+
sourceReliability: percentage.nullable(),
|
|
99
|
+
fraudProbability: require_schemas.number().min(0).max(1).nullable(),
|
|
100
|
+
proxyClass: require_schemas._enum(["datacenter", "unknown"]).optional()
|
|
101
|
+
}).strict();
|
|
102
|
+
const knownKinds = /* @__PURE__ */ new Set([
|
|
103
|
+
"tor_exit",
|
|
104
|
+
"published_vpn_exit",
|
|
105
|
+
"observed_proxy",
|
|
106
|
+
"suspected_residential_proxy",
|
|
107
|
+
"privacy_relay",
|
|
108
|
+
"local_tunnel",
|
|
109
|
+
"hosting"
|
|
110
|
+
]);
|
|
111
|
+
/**
|
|
112
|
+
* The default admits only confirmed, current assertions. maxmind_legacy preserves
|
|
113
|
+
* existing vendor positives without claiming that its undated optional file is fresh.
|
|
114
|
+
* Uncertain evidence never produces a confirmed-clean false Boolean.
|
|
115
|
+
*/
|
|
116
|
+
function mapProxyAssertions(proxyAssertions, nowSeconds, collectionState, compatibility = "confirmed_current") {
|
|
117
|
+
const states = [collectionState];
|
|
118
|
+
const eligible = [];
|
|
119
|
+
for (const assertion of proxyAssertions) {
|
|
120
|
+
if (!knownKinds.has(assertion.kind)) {
|
|
121
|
+
states.push("unsupported");
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
states.push(assertion.collectionState);
|
|
125
|
+
if (assertion.collectionState !== "current" && assertion.collectionState !== "insufficient_support") {
|
|
126
|
+
states.push(assertion.collectionState);
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const dated = assertion.observedAt !== null && assertion.expiresAt !== null;
|
|
130
|
+
const current = dated && assertion.observedAt <= nowSeconds && assertion.expiresAt > nowSeconds;
|
|
131
|
+
if (dated && !current) {
|
|
132
|
+
states.push("stale");
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
const confirmed = assertion.evidenceGrade === "confirmed" && assertion.collectionState === "current" && current;
|
|
136
|
+
const legacy = compatibility === "maxmind_legacy" && assertion.source === "maxmind-anonymous-ip" && assertion.evidenceGrade === "vendor_reported" && assertion.collectionState === "insufficient_support" && assertion.observedAt === null && assertion.expiresAt === null;
|
|
137
|
+
if (confirmed || legacy) eligible.push(assertion);
|
|
138
|
+
else states.push("insufficient_support");
|
|
139
|
+
}
|
|
140
|
+
for (const assertion of eligible) if (assertion.membership === "present" && eligible.some((other) => other.kind === assertion.kind && other.membership === "absent")) states.push("conflicting");
|
|
141
|
+
if (proxyAssertions.length === 0) states.push("insufficient_support");
|
|
142
|
+
const proxyCollectionState = [
|
|
143
|
+
"conflicting",
|
|
144
|
+
"unsupported",
|
|
145
|
+
"unavailable",
|
|
146
|
+
"stale",
|
|
147
|
+
"insufficient_support",
|
|
148
|
+
"current"
|
|
149
|
+
].find((state) => states.includes(state));
|
|
150
|
+
const blocked = proxyCollectionState !== "current" && proxyCollectionState !== "insufficient_support";
|
|
151
|
+
const positive = eligible.filter((assertion) => assertion.membership === "present");
|
|
152
|
+
const preferred = [
|
|
153
|
+
positive.find((assertion) => assertion.kind === "tor_exit"),
|
|
154
|
+
positive.find((assertion) => assertion.kind === "published_vpn_exit"),
|
|
155
|
+
positive.find((assertion) => assertion.kind === "suspected_residential_proxy"),
|
|
156
|
+
positive.find((assertion) => assertion.kind === "observed_proxy" && assertion.proxyClass === "datacenter"),
|
|
157
|
+
positive.find((assertion) => assertion.kind === "observed_proxy")
|
|
158
|
+
].find(Boolean);
|
|
159
|
+
const types = {
|
|
160
|
+
tor_exit: "tor",
|
|
161
|
+
published_vpn_exit: "vpn",
|
|
162
|
+
suspected_residential_proxy: "residential_proxy",
|
|
163
|
+
observed_proxy: preferred?.proxyClass === "datacenter" ? "datacenter" : "unknown"
|
|
164
|
+
};
|
|
165
|
+
return {
|
|
166
|
+
proxy: !blocked && preferred ? {
|
|
167
|
+
isProxy: true,
|
|
168
|
+
proxyType: types[preferred.kind],
|
|
169
|
+
confidence: preferred.membershipConfidence ?? (preferred.evidenceGrade === "vendor_reported" ? 90 : 0)
|
|
170
|
+
} : void 0,
|
|
171
|
+
proxyAssertions,
|
|
172
|
+
proxyCollectionState
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
70
176
|
//#endregion
|
|
71
177
|
//#region src/core/risk-score.ts
|
|
72
178
|
/**
|
|
@@ -514,8 +620,8 @@ const ProxyInfoSchema = require_schemas.object({
|
|
|
514
620
|
});
|
|
515
621
|
/**
|
|
516
622
|
* Host-supplied network / IP-intelligence context for a request's
|
|
517
|
-
* `trueIp`.
|
|
518
|
-
* engine's `VerifyResult.network` (a sibling of `DetectionDetail`, like
|
|
623
|
+
* `trueIp`. Legacy fields mirror the Rust `NetworkContext` and appear on
|
|
624
|
+
* the engine's `VerifyResult.network` (a sibling of `DetectionDetail`, like
|
|
519
625
|
* `EngineInfo` above — there is no wrapping `VerifyResultSchema`) when the
|
|
520
626
|
* host supplied one, and exposed to Cedar as `context.ip_routing_type` /
|
|
521
627
|
* `context.is_proxy`. Absent-safe: a request with no network context is
|
|
@@ -526,7 +632,13 @@ const NetworkContextSchema = require_schemas.object({
|
|
|
526
632
|
asn: require_schemas.number().int().nonnegative().optional(),
|
|
527
633
|
isp: require_schemas.string().optional(),
|
|
528
634
|
routingType: RoutingTypeSchema,
|
|
529
|
-
proxy: ProxyInfoSchema.optional()
|
|
635
|
+
proxy: ProxyInfoSchema.optional(),
|
|
636
|
+
/**
|
|
637
|
+
* TypeScript-host evidence, retained in detection rows and extended API read-back.
|
|
638
|
+
* Older Rust readers do not echo these additive fields.
|
|
639
|
+
*/
|
|
640
|
+
proxyAssertions: require_schemas.array(ProxyAssertionSchema).optional(),
|
|
641
|
+
proxyCollectionState: ProxyCollectionStateSchema.optional()
|
|
530
642
|
});
|
|
531
643
|
/**
|
|
532
644
|
* Descriptive detection detail from the engine.
|
|
@@ -635,7 +747,7 @@ const DetectionDetailSchema = require_schemas.object({
|
|
|
635
747
|
* `DetectionDetail.granted_scopes` (additive, omitted when empty). */
|
|
636
748
|
grantedScopes: require_schemas.array(require_schemas.string()).optional(),
|
|
637
749
|
/**
|
|
638
|
-
*
|
|
750
|
+
* Detection reason codes (#4874): namespaced detection/* codes, most-
|
|
639
751
|
* significant-evidence first, derived via mapDetectionToReasonCodes.
|
|
640
752
|
* Optional: only producers that opt into signal exposure (currently
|
|
641
753
|
* /api/v1/detect via buildDetectionSignalExposure) populate this.
|
|
@@ -1311,7 +1423,7 @@ function getVerificationRiskLevel(method, confidence) {
|
|
|
1311
1423
|
/**
|
|
1312
1424
|
* Detection reason-code mapping: the single pure projection of a
|
|
1313
1425
|
* detection's structured facts onto the `DETECTION_REASON_CODES` registry
|
|
1314
|
-
* (
|
|
1426
|
+
* (#4874).
|
|
1315
1427
|
*
|
|
1316
1428
|
* The engine already emits structured evidence (`signals[]` with a typed
|
|
1317
1429
|
* `source`, `verificationMethod`, `detectionClass`, `isAiCrawler`) but the
|
|
@@ -2562,7 +2674,6 @@ const DEFAULT_ENV_VARS = {
|
|
|
2562
2674
|
AGENTSHIELD_SECRET_KEY: "",
|
|
2563
2675
|
AGENTSHIELD_PIXEL_ID: "",
|
|
2564
2676
|
AGENTSHIELD_API_ENDPOINT: "https://api.agentshield.ai",
|
|
2565
|
-
AGENTSHIELD_WASM_PATH: "/wasm/agentshield_wasm_bg.wasm",
|
|
2566
2677
|
AGENTSHIELD_CACHE_TTL: "3600",
|
|
2567
2678
|
AGENTSHIELD_DEBUG: "false",
|
|
2568
2679
|
AGENTSHIELD_LOG_LEVEL: "info"
|
|
@@ -2826,7 +2937,9 @@ const BARE_ERRORS = {
|
|
|
2826
2937
|
BARE_INVALID_END_DATE: "INVALID_END_DATE",
|
|
2827
2938
|
BARE_INVALID_DATE_RANGE: "INVALID_DATE_RANGE",
|
|
2828
2939
|
BARE_INVALID_DATE: "INVALID_DATE",
|
|
2829
|
-
BARE_UNKNOWN_ERROR: "UNKNOWN_ERROR"
|
|
2940
|
+
BARE_UNKNOWN_ERROR: "UNKNOWN_ERROR",
|
|
2941
|
+
BARE_NOT_FOUND: "NOT_FOUND",
|
|
2942
|
+
BARE_FORBIDDEN: "FORBIDDEN"
|
|
2830
2943
|
};
|
|
2831
2944
|
/**
|
|
2832
2945
|
* Lowercase Error Codes
|
|
@@ -2996,6 +3109,40 @@ const KYAOS_PROTOCOL_ERRORS = {
|
|
|
2996
3109
|
KYAOS_SLASH_POLICY_UNAVAILABLE: "kyaos/policy-unavailable"
|
|
2997
3110
|
};
|
|
2998
3111
|
/**
|
|
3112
|
+
* Gateway Vault Resolve Error Codes
|
|
3113
|
+
*
|
|
3114
|
+
* Emitted by POST /api/v1/gateway/vault/{projectId}/resolve, and five of them
|
|
3115
|
+
* (INVALID_ASSERTION, INVALID_SIGNATURE, ASSERTION_EXPIRED, ASSERTION_REPLAYED,
|
|
3116
|
+
* PROJECT_MISMATCH) also by POST /api/v1/vault/{projectId}/resolve, which
|
|
3117
|
+
* verifies through the same shared verifier and nonce store
|
|
3118
|
+
* (apps/web/lib/vault/). Every emission site passes an explicit message and
|
|
3119
|
+
* status, so registering them changes no wire behaviour.
|
|
3120
|
+
*/
|
|
3121
|
+
const GATEWAY_VAULT_ERRORS = {
|
|
3122
|
+
MALFORMED_REQUEST_BODY: "MALFORMED_REQUEST_BODY",
|
|
3123
|
+
GATEWAY_NOT_CONFIGURED: "GATEWAY_NOT_CONFIGURED",
|
|
3124
|
+
INVALID_ASSERTION: "INVALID_ASSERTION",
|
|
3125
|
+
INVALID_SIGNATURE: "INVALID_SIGNATURE",
|
|
3126
|
+
ASSERTION_EXPIRED: "ASSERTION_EXPIRED",
|
|
3127
|
+
ASSERTION_REPLAYED: "ASSERTION_REPLAYED",
|
|
3128
|
+
PROJECT_MISMATCH: "PROJECT_MISMATCH",
|
|
3129
|
+
ISSUER_MISMATCH: "ISSUER_MISMATCH",
|
|
3130
|
+
USER_DID_MISMATCH: "USER_DID_MISMATCH",
|
|
3131
|
+
TOOL_NAME_MISMATCH: "TOOL_NAME_MISMATCH",
|
|
3132
|
+
SESSION_ID_MISMATCH: "SESSION_ID_MISMATCH",
|
|
3133
|
+
NOT_AUTHORIZED: "NOT_AUTHORIZED",
|
|
3134
|
+
CREDENTIALS_NOT_CONFIGURED: "CREDENTIALS_NOT_CONFIGURED",
|
|
3135
|
+
OAUTH_EXPIRED: "OAUTH_EXPIRED"
|
|
3136
|
+
};
|
|
3137
|
+
/**
|
|
3138
|
+
* Vault Resolve Error Codes
|
|
3139
|
+
*
|
|
3140
|
+
* The one code unique to POST /api/v1/vault/{projectId}/resolve. The rest of
|
|
3141
|
+
* its surface reuses GATEWAY_VAULT_ERRORS, BARE_ERRORS and INTERNAL_ERRORS by
|
|
3142
|
+
* key.
|
|
3143
|
+
*/
|
|
3144
|
+
const VAULT_ERRORS = { NO_AGENT_KEY: "NO_AGENT_KEY" };
|
|
3145
|
+
/**
|
|
2999
3146
|
* All Error Codes
|
|
3000
3147
|
*/
|
|
3001
3148
|
const ERROR_CODES = {
|
|
@@ -3021,7 +3168,9 @@ const ERROR_CODES = {
|
|
|
3021
3168
|
...BOUNCER_UPPERCASE_ERRORS,
|
|
3022
3169
|
...AUDIT_ERRORS,
|
|
3023
3170
|
...AUDIT_PROTOCOL_ERRORS,
|
|
3024
|
-
...KYAOS_PROTOCOL_ERRORS
|
|
3171
|
+
...KYAOS_PROTOCOL_ERRORS,
|
|
3172
|
+
...GATEWAY_VAULT_ERRORS,
|
|
3173
|
+
...VAULT_ERRORS
|
|
3025
3174
|
};
|
|
3026
3175
|
/**
|
|
3027
3176
|
* Error Messages
|
|
@@ -3139,6 +3288,8 @@ const ERROR_MESSAGES = {
|
|
|
3139
3288
|
[BARE_ERRORS.BARE_INVALID_DATE_RANGE]: "startDate must be before endDate",
|
|
3140
3289
|
[BARE_ERRORS.BARE_INVALID_DATE]: "Invalid date format. Use ISO 8601 format (YYYY-MM-DD or YYYY-MM-DDTHH:mm:ss.sssZ)",
|
|
3141
3290
|
[BARE_ERRORS.BARE_UNKNOWN_ERROR]: "Failed to delete project",
|
|
3291
|
+
[BARE_ERRORS.BARE_NOT_FOUND]: "Not found",
|
|
3292
|
+
[BARE_ERRORS.BARE_FORBIDDEN]: "Forbidden",
|
|
3142
3293
|
[LOWERCASE_ERRORS.LOWERCASE_INVALID_JSON]: "Request body must be valid JSON",
|
|
3143
3294
|
[LOWERCASE_ERRORS.LOWERCASE_VALIDATION_ERROR]: "Invalid request body",
|
|
3144
3295
|
[BOUNCER_LOWERCASE_ERRORS.LOWERCASE_NO_PROJECT]: "API key is not associated with a project",
|
|
@@ -3232,7 +3383,22 @@ const ERROR_MESSAGES = {
|
|
|
3232
3383
|
[KYAOS_PROTOCOL_ERRORS.KYAOS_SLASH_HOLDER_MISMATCH]: "The holder does not match the delegation or grant",
|
|
3233
3384
|
[KYAOS_PROTOCOL_ERRORS.KYAOS_SLASH_INVALID_SIGNATURE]: "The signature could not be verified",
|
|
3234
3385
|
[KYAOS_PROTOCOL_ERRORS.KYAOS_SLASH_SESSION_MISMATCH]: "The session does not match the delegation or proof",
|
|
3235
|
-
[KYAOS_PROTOCOL_ERRORS.KYAOS_SLASH_POLICY_UNAVAILABLE]: "The policy revision is currently unavailable"
|
|
3386
|
+
[KYAOS_PROTOCOL_ERRORS.KYAOS_SLASH_POLICY_UNAVAILABLE]: "The policy revision is currently unavailable",
|
|
3387
|
+
[GATEWAY_VAULT_ERRORS.MALFORMED_REQUEST_BODY]: "Malformed JSON body",
|
|
3388
|
+
[GATEWAY_VAULT_ERRORS.GATEWAY_NOT_CONFIGURED]: "Gateway public key or trusted DID not configured for this project",
|
|
3389
|
+
[GATEWAY_VAULT_ERRORS.INVALID_ASSERTION]: "Assertion JWT must have 3 parts",
|
|
3390
|
+
[GATEWAY_VAULT_ERRORS.INVALID_SIGNATURE]: "Assertion signature verification failed",
|
|
3391
|
+
[GATEWAY_VAULT_ERRORS.ASSERTION_EXPIRED]: "Assertion is expired or outside the allowed window",
|
|
3392
|
+
[GATEWAY_VAULT_ERRORS.ASSERTION_REPLAYED]: "Assertion nonce has already been used",
|
|
3393
|
+
[GATEWAY_VAULT_ERRORS.PROJECT_MISMATCH]: "Assertion projectId does not match route",
|
|
3394
|
+
[GATEWAY_VAULT_ERRORS.ISSUER_MISMATCH]: "Assertion issuer does not match trusted gateway DID",
|
|
3395
|
+
[GATEWAY_VAULT_ERRORS.USER_DID_MISMATCH]: "Assertion userDid does not match request body userDid",
|
|
3396
|
+
[GATEWAY_VAULT_ERRORS.TOOL_NAME_MISMATCH]: "Assertion toolName does not match request body toolName",
|
|
3397
|
+
[GATEWAY_VAULT_ERRORS.SESSION_ID_MISMATCH]: "Assertion sessionId does not match request body sessionId",
|
|
3398
|
+
[GATEWAY_VAULT_ERRORS.NOT_AUTHORIZED]: "User is not a member of this organization",
|
|
3399
|
+
[GATEWAY_VAULT_ERRORS.CREDENTIALS_NOT_CONFIGURED]: "Connect your credentials in Checkpoint",
|
|
3400
|
+
[GATEWAY_VAULT_ERRORS.OAUTH_EXPIRED]: "Provider token expired; user must reconnect",
|
|
3401
|
+
[VAULT_ERRORS.NO_AGENT_KEY]: "No agent deployment found for this project"
|
|
3236
3402
|
};
|
|
3237
3403
|
/**
|
|
3238
3404
|
* HTTP Status Codes for Errors
|
|
@@ -3284,6 +3450,8 @@ const ERROR_STATUS_CODES = {
|
|
|
3284
3450
|
[BOUNCER_UPPERCASE_ERRORS.INVALID_REQUEST_ID]: 400,
|
|
3285
3451
|
[AUDIT_ERRORS.AUDIT_INVALID_JSON]: 400,
|
|
3286
3452
|
[AUDIT_ERRORS.AUDIT_INVALID_SUBMISSION]: 400,
|
|
3453
|
+
[GATEWAY_VAULT_ERRORS.MALFORMED_REQUEST_BODY]: 400,
|
|
3454
|
+
[GATEWAY_VAULT_ERRORS.INVALID_ASSERTION]: 400,
|
|
3287
3455
|
[AUTH_ERRORS.INVALID_API_KEY]: 401,
|
|
3288
3456
|
[AUTH_ERRORS.EXPIRED_API_KEY]: 401,
|
|
3289
3457
|
[AUTH_ERRORS.INVALID_TOKEN]: 401,
|
|
@@ -3295,6 +3463,7 @@ const ERROR_STATUS_CODES = {
|
|
|
3295
3463
|
[BOUNCER_LOWERCASE_ERRORS.LOWERCASE_UNAUTHORIZED]: 401,
|
|
3296
3464
|
[AUDIT_ERRORS.AUDIT_CREDENTIAL_REQUIRED]: 401,
|
|
3297
3465
|
[AUDIT_ERRORS.AUDIT_INVALID_CREDENTIAL]: 401,
|
|
3466
|
+
[GATEWAY_VAULT_ERRORS.INVALID_SIGNATURE]: 401,
|
|
3298
3467
|
[BILLING_ERRORS.LIMIT_EXCEEDED]: 402,
|
|
3299
3468
|
[BILLING_ERRORS.BILLING_SUSPENDED]: 402,
|
|
3300
3469
|
[PERMISSION_ERRORS.INSUFFICIENT_PERMISSIONS]: 403,
|
|
@@ -3316,6 +3485,16 @@ const ERROR_STATUS_CODES = {
|
|
|
3316
3485
|
[KYAOS_PROTOCOL_ERRORS.KYAOS_SLASH_DELEGATION_REVOKED]: 403,
|
|
3317
3486
|
[KYAOS_PROTOCOL_ERRORS.KYAOS_SLASH_HOLDER_MISMATCH]: 403,
|
|
3318
3487
|
[KYAOS_PROTOCOL_ERRORS.KYAOS_SLASH_INVALID_SIGNATURE]: 403,
|
|
3488
|
+
[BARE_ERRORS.BARE_FORBIDDEN]: 403,
|
|
3489
|
+
[GATEWAY_VAULT_ERRORS.ASSERTION_EXPIRED]: 403,
|
|
3490
|
+
[GATEWAY_VAULT_ERRORS.ASSERTION_REPLAYED]: 403,
|
|
3491
|
+
[GATEWAY_VAULT_ERRORS.PROJECT_MISMATCH]: 403,
|
|
3492
|
+
[GATEWAY_VAULT_ERRORS.ISSUER_MISMATCH]: 403,
|
|
3493
|
+
[GATEWAY_VAULT_ERRORS.USER_DID_MISMATCH]: 403,
|
|
3494
|
+
[GATEWAY_VAULT_ERRORS.TOOL_NAME_MISMATCH]: 403,
|
|
3495
|
+
[GATEWAY_VAULT_ERRORS.SESSION_ID_MISMATCH]: 403,
|
|
3496
|
+
[GATEWAY_VAULT_ERRORS.NOT_AUTHORIZED]: 403,
|
|
3497
|
+
[GATEWAY_VAULT_ERRORS.OAUTH_EXPIRED]: 403,
|
|
3319
3498
|
[PERMISSION_ERRORS.RESOURCE_NOT_FOUND]: 404,
|
|
3320
3499
|
[API_ERRORS.ENDPOINT_NOT_FOUND]: 404,
|
|
3321
3500
|
[PIXEL_ERRORS.PIXEL_NOT_FOUND]: 404,
|
|
@@ -3333,6 +3512,9 @@ const ERROR_STATUS_CODES = {
|
|
|
3333
3512
|
[BOUNCER_UPPERCASE_ERRORS.DEPLOYMENT_NOT_FOUND]: 404,
|
|
3334
3513
|
[BOUNCER_UPPERCASE_ERRORS.DELEGATION_REQUEST_NOT_FOUND]: 404,
|
|
3335
3514
|
[KYAOS_PROTOCOL_ERRORS.KYAOS_SLASH_INVALID_SESSION]: 404,
|
|
3515
|
+
[BARE_ERRORS.BARE_NOT_FOUND]: 404,
|
|
3516
|
+
[GATEWAY_VAULT_ERRORS.CREDENTIALS_NOT_CONFIGURED]: 404,
|
|
3517
|
+
[VAULT_ERRORS.NO_AGENT_KEY]: 404,
|
|
3336
3518
|
[API_ERRORS.METHOD_NOT_ALLOWED]: 405,
|
|
3337
3519
|
[RESOURCE_ERRORS.CONFLICT]: 409,
|
|
3338
3520
|
[AUDIT_PROTOCOL_ERRORS.AUDIT_LEDGER_MISMATCH]: 409,
|
|
@@ -3384,6 +3566,7 @@ const ERROR_STATUS_CODES = {
|
|
|
3384
3566
|
[AUDIT_PROTOCOL_ERRORS.AUDIT_MIRROR_VERIFICATION_FAILED]: 500,
|
|
3385
3567
|
[AUDIT_PROTOCOL_ERRORS.AUDIT_MIRROR_CONTINUITY_FAILED]: 500,
|
|
3386
3568
|
[AUDIT_PROTOCOL_ERRORS.AUDIT_MIRROR_OUT_OF_ORDER]: 500,
|
|
3569
|
+
[GATEWAY_VAULT_ERRORS.GATEWAY_NOT_CONFIGURED]: 500,
|
|
3387
3570
|
[NETWORK_ERRORS.UPSTREAM_ERROR]: 502,
|
|
3388
3571
|
[INTERNAL_ERRORS.INITIALIZATION_ERROR]: 503,
|
|
3389
3572
|
[INTERNAL_ERRORS.SERVICE_UNAVAILABLE_TRANSIENT]: 503,
|
|
@@ -5595,6 +5778,191 @@ const VerificationCacheEntrySchema = require_schemas.object({
|
|
|
5595
5778
|
expiresAt: require_schemas.number()
|
|
5596
5779
|
});
|
|
5597
5780
|
|
|
5781
|
+
//#endregion
|
|
5782
|
+
//#region src/utils/allowed-domains.ts
|
|
5783
|
+
/**
|
|
5784
|
+
* A pixel's `configuration.allowedDomains`: the page hosts a pixel accepts
|
|
5785
|
+
* events from (`/api/v1/event` compares them to the event URL's hostname).
|
|
5786
|
+
*
|
|
5787
|
+
* Stored form is a bare, lowercase, punycoded host (`shop.example.com`) or a
|
|
5788
|
+
* leftmost wildcard (`*.example.com`, which covers `example.com` itself and
|
|
5789
|
+
* every subdomain, never a look-alike such as `evilexample.com`).
|
|
5790
|
+
*
|
|
5791
|
+
* The comparison side, `URL.hostname`, is always lowercase with no scheme,
|
|
5792
|
+
* port or path, so an entry stored as `*.Example.com`, `https://example.com`
|
|
5793
|
+
* or `example.com:443` never matched and 403'd every event. Entries are now
|
|
5794
|
+
* normalized on write, and legacy rows are normalized again on read so they
|
|
5795
|
+
* stop failing without a backfill.
|
|
5796
|
+
*/
|
|
5797
|
+
const WILDCARD_PROBE_LABEL = "allowed-domain-wildcard-probe";
|
|
5798
|
+
const MAX_ALLOWED_DOMAIN_LENGTH = 300;
|
|
5799
|
+
/**
|
|
5800
|
+
* Most entries one pixel may list. Generous on purpose: each event checks
|
|
5801
|
+
* its host against every entry, and the list was uncapped before, so a
|
|
5802
|
+
* smaller cap could refuse an existing pixel's next save.
|
|
5803
|
+
*/
|
|
5804
|
+
const MAX_ALLOWED_DOMAINS = 1e3;
|
|
5805
|
+
/** One DNS label after URL's lowercasing and punycoding. `_` occurs in real subdomains. */
|
|
5806
|
+
const HOST_LABEL = /^[a-z0-9_-]{1,63}$/;
|
|
5807
|
+
const DEFAULT_PORTS = /* @__PURE__ */ new Set(["80", "443"]);
|
|
5808
|
+
/** URL accepts empty labels and characters such as `;` or `,`, which no page host has. */
|
|
5809
|
+
function isHostName(host) {
|
|
5810
|
+
if (host.startsWith("[") && host.endsWith("]")) return true;
|
|
5811
|
+
return host.split(".").every((label) => HOST_LABEL.test(label));
|
|
5812
|
+
}
|
|
5813
|
+
function parseAllowedDomain(entry) {
|
|
5814
|
+
const trimmed = typeof entry === "string" ? entry.trim() : "";
|
|
5815
|
+
if (!trimmed) return { error: "Enter a domain such as shop.example.com" };
|
|
5816
|
+
if (trimmed.length > 300) return { error: `Must be at most ${300} characters` };
|
|
5817
|
+
const schemeMatch = /^([a-z][a-z0-9+.-]*):\/\//i.exec(trimmed);
|
|
5818
|
+
const scheme = schemeMatch ? schemeMatch[1].toLowerCase() : "https";
|
|
5819
|
+
if (scheme !== "https" && scheme !== "http") return { error: "Use a domain name, e.g. shop.example.com" };
|
|
5820
|
+
const rest = schemeMatch ? trimmed.slice(schemeMatch[0].length) : trimmed;
|
|
5821
|
+
const wildcard = rest.startsWith("*.");
|
|
5822
|
+
const withoutWildcard = wildcard ? rest.slice(2) : rest;
|
|
5823
|
+
if (!withoutWildcard || withoutWildcard.includes("*")) return { error: "A wildcard is only allowed as the first label, e.g. *.example.com" };
|
|
5824
|
+
let url;
|
|
5825
|
+
try {
|
|
5826
|
+
url = new URL(`${scheme}://${wildcard ? `${WILDCARD_PROBE_LABEL}.` : ""}${withoutWildcard}`);
|
|
5827
|
+
} catch {
|
|
5828
|
+
return { error: "Not a valid domain" };
|
|
5829
|
+
}
|
|
5830
|
+
if (url.username || url.password) return { error: "Domains cannot contain a username" };
|
|
5831
|
+
let host = url.hostname.replace(/\.$/, "");
|
|
5832
|
+
if (wildcard) {
|
|
5833
|
+
if (!host.startsWith(`${WILDCARD_PROBE_LABEL}.`)) return { error: "Not a valid domain" };
|
|
5834
|
+
host = host.slice(30);
|
|
5835
|
+
}
|
|
5836
|
+
if (!isHostName(host)) return { error: "Not a valid domain" };
|
|
5837
|
+
return {
|
|
5838
|
+
host,
|
|
5839
|
+
wildcard,
|
|
5840
|
+
port: DEFAULT_PORTS.has(url.port) ? "" : url.port
|
|
5841
|
+
};
|
|
5842
|
+
}
|
|
5843
|
+
function format(parsed) {
|
|
5844
|
+
return `${parsed.wildcard ? "*." : ""}${parsed.host}`;
|
|
5845
|
+
}
|
|
5846
|
+
/**
|
|
5847
|
+
* `*.com`, `*.co.uk`, `*.myshopify.com`: a wildcard that admits sites the
|
|
5848
|
+
* customer does not control. Same rule as posture origins, so the two
|
|
5849
|
+
* allowlists refuse the same entries.
|
|
5850
|
+
*/
|
|
5851
|
+
function isPublicSuffixWildcard(parsed) {
|
|
5852
|
+
return parsed.wildcard && require_posture_origins.isPublicSuffixLike(parsed.host);
|
|
5853
|
+
}
|
|
5854
|
+
/**
|
|
5855
|
+
* Strict write-time normalization. Returns the stored form, or an error for
|
|
5856
|
+
* junk: another scheme, userinfo, a misplaced wildcard, a host with an empty
|
|
5857
|
+
* label or a character no host has, a non-default port (the check compares
|
|
5858
|
+
* host names only, so a port would suggest a restriction that is never
|
|
5859
|
+
* enforced), or a wildcard over a public suffix.
|
|
5860
|
+
*
|
|
5861
|
+
* @example
|
|
5862
|
+
* normalizeAllowedDomainForWrite('HTTPS://Shop.Example.com:443/cart') // { ok: true, value: 'shop.example.com' }
|
|
5863
|
+
* normalizeAllowedDomainForWrite('*.Example.com.') // { ok: true, value: '*.example.com' }
|
|
5864
|
+
*/
|
|
5865
|
+
function normalizeAllowedDomainForWrite(entry) {
|
|
5866
|
+
const parsed = parseAllowedDomain(entry);
|
|
5867
|
+
if ("error" in parsed) return {
|
|
5868
|
+
ok: false,
|
|
5869
|
+
error: parsed.error
|
|
5870
|
+
};
|
|
5871
|
+
if (parsed.port) return {
|
|
5872
|
+
ok: false,
|
|
5873
|
+
error: "Ports are not supported; the check matches the host name only"
|
|
5874
|
+
};
|
|
5875
|
+
if (isPublicSuffixWildcard(parsed)) return {
|
|
5876
|
+
ok: false,
|
|
5877
|
+
error: `*.${parsed.host} would include sites you do not control; list your own hosts instead`
|
|
5878
|
+
};
|
|
5879
|
+
return {
|
|
5880
|
+
ok: true,
|
|
5881
|
+
value: format(parsed)
|
|
5882
|
+
};
|
|
5883
|
+
}
|
|
5884
|
+
/**
|
|
5885
|
+
* Lenient read-time normalization for entries already stored: strips a
|
|
5886
|
+
* scheme, path, port and trailing dot and lowercases, so a legacy entry
|
|
5887
|
+
* such as `https://Example.com:443/` still matches. Undefined for entries
|
|
5888
|
+
* that cannot be a host at all (they then match nothing, as before).
|
|
5889
|
+
*
|
|
5890
|
+
* It never widens what a pixel accepts to a public suffix. A malformed
|
|
5891
|
+
* wildcard over one (`*.COM`, `https://*.co.uk`) matched nothing before, and
|
|
5892
|
+
* cleaning it up would admit every site under it, which writes now refuse.
|
|
5893
|
+
* So it stays undefined. One already stored in exact form (`*.com`) matched
|
|
5894
|
+
* before this normalization existed and is returned unchanged.
|
|
5895
|
+
*/
|
|
5896
|
+
function normalizeStoredAllowedDomain(entry) {
|
|
5897
|
+
if (typeof entry !== "string") return void 0;
|
|
5898
|
+
const parsed = parseAllowedDomain(entry);
|
|
5899
|
+
if ("error" in parsed) return void 0;
|
|
5900
|
+
const normalized = format(parsed);
|
|
5901
|
+
if (isPublicSuffixWildcard(parsed) && entry !== normalized) return void 0;
|
|
5902
|
+
return normalized;
|
|
5903
|
+
}
|
|
5904
|
+
/**
|
|
5905
|
+
* Whether a page host is admitted by a pixel's allowed domains. Exact
|
|
5906
|
+
* entries match the host exactly; `*.example.com` matches `example.com`
|
|
5907
|
+
* and any subdomain, on a label boundary.
|
|
5908
|
+
*
|
|
5909
|
+
* @example
|
|
5910
|
+
* hostMatchesAllowedDomains('shop.example.com', ['*.Example.com']) // true
|
|
5911
|
+
* hostMatchesAllowedDomains('evilexample.com', ['*.example.com']) // false
|
|
5912
|
+
*/
|
|
5913
|
+
function hostMatchesAllowedDomains(hostname, allowedDomains) {
|
|
5914
|
+
const host = hostname.toLowerCase().replace(/\.$/, "");
|
|
5915
|
+
if (!host) return false;
|
|
5916
|
+
return allowedDomains.some((raw) => {
|
|
5917
|
+
const entry = normalizeStoredAllowedDomain(raw);
|
|
5918
|
+
if (!entry) return false;
|
|
5919
|
+
if (!entry.startsWith("*.")) return host === entry;
|
|
5920
|
+
const base = entry.slice(2);
|
|
5921
|
+
return host === base || host.endsWith(`.${base}`);
|
|
5922
|
+
});
|
|
5923
|
+
}
|
|
5924
|
+
/**
|
|
5925
|
+
* Normalizes a whole list for a write: stored forms in first-seen order with
|
|
5926
|
+
* duplicates removed, plus each junk entry's index and reason. Linear in the
|
|
5927
|
+
* list's length.
|
|
5928
|
+
*
|
|
5929
|
+
* @example
|
|
5930
|
+
* normalizeAllowedDomainList(['Example.com', 'a..b', 'example.com'])
|
|
5931
|
+
* // { values: ['example.com'], errors: [{ index: 1, message: 'Not a valid domain' }] }
|
|
5932
|
+
*/
|
|
5933
|
+
function normalizeAllowedDomainList(entries) {
|
|
5934
|
+
const values = /* @__PURE__ */ new Set();
|
|
5935
|
+
const errors = [];
|
|
5936
|
+
entries.forEach((entry, index) => {
|
|
5937
|
+
const result = normalizeAllowedDomainForWrite(entry);
|
|
5938
|
+
if (result.ok) values.add(result.value);
|
|
5939
|
+
else errors.push({
|
|
5940
|
+
index,
|
|
5941
|
+
message: result.error
|
|
5942
|
+
});
|
|
5943
|
+
});
|
|
5944
|
+
return {
|
|
5945
|
+
values: [...values],
|
|
5946
|
+
errors
|
|
5947
|
+
};
|
|
5948
|
+
}
|
|
5949
|
+
/**
|
|
5950
|
+
* `allowedDomains` on a pixel write: at most {@link MAX_ALLOWED_DOMAINS}
|
|
5951
|
+
* entries, each normalized to its stored form (duplicates removed), and each
|
|
5952
|
+
* junk entry reported at its index so the route's 400 says which one and
|
|
5953
|
+
* why. The cap is checked first, so an oversized list is refused without
|
|
5954
|
+
* normalizing any entry.
|
|
5955
|
+
*/
|
|
5956
|
+
const AllowedDomainsSchema = require_schemas.array(require_schemas.string()).max(MAX_ALLOWED_DOMAINS, `At most ${MAX_ALLOWED_DOMAINS} allowed domains`).transform((entries, ctx) => {
|
|
5957
|
+
const { values, errors } = normalizeAllowedDomainList(entries);
|
|
5958
|
+
errors.forEach(({ index, message }) => ctx.addIssue({
|
|
5959
|
+
code: "custom",
|
|
5960
|
+
message,
|
|
5961
|
+
path: [index]
|
|
5962
|
+
}));
|
|
5963
|
+
return values;
|
|
5964
|
+
});
|
|
5965
|
+
|
|
5598
5966
|
//#endregion
|
|
5599
5967
|
//#region src/api/bulk.ts
|
|
5600
5968
|
/**
|
|
@@ -5751,7 +6119,7 @@ const PixelsBulkCreateItemSchema = require_schemas.object({
|
|
|
5751
6119
|
domain: require_schemas.string().url().optional(),
|
|
5752
6120
|
isActive: require_schemas.boolean().default(true),
|
|
5753
6121
|
configuration: require_schemas.object({
|
|
5754
|
-
allowedDomains:
|
|
6122
|
+
allowedDomains: AllowedDomainsSchema.default([]),
|
|
5755
6123
|
collectBehavioral: require_schemas.boolean().default(true),
|
|
5756
6124
|
enableFingerprinting: require_schemas.boolean().default(true),
|
|
5757
6125
|
enableSessionTracking: require_schemas.boolean().default(true),
|
|
@@ -5764,7 +6132,7 @@ const PixelsBulkUpdateItemSchema = require_schemas.object({
|
|
|
5764
6132
|
domain: require_schemas.string().url().optional(),
|
|
5765
6133
|
isActive: require_schemas.boolean().optional(),
|
|
5766
6134
|
configuration: require_schemas.object({
|
|
5767
|
-
allowedDomains:
|
|
6135
|
+
allowedDomains: AllowedDomainsSchema.optional(),
|
|
5768
6136
|
collectBehavioral: require_schemas.boolean().optional(),
|
|
5769
6137
|
enableFingerprinting: require_schemas.boolean().optional(),
|
|
5770
6138
|
enableSessionTracking: require_schemas.boolean().optional(),
|
|
@@ -6021,7 +6389,7 @@ const ProjectSchema = require_schemas.object({
|
|
|
6021
6389
|
const PixelConfigurationSchema = require_schemas.object({
|
|
6022
6390
|
enabled: require_schemas.boolean().default(true),
|
|
6023
6391
|
skipPaths: require_schemas.array(require_schemas.string()).default([]),
|
|
6024
|
-
allowedDomains:
|
|
6392
|
+
allowedDomains: AllowedDomainsSchema.default([]),
|
|
6025
6393
|
blockedAgents: require_schemas.array(require_schemas.string()).default([]),
|
|
6026
6394
|
batchSize: require_schemas.number().min(1).max(100).default(10),
|
|
6027
6395
|
flushInterval: require_schemas.number().min(100).max(6e4).default(5e3),
|
|
@@ -6583,6 +6951,31 @@ const ConsentAgentMetadataSchema = require_schemas.object({
|
|
|
6583
6951
|
connectedAt: require_schemas.string().datetime().optional()
|
|
6584
6952
|
});
|
|
6585
6953
|
/**
|
|
6954
|
+
* Brand copy for one input the consent page asks a person to fill in. Copy
|
|
6955
|
+
* only: which inputs appear is the project's consent policy's call (its
|
|
6956
|
+
* sign-in methods and assurance providers), never this config's.
|
|
6957
|
+
*/
|
|
6958
|
+
const ConsentInputCopySchema = require_schemas.object({
|
|
6959
|
+
label: require_schemas.string().max(80).optional(),
|
|
6960
|
+
/** A typed field's placeholder, or the hint line under it where the step has one. */
|
|
6961
|
+
hint: require_schemas.string().max(200).optional()
|
|
6962
|
+
});
|
|
6963
|
+
const ConsentSignInCopySchema = require_schemas.object({
|
|
6964
|
+
/** The address field of the email-code and email-and-password sign-ins. */
|
|
6965
|
+
email: ConsentInputCopySchema.optional(),
|
|
6966
|
+
password: ConsentInputCopySchema.optional(),
|
|
6967
|
+
/** The RPPS number step (`registry:fr-rpps`); `prompt` is its heading. */
|
|
6968
|
+
rpps: ConsentInputCopySchema.extend({ prompt: require_schemas.string().max(120).optional() }).optional()
|
|
6969
|
+
});
|
|
6970
|
+
/** A consent policy names a handful of scopes; this only bounds the stored map. */
|
|
6971
|
+
const MAX_SCOPE_LABELS = 50;
|
|
6972
|
+
/**
|
|
6973
|
+
* The brand's name for a scope no authored capability covers, keyed by the
|
|
6974
|
+
* literal scope. Copy only: unlike a capability, a label here never makes a
|
|
6975
|
+
* scope grantable (`allowedScopesFor` does not read it) and carries no Cedar.
|
|
6976
|
+
*/
|
|
6977
|
+
const ConsentScopeLabelsSchema = require_schemas.record(require_schemas.string().min(1).max(120), require_schemas.string().min(1).max(80)).refine((labels) => Object.keys(labels).length <= MAX_SCOPE_LABELS, `At most ${MAX_SCOPE_LABELS} scope labels`);
|
|
6978
|
+
/**
|
|
6586
6979
|
* Full Consent Configuration
|
|
6587
6980
|
*/
|
|
6588
6981
|
const ConsentConfigSchema = require_schemas.object({
|
|
@@ -6599,7 +6992,9 @@ const ConsentConfigSchema = require_schemas.object({
|
|
|
6599
6992
|
headlineVerb: require_schemas.string().min(1).max(40).optional(),
|
|
6600
6993
|
revocationPath: require_schemas.string().min(1).max(120).optional(),
|
|
6601
6994
|
inactivityDays: require_schemas.number().int().min(1).max(3650).optional(),
|
|
6602
|
-
authorizationHost: require_schemas.string().min(1).max(255).optional()
|
|
6995
|
+
authorizationHost: require_schemas.string().min(1).max(255).optional(),
|
|
6996
|
+
signInCopy: ConsentSignInCopySchema.optional(),
|
|
6997
|
+
scopeLabels: ConsentScopeLabelsSchema.optional()
|
|
6603
6998
|
});
|
|
6604
6999
|
/**
|
|
6605
7000
|
* Tool Consent Overrides (CRED-002)
|
|
@@ -7377,7 +7772,36 @@ const MarketplaceSourceSchema = require_schemas._enum([
|
|
|
7377
7772
|
]);
|
|
7378
7773
|
/** Enforcement posture — mirrors the SDK's `enforcementMode` ('observe' = detect-only). */
|
|
7379
7774
|
const ProvisioningModeSchema = require_schemas._enum(["observe", "enforce"]);
|
|
7775
|
+
/** Backend-verifiable installer identity. Caller-supplied verification flags confer no authority. */
|
|
7776
|
+
const ProvisioningIdentityProofSchema = require_schemas.discriminatedUnion("type", [
|
|
7777
|
+
require_schemas.object({
|
|
7778
|
+
type: require_schemas.literal("vercel-oidc"),
|
|
7779
|
+
token: require_schemas.string().min(1).max(16384)
|
|
7780
|
+
}),
|
|
7781
|
+
require_schemas.object({
|
|
7782
|
+
type: require_schemas.literal("railway-oauth"),
|
|
7783
|
+
accessToken: require_schemas.string().min(1).max(16384)
|
|
7784
|
+
}),
|
|
7785
|
+
require_schemas.object({
|
|
7786
|
+
type: require_schemas.literal("checkpoint-account-link"),
|
|
7787
|
+
token: require_schemas.string().min(1).max(16384)
|
|
7788
|
+
})
|
|
7789
|
+
]);
|
|
7790
|
+
/** A signed account-link capability issued only from the installer's authenticated session. */
|
|
7791
|
+
const ProvisioningAccountLinkRequestSchema = require_schemas.object({
|
|
7792
|
+
source: MarketplaceSourceSchema,
|
|
7793
|
+
externalId: require_schemas.string().min(1).max(255),
|
|
7794
|
+
resourceId: require_schemas.string().min(1).max(255).optional()
|
|
7795
|
+
});
|
|
7796
|
+
const ProvisioningAccountLinkResponseSchema = require_schemas.object({
|
|
7797
|
+
identityProof: require_schemas.object({
|
|
7798
|
+
type: require_schemas.literal("checkpoint-account-link"),
|
|
7799
|
+
token: require_schemas.string().min(1)
|
|
7800
|
+
}),
|
|
7801
|
+
expiresIn: require_schemas.literal(600)
|
|
7802
|
+
});
|
|
7380
7803
|
const ProvisionKeyRequestSchema = require_schemas.object({
|
|
7804
|
+
identityProof: ProvisioningIdentityProofSchema.optional(),
|
|
7381
7805
|
source: MarketplaceSourceSchema,
|
|
7382
7806
|
/** Provider installation/configuration id (e.g. Vercel configurationId). */
|
|
7383
7807
|
externalId: require_schemas.string().min(1).max(255),
|
|
@@ -7390,12 +7814,7 @@ const ProvisionKeyRequestSchema = require_schemas.object({
|
|
|
7390
7814
|
resourceId: require_schemas.string().min(1).max(255),
|
|
7391
7815
|
/** Human-readable label for the dashboard (e.g. "Vercel / team_xxx / my-project"). */
|
|
7392
7816
|
label: require_schemas.string().min(1).max(200),
|
|
7393
|
-
/**
|
|
7394
|
-
* Owner of the provisioned project. `email` is the account-linking key: we find-or-create
|
|
7395
|
-
* the KYA-OS user + personal org from it (Shopify-parity), so an address matching an
|
|
7396
|
-
* existing account provisions INTO that account — including the org it lands in.
|
|
7397
|
-
*
|
|
7398
|
-
*/
|
|
7817
|
+
/** Installer email must match the identity established by identityProof. */
|
|
7399
7818
|
owner: require_schemas.object({
|
|
7400
7819
|
email: require_schemas.string().email(),
|
|
7401
7820
|
name: require_schemas.string().min(1).max(255).optional()
|
|
@@ -7429,15 +7848,16 @@ const ProvisionKeyResponseSchema = require_schemas.object({
|
|
|
7429
7848
|
});
|
|
7430
7849
|
/**
|
|
7431
7850
|
* Request for `POST /api/provisioning/sso-link` — the "Open in Provider" handoff.
|
|
7432
|
-
* The
|
|
7851
|
+
* The backend verifies `ownerEmail` using provider evidence or an authenticated account-link ticket.
|
|
7433
7852
|
*/
|
|
7434
7853
|
const SsoLinkRequestSchema = require_schemas.object({
|
|
7854
|
+
identityProof: ProvisioningIdentityProofSchema.optional(),
|
|
7435
7855
|
source: MarketplaceSourceSchema,
|
|
7436
7856
|
/** Provider installation/configuration id (e.g. Vercel configurationId). */
|
|
7437
7857
|
externalId: require_schemas.string().min(1).max(255),
|
|
7438
7858
|
/** Optional provider resource id — present → deep-link to that project; absent → org landing. */
|
|
7439
7859
|
resourceId: require_schemas.string().min(1).max(255).optional(),
|
|
7440
|
-
/**
|
|
7860
|
+
/** Installer email must match the identity established by identityProof. */
|
|
7441
7861
|
ownerEmail: require_schemas.string().email()
|
|
7442
7862
|
});
|
|
7443
7863
|
const SsoLinkResponseSchema = require_schemas.object({
|
|
@@ -7477,7 +7897,13 @@ const ProvisioningOrganizationSummarySchema = require_schemas.object({
|
|
|
7477
7897
|
role: ProvisioningOrganizationRoleSchema
|
|
7478
7898
|
});
|
|
7479
7899
|
/** List a user's administrable orgs by verified email. No user match ⇒ `{ organizations: [] }`. */
|
|
7480
|
-
const ListProvisioningOrganizationsRequestSchema = require_schemas.object({
|
|
7900
|
+
const ListProvisioningOrganizationsRequestSchema = require_schemas.object({
|
|
7901
|
+
source: MarketplaceSourceSchema.optional(),
|
|
7902
|
+
externalId: require_schemas.string().min(1).max(255).optional(),
|
|
7903
|
+
resourceId: require_schemas.string().min(1).max(255).optional(),
|
|
7904
|
+
identityProof: ProvisioningIdentityProofSchema.optional(),
|
|
7905
|
+
email: require_schemas.string().email()
|
|
7906
|
+
});
|
|
7481
7907
|
const ListProvisioningOrganizationsResponseSchema = require_schemas.object({ organizations: require_schemas.array(ProvisioningOrganizationSummarySchema) });
|
|
7482
7908
|
/**
|
|
7483
7909
|
* Create an org for a (found-or-created) user by verified email. `name`/`slug` reuse the
|
|
@@ -7485,6 +7911,10 @@ const ListProvisioningOrganizationsResponseSchema = require_schemas.object({ org
|
|
|
7485
7911
|
* accept exactly the same input.
|
|
7486
7912
|
*/
|
|
7487
7913
|
const CreateProvisioningOrganizationRequestSchema = require_schemas.object({
|
|
7914
|
+
source: MarketplaceSourceSchema.optional(),
|
|
7915
|
+
externalId: require_schemas.string().min(1).max(255).optional(),
|
|
7916
|
+
resourceId: require_schemas.string().min(1).max(255).optional(),
|
|
7917
|
+
identityProof: ProvisioningIdentityProofSchema.optional(),
|
|
7488
7918
|
email: require_schemas.string().email(),
|
|
7489
7919
|
name: CreateOrganizationInputSchema.shape.name,
|
|
7490
7920
|
slug: CreateOrganizationInputSchema.shape.slug
|
|
@@ -8072,30 +8502,13 @@ const ShopifySessionsPaginationSchema = require_schemas.object({
|
|
|
8072
8502
|
totalPages: require_schemas.number().int().nonnegative().describe("`min(ceil(total / limit), 200)`: the last page `sessionsPage` accepts."),
|
|
8073
8503
|
hasMore: require_schemas.boolean().describe("True when `page < totalPages`.")
|
|
8074
8504
|
});
|
|
8075
|
-
/**
|
|
8076
|
-
* Shopify Stats Response
|
|
8077
|
-
*
|
|
8078
|
-
* Every counter is a SESSION count, not an event count. `totalRequests` is
|
|
8079
|
-
* the number of sessions in the window and `blockedBots` the AI-agent
|
|
8080
|
-
* sessions among them.
|
|
8081
|
-
*
|
|
8082
|
-
* `crawlerSessions` and `humanSessions` complete the four-way split
|
|
8083
|
-
* (AI agent / crawler / human / unclassified). Both are optional in both
|
|
8084
|
-
* directions: an older Checkpoint does not send them, and an older Shopify
|
|
8085
|
-
* app ignores them. When present they come from the same per-session
|
|
8086
|
-
* classification as `blockedBots` (ai_agent > bot > human priority), so
|
|
8087
|
-
* `blockedBots + crawlerSessions + humanSessions <= totalRequests`; the
|
|
8088
|
-
* remainder is sessions that belong to no class.
|
|
8089
|
-
*
|
|
8090
|
-
* `sessions` and `sessionsPagination` are present only when the request
|
|
8091
|
-
* asks for them (`include=sessions`); an older Checkpoint never sends them.
|
|
8092
|
-
*/
|
|
8093
8505
|
const ShopifyStatsResponseSchema = require_schemas.object({
|
|
8094
8506
|
totalRequests: require_schemas.number().int().nonnegative(),
|
|
8095
8507
|
blockedBots: require_schemas.number().int().nonnegative(),
|
|
8096
8508
|
allowedRequests: require_schemas.number().int().nonnegative(),
|
|
8097
8509
|
crawlerSessions: require_schemas.number().int().nonnegative().optional(),
|
|
8098
8510
|
humanSessions: require_schemas.number().int().nonnegative().optional(),
|
|
8511
|
+
unidentifiedSessions: require_schemas.number().int().nonnegative().optional().describe("Sessions in the window with no ai_agent, bot or human detection and at least one incomplete-data detection that carries the no_evidence basis: an idle visitor the engine had nothing to weigh. They are counted in `totalRequests` and `humanSessions`, so this says how many of the human sessions the engine could not classify. Sessions whose incomplete-data detections all have another reason, such as suspicious headers, are in no counter. A window over 31 days is counted the same way, one UTC day at a time, from the daily rollups. Omitted when the session split is unavailable: a window over 31 days served from a cached result that predates the split, and older deployments."),
|
|
8099
8512
|
threatLevel: require_schemas._enum([
|
|
8100
8513
|
"low",
|
|
8101
8514
|
"medium",
|
|
@@ -10318,6 +10731,14 @@ const FingerprintSearchQuerySchema = require_schemas.object({
|
|
|
10318
10731
|
]).default("timestamp"),
|
|
10319
10732
|
sortOrder: require_schemas._enum(["asc", "desc"]).default("desc")
|
|
10320
10733
|
});
|
|
10734
|
+
/**
|
|
10735
|
+
* Test result when running detection on a fingerprint.
|
|
10736
|
+
*
|
|
10737
|
+
* @deprecated Nothing in this repository builds or parses it; the
|
|
10738
|
+
* `/fingerprint/test` route returns its own shape. Kept because this file is
|
|
10739
|
+
* the package's public type surface and a shipped CHANGELOG entry names it.
|
|
10740
|
+
* Remove in the next major.
|
|
10741
|
+
*/
|
|
10321
10742
|
const DetectionTestResultSchema = require_schemas.object({
|
|
10322
10743
|
fingerprintId: require_schemas.string(),
|
|
10323
10744
|
timestamp: require_schemas.date(),
|
|
@@ -10372,8 +10793,8 @@ const PublishProfileRequestSchema = require_schemas.object({
|
|
|
10372
10793
|
version: require_schemas.string().optional()
|
|
10373
10794
|
});
|
|
10374
10795
|
const TestDetectionRequestSchema = require_schemas.object({
|
|
10375
|
-
fingerprintId: require_schemas.string(),
|
|
10376
|
-
integrationTypes: require_schemas.array(IntegrationTypeSchema).optional()
|
|
10796
|
+
fingerprintId: require_schemas.string().uuid(),
|
|
10797
|
+
integrationTypes: require_schemas.array(IntegrationTypeSchema).min(1, "integrationTypes must list at least one integration type, or be omitted entirely").optional()
|
|
10377
10798
|
});
|
|
10378
10799
|
function generateTestId() {
|
|
10379
10800
|
return `test-${Date.now().toString(36)}-${Math.random().toString(36).substring(2, 8)}`;
|
|
@@ -10862,7 +11283,8 @@ const ADMIN_OVERVIEW_SECTIONS = [
|
|
|
10862
11283
|
"installations",
|
|
10863
11284
|
"traffic",
|
|
10864
11285
|
"lists",
|
|
10865
|
-
"hiAi"
|
|
11286
|
+
"hiAi",
|
|
11287
|
+
"accounts"
|
|
10866
11288
|
];
|
|
10867
11289
|
/** Cache states a section can report in `meta.cache.status`. */
|
|
10868
11290
|
const ADMIN_OVERVIEW_CACHE_STATUSES = [
|
|
@@ -10883,6 +11305,51 @@ const SERVICE_TRAFFIC_KEYS = [
|
|
|
10883
11305
|
"mixed",
|
|
10884
11306
|
"none"
|
|
10885
11307
|
];
|
|
11308
|
+
/**
|
|
11309
|
+
* Headline numbers that show "N counted · M excluded" and open a drill-down
|
|
11310
|
+
* of every account behind them. The first five mirror the ladder steps
|
|
11311
|
+
* (signedIn is the ladder's signedInProxy); the last three are the KYA-1147
|
|
11312
|
+
* people numbers.
|
|
11313
|
+
*/
|
|
11314
|
+
const ADMIN_TRUSTED_METRICS = [
|
|
11315
|
+
"emailsCollected",
|
|
11316
|
+
"users",
|
|
11317
|
+
"signedIn",
|
|
11318
|
+
"onboarded",
|
|
11319
|
+
"activated",
|
|
11320
|
+
"activeUsers",
|
|
11321
|
+
"peopleInOrgs",
|
|
11322
|
+
"installedOrgs"
|
|
11323
|
+
];
|
|
11324
|
+
/**
|
|
11325
|
+
* Why an account a user-level exclusion did not catch is still left out:
|
|
11326
|
+
* every org that would count it is test-named (`test_org`), or, for an org
|
|
11327
|
+
* row, none of its members is a counted person (`no_counted_members`).
|
|
11328
|
+
*/
|
|
11329
|
+
const ADMIN_ORG_EXCLUSION_REASONS = ["test_org", "no_counted_members"];
|
|
11330
|
+
/** `counted`, or the first rule that left the account out (user buckets take precedence). */
|
|
11331
|
+
const ADMIN_ACCOUNT_STATUSES = [
|
|
11332
|
+
"counted",
|
|
11333
|
+
...EXCLUSION_BUCKETS,
|
|
11334
|
+
...ADMIN_ORG_EXCLUSION_REASONS
|
|
11335
|
+
];
|
|
11336
|
+
/** GET /api/admin/overview/accounts query. */
|
|
11337
|
+
/** Drill-down status filter: everyone, any exclusion, or one status. */
|
|
11338
|
+
const ADMIN_ACCOUNTS_STATUS_FILTERS = [
|
|
11339
|
+
"all",
|
|
11340
|
+
"excluded",
|
|
11341
|
+
...ADMIN_ACCOUNT_STATUSES
|
|
11342
|
+
];
|
|
11343
|
+
/**
|
|
11344
|
+
* GET /api/admin/overview/accounts query. `status` filters on the server,
|
|
11345
|
+
* so the row cap applies to the filtered list and an exclusion is never cut
|
|
11346
|
+
* off by counted rows.
|
|
11347
|
+
*/
|
|
11348
|
+
const adminAccountsQuerySchema = require_schemas.object({
|
|
11349
|
+
metric: require_schemas._enum(ADMIN_TRUSTED_METRICS),
|
|
11350
|
+
window: require_schemas._enum(ADMIN_OVERVIEW_WINDOWS).default("30d"),
|
|
11351
|
+
status: require_schemas._enum(ADMIN_ACCOUNTS_STATUS_FILTERS).default("all")
|
|
11352
|
+
});
|
|
10886
11353
|
|
|
10887
11354
|
//#endregion
|
|
10888
11355
|
//#region src/types/api.ts
|
|
@@ -11681,6 +12148,35 @@ const RecommendationGenerationSchema = require_schemas.object({
|
|
|
11681
12148
|
forceRefresh: require_schemas.boolean().optional().default(false)
|
|
11682
12149
|
});
|
|
11683
12150
|
|
|
12151
|
+
//#endregion
|
|
12152
|
+
//#region src/schemas/consent-policy-endpoint.ts
|
|
12153
|
+
/**
|
|
12154
|
+
* Wire shape of `GET /api/v1/kya-os/consent-policy`, defined once here. The
|
|
12155
|
+
* response is the project's consent policy as a client needs to render and
|
|
12156
|
+
* pre-check it; it is authenticated with the project API key.
|
|
12157
|
+
*
|
|
12158
|
+
* `etag` is the BARE hash (lowercase hex). The HTTP `ETag` header carries the
|
|
12159
|
+
* same value as a quoted strong validator, `"<etag>"`, on 200 and 304.
|
|
12160
|
+
* `riskLevel` is ConsentConfig's capability risk set, unchanged.
|
|
12161
|
+
*/
|
|
12162
|
+
const ConsentPolicyRiskLevelSchema = require_schemas._enum([
|
|
12163
|
+
"low",
|
|
12164
|
+
"medium",
|
|
12165
|
+
"high",
|
|
12166
|
+
"critical"
|
|
12167
|
+
]);
|
|
12168
|
+
const ConsentPolicyCapabilitySchema = require_schemas.strictObject({
|
|
12169
|
+
scope: require_schemas.string().min(1),
|
|
12170
|
+
defaultOn: require_schemas.boolean(),
|
|
12171
|
+
riskLevel: ConsentPolicyRiskLevelSchema
|
|
12172
|
+
});
|
|
12173
|
+
const ConsentPolicyResponseSchema = require_schemas.strictObject({
|
|
12174
|
+
allowedScopes: require_schemas.array(require_schemas.string().min(1)).optional(),
|
|
12175
|
+
maxGrantSeconds: require_schemas.number().int().positive().optional(),
|
|
12176
|
+
capabilities: require_schemas.array(ConsentPolicyCapabilitySchema).optional(),
|
|
12177
|
+
etag: require_schemas.string().regex(/^[0-9a-f]{64}$/)
|
|
12178
|
+
});
|
|
12179
|
+
|
|
11684
12180
|
//#endregion
|
|
11685
12181
|
//#region src/wire/gateway-internal-tools.ts
|
|
11686
12182
|
/**
|
|
@@ -11833,20 +12329,14 @@ function isPrivateOrReservedHost(hostname) {
|
|
|
11833
12329
|
* octal/hex-encoded SSRF bypasses like `0177.0.0.01` → `127.0.0.1`.
|
|
11834
12330
|
*/
|
|
11835
12331
|
function parseIPv4Octet(part) {
|
|
11836
|
-
if (/^0x[0-9a-f]+$/i.test(part))
|
|
11837
|
-
|
|
11838
|
-
return Number.isNaN(n) ? null : n;
|
|
11839
|
-
}
|
|
11840
|
-
if (/^0[0-7]+$/.test(part)) {
|
|
11841
|
-
const n = parseInt(part, 8);
|
|
11842
|
-
return Number.isNaN(n) ? null : n;
|
|
11843
|
-
}
|
|
12332
|
+
if (/^0x[0-9a-f]+$/i.test(part)) return parseInt(part, 16);
|
|
12333
|
+
if (/^0[0-7]+$/.test(part)) return parseInt(part, 8);
|
|
11844
12334
|
if (/^(0|[1-9]\d*)$/.test(part)) return parseInt(part, 10);
|
|
11845
12335
|
return null;
|
|
11846
12336
|
}
|
|
11847
12337
|
function isPrivateIPv4(ip) {
|
|
11848
12338
|
const parts = ip.split(".").map(Number);
|
|
11849
|
-
if (parts.
|
|
12339
|
+
if (parts.some((p) => p > 255)) return false;
|
|
11850
12340
|
const [a, b] = parts;
|
|
11851
12341
|
if (a === 0) return true;
|
|
11852
12342
|
if (a === 127) return true;
|
|
@@ -11955,7 +12445,8 @@ const upstreamServerSchema = require_schemas.object({
|
|
|
11955
12445
|
});
|
|
11956
12446
|
/**
|
|
11957
12447
|
* Input variant — id/slug optional for new upstreams (auto-generated by PUT
|
|
11958
|
-
* handler). Also omits
|
|
12448
|
+
* handler). Also omits server-managed project ownership and the two
|
|
12449
|
+
* server-managed static-headers fields:
|
|
11959
12450
|
* `staticHeadersEncrypted` (ciphertext — clients never author this
|
|
11960
12451
|
* directly) and `staticHeaderKeys` (a read-only projection echoed back on
|
|
11961
12452
|
* GET/PUT responses). The plaintext `staticHeaders` field is intentionally
|
|
@@ -11963,6 +12454,7 @@ const upstreamServerSchema = require_schemas.object({
|
|
|
11963
12454
|
* values; the PUT handler encrypts it before persisting.
|
|
11964
12455
|
*/
|
|
11965
12456
|
const upstreamServerInputSchema = upstreamServerSchema.omit({
|
|
12457
|
+
projectId: true,
|
|
11966
12458
|
staticHeadersEncrypted: true,
|
|
11967
12459
|
staticHeaderKeys: true
|
|
11968
12460
|
}).extend({
|
|
@@ -14366,13 +14858,21 @@ const PolicyConfigSchema = require_schemas.object({
|
|
|
14366
14858
|
* Trusted Layer-2 delegation root DIDs for the project's org (P2 / DR-1),
|
|
14367
14859
|
* server-resolved by the policy API. A consuming middleware forwards these
|
|
14368
14860
|
* into the engine's `ContextSpec.trustedDelegationRoots` so L2 delegation
|
|
14369
|
-
* chains are pinned to the org DID. Absent ⇒ omitted
|
|
14370
|
-
*
|
|
14861
|
+
* chains are pinned to the org DID. Absent ⇒ omitted, and the engine rejects
|
|
14862
|
+
* delegation. Optional (no default)
|
|
14371
14863
|
* so a policy without the field round-trips as `undefined`, matching the
|
|
14372
14864
|
* policy API's `PolicyResponse` shape and the orchestrator's omit-when-unset
|
|
14373
14865
|
* contract.
|
|
14374
14866
|
*/
|
|
14375
|
-
trustedDelegationRoots: require_schemas.array(require_schemas.string()).optional()
|
|
14867
|
+
trustedDelegationRoots: require_schemas.array(require_schemas.string()).optional(),
|
|
14868
|
+
/**
|
|
14869
|
+
* The org's one OAuth authorization server issuer (RFC 8414 `issuer`), as the
|
|
14870
|
+
* platform's IssuerContext computes it (`https://<branded host or platform>/oauth/<slug>`).
|
|
14871
|
+
* A middleware that serves protected resource metadata advertises exactly
|
|
14872
|
+
* this in `authorization_servers` and never builds an issuer URL itself.
|
|
14873
|
+
* Absent ⇒ the platform could not resolve the org; serve no metadata.
|
|
14874
|
+
*/
|
|
14875
|
+
authorizationServerIssuer: require_schemas.string().url().optional()
|
|
14376
14876
|
});
|
|
14377
14877
|
const PolicyEvaluationContextSchema = require_schemas.object({
|
|
14378
14878
|
agentType: require_schemas.string().optional(),
|
|
@@ -14414,6 +14914,9 @@ const PolicyEvaluationResultSchema = require_schemas.object({
|
|
|
14414
14914
|
/** What type of match triggered this decision */
|
|
14415
14915
|
matchType: PolicyMatchTypeSchema
|
|
14416
14916
|
});
|
|
14917
|
+
function isEngineEnforcing(flags) {
|
|
14918
|
+
return flags.engineEnforcementEnabled === true && flags.enabled !== false;
|
|
14919
|
+
}
|
|
14417
14920
|
/**
|
|
14418
14921
|
* Validate and parse a policy configuration
|
|
14419
14922
|
*/
|
|
@@ -14434,6 +14937,20 @@ function parseEvaluationContext(data) {
|
|
|
14434
14937
|
return PolicyEvaluationContextSchema.parse(data);
|
|
14435
14938
|
}
|
|
14436
14939
|
|
|
14940
|
+
//#endregion
|
|
14941
|
+
//#region src/policy/fail-closed-response.ts
|
|
14942
|
+
const FAIL_CLOSED_STATUS = 503;
|
|
14943
|
+
const FAIL_CLOSED_RETRY_AFTER_SECONDS = 3;
|
|
14944
|
+
const FAIL_CLOSED_BODY = {
|
|
14945
|
+
error: "Service temporarily unavailable",
|
|
14946
|
+
source: "checkpoint-middleware"
|
|
14947
|
+
};
|
|
14948
|
+
const FAIL_CLOSED_HEADERS = {
|
|
14949
|
+
"Content-Type": "application/json",
|
|
14950
|
+
"Cache-Control": "no-store",
|
|
14951
|
+
"Retry-After": String(3)
|
|
14952
|
+
};
|
|
14953
|
+
|
|
14437
14954
|
//#endregion
|
|
14438
14955
|
//#region src/policy/evaluator.ts
|
|
14439
14956
|
/**
|
|
@@ -14678,6 +15195,44 @@ function createResult(action, reason, matchType, extras) {
|
|
|
14678
15195
|
};
|
|
14679
15196
|
}
|
|
14680
15197
|
|
|
15198
|
+
//#endregion
|
|
15199
|
+
//#region src/policy/cedar-mask.ts
|
|
15200
|
+
const blank = (char) => char === "\n" || char === "\r" ? char : " ";
|
|
15201
|
+
function maskCedar(cedar) {
|
|
15202
|
+
const visible = cedar.split("");
|
|
15203
|
+
const code = cedar.split("");
|
|
15204
|
+
const inString = new Array(cedar.length).fill(false);
|
|
15205
|
+
let i = 0;
|
|
15206
|
+
while (i < cedar.length) if (cedar[i] === "\"") {
|
|
15207
|
+
let end = i + 1;
|
|
15208
|
+
while (end < cedar.length && cedar[end] !== "\"") end += cedar[end] === "\\" ? 2 : 1;
|
|
15209
|
+
const bodyEnd = Math.min(end, cedar.length);
|
|
15210
|
+
for (let k = i + 1; k < bodyEnd; k++) {
|
|
15211
|
+
inString[k] = true;
|
|
15212
|
+
code[k] = blank(cedar[k]);
|
|
15213
|
+
}
|
|
15214
|
+
i = end + 1;
|
|
15215
|
+
} else if (cedar[i] === "/" && cedar[i + 1] === "/") while (i < cedar.length && cedar[i] !== "\n" && cedar[i] !== "\r") {
|
|
15216
|
+
visible[i] = " ";
|
|
15217
|
+
code[i] = " ";
|
|
15218
|
+
i++;
|
|
15219
|
+
}
|
|
15220
|
+
else i++;
|
|
15221
|
+
return {
|
|
15222
|
+
visible: visible.join(""),
|
|
15223
|
+
code: code.join(""),
|
|
15224
|
+
inString
|
|
15225
|
+
};
|
|
15226
|
+
}
|
|
15227
|
+
|
|
15228
|
+
//#endregion
|
|
15229
|
+
//#region src/policy/cedar-space.ts
|
|
15230
|
+
const CEDAR_SPACE_CLASS = "[\\t-\\r \\u0085\\u00a0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000]";
|
|
15231
|
+
function isCedarSpace(char) {
|
|
15232
|
+
const code = char.charCodeAt(0);
|
|
15233
|
+
return code >= 9 && code <= 13 || code === 32 || code === 133 || code === 160 || code === 5760 || code >= 8192 && code <= 8202 || code === 8232 || code === 8233 || code === 8239 || code === 8287 || code === 12288;
|
|
15234
|
+
}
|
|
15235
|
+
|
|
14681
15236
|
//#endregion
|
|
14682
15237
|
//#region src/policy/cedar-string.ts
|
|
14683
15238
|
/**
|
|
@@ -14705,6 +15260,1041 @@ function unescapeCedarString(value) {
|
|
|
14705
15260
|
function cedarQuotedValueRegExp(prefixSource, flags = "") {
|
|
14706
15261
|
return new RegExp(`${prefixSource}"((?:\\\\.|[^"\\\\])*)"`, flags);
|
|
14707
15262
|
}
|
|
15263
|
+
const LIKE_ESCAPES = {
|
|
15264
|
+
n: "\n",
|
|
15265
|
+
r: "\r",
|
|
15266
|
+
t: " ",
|
|
15267
|
+
"0": "\0"
|
|
15268
|
+
};
|
|
15269
|
+
const NUMERIC_ESCAPE = /x([0-9a-fA-F]{2})|u\{([0-9a-fA-F][0-9a-fA-F_]*)\}/y;
|
|
15270
|
+
const MAX_CODE_POINT = 1114111;
|
|
15271
|
+
const MAX_UNICODE_DIGITS = 6;
|
|
15272
|
+
function numericEscapeCode(raw, at) {
|
|
15273
|
+
NUMERIC_ESCAPE.lastIndex = at;
|
|
15274
|
+
const match = NUMERIC_ESCAPE.exec(raw);
|
|
15275
|
+
if (match === null) return null;
|
|
15276
|
+
if (match[1] !== void 0) return {
|
|
15277
|
+
code: parseInt(match[1], 16),
|
|
15278
|
+
length: match[0].length
|
|
15279
|
+
};
|
|
15280
|
+
const digits = match[2].replace(/_/g, "");
|
|
15281
|
+
const code = parseInt(digits, 16);
|
|
15282
|
+
return digits.length <= MAX_UNICODE_DIGITS && code <= MAX_CODE_POINT && (code < 55296 || code > 57343) ? {
|
|
15283
|
+
code,
|
|
15284
|
+
length: match[0].length
|
|
15285
|
+
} : null;
|
|
15286
|
+
}
|
|
15287
|
+
function cedarLikeSegments(rawPattern) {
|
|
15288
|
+
const segments = [""];
|
|
15289
|
+
const append = (char) => {
|
|
15290
|
+
if (char === "*") segments.push("");
|
|
15291
|
+
else segments[segments.length - 1] += char;
|
|
15292
|
+
};
|
|
15293
|
+
for (let i = 0; i < rawPattern.length; i++) {
|
|
15294
|
+
const char = rawPattern.charAt(i);
|
|
15295
|
+
if (char !== "\\") {
|
|
15296
|
+
append(char);
|
|
15297
|
+
continue;
|
|
15298
|
+
}
|
|
15299
|
+
const numeric = numericEscapeCode(rawPattern, i + 1);
|
|
15300
|
+
if (numeric !== null) {
|
|
15301
|
+
append(String.fromCodePoint(numeric.code));
|
|
15302
|
+
i += numeric.length;
|
|
15303
|
+
} else {
|
|
15304
|
+
const next = rawPattern.charAt(++i);
|
|
15305
|
+
segments[segments.length - 1] += LIKE_ESCAPES[next] ?? next;
|
|
15306
|
+
}
|
|
15307
|
+
}
|
|
15308
|
+
return segments;
|
|
15309
|
+
}
|
|
15310
|
+
function globMatches(segments, value) {
|
|
15311
|
+
const first = segments[0];
|
|
15312
|
+
if (segments.length === 1) return value === first;
|
|
15313
|
+
const last = segments[segments.length - 1];
|
|
15314
|
+
const end = value.length - last.length;
|
|
15315
|
+
if (end < first.length || !value.startsWith(first) || !value.endsWith(last)) return false;
|
|
15316
|
+
let position = first.length;
|
|
15317
|
+
for (let i = 1; i < segments.length - 1; i++) {
|
|
15318
|
+
const at = value.indexOf(segments[i], position);
|
|
15319
|
+
if (at === -1 || at + segments[i].length > end) return false;
|
|
15320
|
+
position = at + segments[i].length;
|
|
15321
|
+
}
|
|
15322
|
+
return true;
|
|
15323
|
+
}
|
|
15324
|
+
|
|
15325
|
+
//#endregion
|
|
15326
|
+
//#region src/policy/legacy-carve-out.ts
|
|
15327
|
+
const NO_EVIDENCE_CATEGORY = "no_evidence";
|
|
15328
|
+
const NO_EVIDENCE_EXCLUSION_TERM = `principal.category != "${NO_EVIDENCE_CATEGORY}"`;
|
|
15329
|
+
const NO_EVIDENCE_EQUALITY_TERM = `principal.category == "${NO_EVIDENCE_CATEGORY}"`;
|
|
15330
|
+
const WS = `${CEDAR_SPACE_CLASS}*`;
|
|
15331
|
+
const SEGMENT_BOUNDARY = new RegExp(`\\b(?:forbid|permit)${WS}\\(|;`, "g");
|
|
15332
|
+
const ACCESSOR = `(?:\\.${WS}category\\b|\\[${WS}"C[^"]*"${WS}\\])`;
|
|
15333
|
+
const SUBJECT = `(?<![.\\w])principal${WS}${ACCESSOR}`;
|
|
15334
|
+
const EXACT = "\"E[^\"]*\"";
|
|
15335
|
+
const LIKEABLE = "\"[EL][^\"]*\"";
|
|
15336
|
+
const ELEMENTS = `[^\\]\\[]*(?:\\[${WS}"[^"]*"${WS}\\][^\\]\\[]*){0,16}`;
|
|
15337
|
+
const CATEGORY_READ = new RegExp(`(?<![.\\w])principal(?:${WS}\\))*${WS}${ACCESSOR}`, "g");
|
|
15338
|
+
const GROUP_OR_PRINCIPAL = /[()[\]{}]|(?<![\w.])principal(?!\w)/g;
|
|
15339
|
+
const CHAIN_LINK = new RegExp(`${WS}(?:\\.${WS}(category\\b)|\\.${WS}\\w+|\\[${WS}"(C)?[^"]*"${WS}\\])`, "y");
|
|
15340
|
+
const PRINCIPAL_LENGTH = 9;
|
|
15341
|
+
const BARE_GROUP = new RegExp(`^(?:\\(|${CEDAR_SPACE_CLASS})*$`);
|
|
15342
|
+
const CATEGORY_COMPARED = new RegExp(`${SUBJECT}${WS}(?:(?:==|!=)${WS}${EXACT}|like${WS}${LIKEABLE})|${EXACT}${WS}(?:==|!=)${WS}${SUBJECT}`);
|
|
15343
|
+
const LIST_CALL = new RegExp(`\\[(${ELEMENTS})\\]${WS}\\.${WS}contains(?:All|Any)?${WS}(?:(${SUBJECT})|(${EXACT})|\\[(${ELEMENTS})\\])`, "g");
|
|
15344
|
+
const HAS_CATEGORY = new RegExp(SUBJECT);
|
|
15345
|
+
const HAS_NO_EVIDENCE = new RegExp(EXACT);
|
|
15346
|
+
const SUBSTITUTED_READ = new RegExp(`\\(if ((?:\\(|${CEDAR_SPACE_CLASS})*principal(?:\\)|${CEDAR_SPACE_CLASS})*(?:\\.${WS}category\\b|\\[${WS}("(?:\\\\.|[^"\\\\])*")${WS}\\])) == "${NO_EVIDENCE_CATEGORY}" then "human" else \\1\\)`, "g");
|
|
15347
|
+
function literalMarker(body) {
|
|
15348
|
+
const segments = cedarLikeSegments(body);
|
|
15349
|
+
if (segments.length === 1) {
|
|
15350
|
+
if (segments[0] === "no_evidence") return "E";
|
|
15351
|
+
return segments[0] === "category" ? "C" : " ";
|
|
15352
|
+
}
|
|
15353
|
+
return segments.some((segment) => segment.includes("no_evidence")) && globMatches(segments, "no_evidence") ? "L" : " ";
|
|
15354
|
+
}
|
|
15355
|
+
function scan(cedar) {
|
|
15356
|
+
const { visible, code, inString } = maskCedar(cedar);
|
|
15357
|
+
const marked = code.split("");
|
|
15358
|
+
for (let start = 0; start < cedar.length;) {
|
|
15359
|
+
if (!inString[start]) {
|
|
15360
|
+
start++;
|
|
15361
|
+
continue;
|
|
15362
|
+
}
|
|
15363
|
+
let end = start;
|
|
15364
|
+
while (end < cedar.length && inString[end]) end++;
|
|
15365
|
+
const marker = literalMarker(visible.slice(start, end));
|
|
15366
|
+
if (marker !== " ") marked[start] = marker;
|
|
15367
|
+
start = end;
|
|
15368
|
+
}
|
|
15369
|
+
const text = marked.join("");
|
|
15370
|
+
return {
|
|
15371
|
+
visible,
|
|
15372
|
+
text,
|
|
15373
|
+
flat: text.replace(/[()]/g, " "),
|
|
15374
|
+
pairs: pairParentheses(text)
|
|
15375
|
+
};
|
|
15376
|
+
}
|
|
15377
|
+
function pairParentheses(text) {
|
|
15378
|
+
const pairs = new Int32Array(text.length).fill(-1);
|
|
15379
|
+
const open = [];
|
|
15380
|
+
for (let i = 0; i < text.length; i++) if (text[i] === "(") open.push(i);
|
|
15381
|
+
else if (text[i] === ")") pairs[i] = open.pop() ?? -1;
|
|
15382
|
+
return pairs;
|
|
15383
|
+
}
|
|
15384
|
+
function statementRanges(text) {
|
|
15385
|
+
const ranges = [];
|
|
15386
|
+
let open = -1;
|
|
15387
|
+
for (const boundary of text.matchAll(SEGMENT_BOUNDARY)) if (boundary[0] === ";") {
|
|
15388
|
+
if (open !== -1) ranges.push([open, boundary.index + 1]);
|
|
15389
|
+
open = -1;
|
|
15390
|
+
} else {
|
|
15391
|
+
if (open !== -1) ranges.push([open, boundary.index]);
|
|
15392
|
+
open = boundary.index;
|
|
15393
|
+
}
|
|
15394
|
+
if (open !== -1) ranges.push([open, text.length]);
|
|
15395
|
+
return ranges;
|
|
15396
|
+
}
|
|
15397
|
+
function applyEdits(cedar, edits) {
|
|
15398
|
+
if (edits.length === 0) return cedar;
|
|
15399
|
+
const pieces = [];
|
|
15400
|
+
let position = 0;
|
|
15401
|
+
for (const edit of edits) {
|
|
15402
|
+
pieces.push(cedar.slice(position, edit.start), edit.text);
|
|
15403
|
+
position = edit.end;
|
|
15404
|
+
}
|
|
15405
|
+
pieces.push(cedar.slice(position));
|
|
15406
|
+
return pieces.join("");
|
|
15407
|
+
}
|
|
15408
|
+
function namesNoEvidenceIn(flat) {
|
|
15409
|
+
if (CATEGORY_COMPARED.test(flat)) return true;
|
|
15410
|
+
for (const [, receiver, subject, exact, list = ""] of flat.matchAll(LIST_CALL)) {
|
|
15411
|
+
const receiverReadsCategory = HAS_CATEGORY.test(receiver);
|
|
15412
|
+
const receiverNamesNoEvidence = HAS_NO_EVIDENCE.test(receiver);
|
|
15413
|
+
if (receiverReadsCategory && (exact !== void 0 || HAS_NO_EVIDENCE.test(list)) || receiverNamesNoEvidence && (subject !== void 0 || HAS_CATEGORY.test(list))) return true;
|
|
15414
|
+
}
|
|
15415
|
+
return false;
|
|
15416
|
+
}
|
|
15417
|
+
function namesNoEvidence(cedar) {
|
|
15418
|
+
return namesNoEvidenceIn(scan(cedar).flat);
|
|
15419
|
+
}
|
|
15420
|
+
function groupStart({ text, pairs }, principal, read) {
|
|
15421
|
+
const lastCloser = read.lastIndexOf(")");
|
|
15422
|
+
if (lastCloser === -1) return principal;
|
|
15423
|
+
const open = pairs[principal + lastCloser];
|
|
15424
|
+
return open !== -1 && BARE_GROUP.test(text.slice(open, principal)) ? open : -1;
|
|
15425
|
+
}
|
|
15426
|
+
const isWordChar = (char) => char !== void 0 && /\w/.test(char);
|
|
15427
|
+
function skipSpaceBack(text, from) {
|
|
15428
|
+
let i = from;
|
|
15429
|
+
while (i >= 0 && isCedarSpace(text[i])) i--;
|
|
15430
|
+
return i;
|
|
15431
|
+
}
|
|
15432
|
+
function skipSpaceForward(text, from) {
|
|
15433
|
+
let i = from;
|
|
15434
|
+
while (i < text.length && isCedarSpace(text[i])) i++;
|
|
15435
|
+
return i;
|
|
15436
|
+
}
|
|
15437
|
+
function wordEndingAt(text, end) {
|
|
15438
|
+
let start = end;
|
|
15439
|
+
while (start > 0 && isWordChar(text[start - 1])) start--;
|
|
15440
|
+
return text.slice(start, end + 1);
|
|
15441
|
+
}
|
|
15442
|
+
function isPrincipalVariable(text, at) {
|
|
15443
|
+
const before = skipSpaceBack(text, at - 1);
|
|
15444
|
+
const char = text[before];
|
|
15445
|
+
if (char === "." || char === "?") return false;
|
|
15446
|
+
if (char === ":" && text[before - 1] === ":") return false;
|
|
15447
|
+
if (isWordChar(char) && wordEndingAt(text, before) === "has") return false;
|
|
15448
|
+
return text[skipSpaceForward(text, at + PRINCIPAL_LENGTH)] !== ":";
|
|
15449
|
+
}
|
|
15450
|
+
function isBranchValue(text, at) {
|
|
15451
|
+
let before = skipSpaceBack(text, at - 1);
|
|
15452
|
+
while (text[before] === "(") before = skipSpaceBack(text, before - 1);
|
|
15453
|
+
const char = text[before];
|
|
15454
|
+
const word = isWordChar(char) ? wordEndingAt(text, before) : "";
|
|
15455
|
+
const introduced = word === "then" || word === "else" || char === ":" && text[before - 1] !== ":";
|
|
15456
|
+
const after = skipSpaceForward(text, at + PRINCIPAL_LENGTH);
|
|
15457
|
+
const next = text[after];
|
|
15458
|
+
const ends = next === ")" || next === "}" || next === "]" || next === "," || text.startsWith("else", after) && !isWordChar(text[after + 4]);
|
|
15459
|
+
return introduced && ends;
|
|
15460
|
+
}
|
|
15461
|
+
function headEnd(text, from, to) {
|
|
15462
|
+
let depth = 0;
|
|
15463
|
+
for (let i = text.indexOf("(", from); i < to; i++) if (text[i] === "(") depth++;
|
|
15464
|
+
else if (text[i] === ")" && --depth === 0) return i + 1;
|
|
15465
|
+
return from;
|
|
15466
|
+
}
|
|
15467
|
+
function directReads(scanned, from, to) {
|
|
15468
|
+
const reads = [];
|
|
15469
|
+
for (const read of scanned.text.slice(from, to).matchAll(CATEGORY_READ)) {
|
|
15470
|
+
const principal = from + read.index;
|
|
15471
|
+
if (!isPrincipalVariable(scanned.text, principal)) continue;
|
|
15472
|
+
const start = groupStart(scanned, principal, read[0]);
|
|
15473
|
+
if (start !== -1) reads.push({
|
|
15474
|
+
principal,
|
|
15475
|
+
start,
|
|
15476
|
+
end: principal + read[0].length
|
|
15477
|
+
});
|
|
15478
|
+
}
|
|
15479
|
+
return reads;
|
|
15480
|
+
}
|
|
15481
|
+
function readsCategoryAfter(text, from) {
|
|
15482
|
+
CHAIN_LINK.lastIndex = from;
|
|
15483
|
+
for (let link = CHAIN_LINK.exec(text); link !== null; link = CHAIN_LINK.exec(text)) if (link[1] !== void 0 || link[2] !== void 0) return true;
|
|
15484
|
+
return false;
|
|
15485
|
+
}
|
|
15486
|
+
function readsCategoryOfCarriedPrincipal(text, from, to, reads) {
|
|
15487
|
+
const direct = new Set(reads.map((read) => read.principal));
|
|
15488
|
+
const holding = [false];
|
|
15489
|
+
for (const token of text.slice(from, to).matchAll(GROUP_OR_PRINCIPAL)) {
|
|
15490
|
+
const at = from + token.index;
|
|
15491
|
+
if (token[0] === "principal") {
|
|
15492
|
+
if (!direct.has(at) && isPrincipalVariable(text, at) && isBranchValue(text, at)) holding[holding.length - 1] = true;
|
|
15493
|
+
} else if ("([{".includes(token[0])) holding.push(false);
|
|
15494
|
+
else if (holding.length > 1 && holding.pop()) {
|
|
15495
|
+
holding[holding.length - 1] = true;
|
|
15496
|
+
if (readsCategoryAfter(text, at + 1)) return true;
|
|
15497
|
+
}
|
|
15498
|
+
}
|
|
15499
|
+
return false;
|
|
15500
|
+
}
|
|
15501
|
+
function withNoEvidenceExclusion(cedar) {
|
|
15502
|
+
const scanned = scan(cedar);
|
|
15503
|
+
const { visible, text, flat } = scanned;
|
|
15504
|
+
const edits = [];
|
|
15505
|
+
for (const [from, to] of statementRanges(text)) {
|
|
15506
|
+
if (namesNoEvidenceIn(flat.slice(from, to))) continue;
|
|
15507
|
+
const reads = directReads(scanned, from, to);
|
|
15508
|
+
if (reads.length === 0) continue;
|
|
15509
|
+
if (readsCategoryOfCarriedPrincipal(text, headEnd(text, from, to), to, reads)) continue;
|
|
15510
|
+
for (const { start, end } of reads) {
|
|
15511
|
+
const accessor = visible.slice(start, end);
|
|
15512
|
+
edits.push({
|
|
15513
|
+
start,
|
|
15514
|
+
end,
|
|
15515
|
+
text: `(if ${accessor} == "${NO_EVIDENCE_CATEGORY}" then "human" else ${accessor})`
|
|
15516
|
+
});
|
|
15517
|
+
}
|
|
15518
|
+
}
|
|
15519
|
+
return applyEdits(cedar, edits);
|
|
15520
|
+
}
|
|
15521
|
+
function withoutNoEvidenceExclusion(cedar) {
|
|
15522
|
+
const { visible, inString } = maskCedar(cedar);
|
|
15523
|
+
const edits = [];
|
|
15524
|
+
for (const read of visible.matchAll(SUBSTITUTED_READ)) {
|
|
15525
|
+
const key = read[2];
|
|
15526
|
+
if (!inString[read.index] && (key === void 0 || literalMarker(key.slice(1, -1)) === "C")) edits.push({
|
|
15527
|
+
start: read.index,
|
|
15528
|
+
end: read.index + read[0].length,
|
|
15529
|
+
text: read[1]
|
|
15530
|
+
});
|
|
15531
|
+
}
|
|
15532
|
+
return applyEdits(cedar, edits);
|
|
15533
|
+
}
|
|
15534
|
+
|
|
15535
|
+
//#endregion
|
|
15536
|
+
//#region src/policy/cedar-expression.ts
|
|
15537
|
+
const MAX_NESTING = 48;
|
|
15538
|
+
const MAX_HEX_ESCAPE = 127;
|
|
15539
|
+
const UNNAMED_CATEGORY = "\ud800";
|
|
15540
|
+
const LONE_SURROGATE = /\p{Surrogate}/u;
|
|
15541
|
+
const HUMAN_NAMES = [
|
|
15542
|
+
"",
|
|
15543
|
+
"human",
|
|
15544
|
+
"unknown",
|
|
15545
|
+
"anonymous"
|
|
15546
|
+
];
|
|
15547
|
+
const UNKNOWN = { k: "unknown" };
|
|
15548
|
+
const PUNCTUATION = /* @__PURE__ */ new Set("<>!+-*()[]{}.,:");
|
|
15549
|
+
const TWO_CHARACTER = /* @__PURE__ */ new Set([
|
|
15550
|
+
"&&",
|
|
15551
|
+
"||",
|
|
15552
|
+
"==",
|
|
15553
|
+
"!=",
|
|
15554
|
+
"<=",
|
|
15555
|
+
">=",
|
|
15556
|
+
"::"
|
|
15557
|
+
]);
|
|
15558
|
+
const SIMPLE_ESCAPES = {
|
|
15559
|
+
n: "\n",
|
|
15560
|
+
r: "\r",
|
|
15561
|
+
t: " ",
|
|
15562
|
+
"\\": "\\",
|
|
15563
|
+
"0": "\0",
|
|
15564
|
+
"'": "'",
|
|
15565
|
+
"\"": "\""
|
|
15566
|
+
};
|
|
15567
|
+
const IDENTIFIER_START = /[A-Za-z_]/;
|
|
15568
|
+
const IDENTIFIER_PART = /[A-Za-z0-9_]/;
|
|
15569
|
+
const DIGIT = /[0-9]/;
|
|
15570
|
+
const UNSUPPORTED_PATTERN_ESCAPE = /\\[0u]/;
|
|
15571
|
+
function tokenize(text) {
|
|
15572
|
+
const tokens = [];
|
|
15573
|
+
let i = 0;
|
|
15574
|
+
while (i < text.length) {
|
|
15575
|
+
const char = text[i];
|
|
15576
|
+
if (isCedarSpace(char)) i += 1;
|
|
15577
|
+
else if (char === "/" && text[i + 1] === "/") while (i < text.length && text[i] !== "\n" && text[i] !== "\r") i += 1;
|
|
15578
|
+
else if (char === "\"") {
|
|
15579
|
+
let end = i + 1;
|
|
15580
|
+
while (end < text.length && text[end] !== "\"") end += text[end] === "\\" ? 2 : 1;
|
|
15581
|
+
if (end >= text.length) throw new SyntaxError("unterminated string");
|
|
15582
|
+
const body = text.slice(i + 1, end);
|
|
15583
|
+
if (LONE_SURROGATE.test(body)) throw new SyntaxError("ill-formed string");
|
|
15584
|
+
tokens.push({
|
|
15585
|
+
t: "str",
|
|
15586
|
+
v: body
|
|
15587
|
+
});
|
|
15588
|
+
i = end + 1;
|
|
15589
|
+
} else if (IDENTIFIER_START.test(char)) {
|
|
15590
|
+
let end = i + 1;
|
|
15591
|
+
while (end < text.length && IDENTIFIER_PART.test(text[end])) end += 1;
|
|
15592
|
+
tokens.push({
|
|
15593
|
+
t: "id",
|
|
15594
|
+
v: text.slice(i, end)
|
|
15595
|
+
});
|
|
15596
|
+
i = end;
|
|
15597
|
+
} else if (DIGIT.test(char)) {
|
|
15598
|
+
let end = i + 1;
|
|
15599
|
+
while (end < text.length && DIGIT.test(text[end])) end += 1;
|
|
15600
|
+
tokens.push({
|
|
15601
|
+
t: "num",
|
|
15602
|
+
v: text.slice(i, end)
|
|
15603
|
+
});
|
|
15604
|
+
i = end;
|
|
15605
|
+
} else if (TWO_CHARACTER.has(text.slice(i, i + 2))) {
|
|
15606
|
+
tokens.push({
|
|
15607
|
+
t: "p",
|
|
15608
|
+
v: text.slice(i, i + 2)
|
|
15609
|
+
});
|
|
15610
|
+
i += 2;
|
|
15611
|
+
} else if (PUNCTUATION.has(char)) {
|
|
15612
|
+
tokens.push({
|
|
15613
|
+
t: "p",
|
|
15614
|
+
v: char
|
|
15615
|
+
});
|
|
15616
|
+
i += 1;
|
|
15617
|
+
} else throw new SyntaxError("unexpected character");
|
|
15618
|
+
}
|
|
15619
|
+
return tokens;
|
|
15620
|
+
}
|
|
15621
|
+
function decodeCedarString(raw) {
|
|
15622
|
+
let out = "";
|
|
15623
|
+
for (let i = 0; i < raw.length; i += 1) if (raw[i] !== "\\") out += raw[i];
|
|
15624
|
+
else if (raw[i + 1] === "x" || raw[i + 1] === "u") {
|
|
15625
|
+
const numeric = numericEscapeCode(raw, i + 1);
|
|
15626
|
+
if (numeric === null || raw[i + 1] === "x" && numeric.code > MAX_HEX_ESCAPE) return null;
|
|
15627
|
+
out += String.fromCodePoint(numeric.code);
|
|
15628
|
+
i += numeric.length;
|
|
15629
|
+
} else {
|
|
15630
|
+
const mapped = SIMPLE_ESCAPES[raw[i + 1]];
|
|
15631
|
+
if (mapped === void 0) return null;
|
|
15632
|
+
out += mapped;
|
|
15633
|
+
i += 1;
|
|
15634
|
+
}
|
|
15635
|
+
return out;
|
|
15636
|
+
}
|
|
15637
|
+
var Parser = class {
|
|
15638
|
+
tokens;
|
|
15639
|
+
position = 0;
|
|
15640
|
+
readsTag = false;
|
|
15641
|
+
constructor(tokens) {
|
|
15642
|
+
this.tokens = tokens;
|
|
15643
|
+
}
|
|
15644
|
+
parseAll() {
|
|
15645
|
+
const expression = this.expression(0);
|
|
15646
|
+
if (this.position < this.tokens.length) throw new SyntaxError("trailing tokens");
|
|
15647
|
+
return this.readsTag ? UNKNOWN : expression;
|
|
15648
|
+
}
|
|
15649
|
+
peek() {
|
|
15650
|
+
return this.tokens[this.position];
|
|
15651
|
+
}
|
|
15652
|
+
is(type, value) {
|
|
15653
|
+
const token = this.peek();
|
|
15654
|
+
return token !== void 0 && token.t === type && token.v === value;
|
|
15655
|
+
}
|
|
15656
|
+
take(type, value) {
|
|
15657
|
+
const found = this.is(type, value);
|
|
15658
|
+
if (found) this.position += 1;
|
|
15659
|
+
return found;
|
|
15660
|
+
}
|
|
15661
|
+
expect(type, value) {
|
|
15662
|
+
if (!this.take(type, value)) throw new SyntaxError(`expected ${value}`);
|
|
15663
|
+
}
|
|
15664
|
+
next(type) {
|
|
15665
|
+
const token = this.peek();
|
|
15666
|
+
if (token === void 0 || token.t !== type) throw new SyntaxError(`expected ${type}`);
|
|
15667
|
+
this.position += 1;
|
|
15668
|
+
return token;
|
|
15669
|
+
}
|
|
15670
|
+
expression(depth) {
|
|
15671
|
+
if (depth > MAX_NESTING) throw new SyntaxError("too deep");
|
|
15672
|
+
if (this.take("id", "if")) {
|
|
15673
|
+
const cond = this.expression(depth + 1);
|
|
15674
|
+
this.expect("id", "then");
|
|
15675
|
+
const then = this.expression(depth + 1);
|
|
15676
|
+
this.expect("id", "else");
|
|
15677
|
+
return {
|
|
15678
|
+
k: "if",
|
|
15679
|
+
cond,
|
|
15680
|
+
then,
|
|
15681
|
+
otherwise: this.expression(depth + 1)
|
|
15682
|
+
};
|
|
15683
|
+
}
|
|
15684
|
+
return this.chain("||", () => this.chain("&&", () => this.relation(depth)));
|
|
15685
|
+
}
|
|
15686
|
+
chain(operator, operand) {
|
|
15687
|
+
const terms = [operand()];
|
|
15688
|
+
while (this.take("p", operator)) terms.push(operand());
|
|
15689
|
+
return terms.length === 1 ? terms[0] : {
|
|
15690
|
+
k: operator === "&&" ? "and" : "or",
|
|
15691
|
+
terms
|
|
15692
|
+
};
|
|
15693
|
+
}
|
|
15694
|
+
relation(depth) {
|
|
15695
|
+
const left = this.additive(depth);
|
|
15696
|
+
const token = this.peek();
|
|
15697
|
+
if (token === void 0) return left;
|
|
15698
|
+
if (token.t === "p" && (token.v === "==" || token.v === "!=")) {
|
|
15699
|
+
this.position += 1;
|
|
15700
|
+
return {
|
|
15701
|
+
k: "cmp",
|
|
15702
|
+
equals: token.v === "==",
|
|
15703
|
+
left,
|
|
15704
|
+
right: this.additive(depth)
|
|
15705
|
+
};
|
|
15706
|
+
}
|
|
15707
|
+
if (token.t === "p" && [
|
|
15708
|
+
"<",
|
|
15709
|
+
"<=",
|
|
15710
|
+
">",
|
|
15711
|
+
">="
|
|
15712
|
+
].includes(token.v)) {
|
|
15713
|
+
this.position += 1;
|
|
15714
|
+
this.additive(depth);
|
|
15715
|
+
return UNKNOWN;
|
|
15716
|
+
}
|
|
15717
|
+
if (token.t === "id" && token.v === "in") {
|
|
15718
|
+
this.position += 1;
|
|
15719
|
+
this.additive(depth);
|
|
15720
|
+
return UNKNOWN;
|
|
15721
|
+
}
|
|
15722
|
+
if (token.t === "id" && token.v === "like") {
|
|
15723
|
+
this.position += 1;
|
|
15724
|
+
return {
|
|
15725
|
+
k: "like",
|
|
15726
|
+
operand: left,
|
|
15727
|
+
pattern: this.next("str").v
|
|
15728
|
+
};
|
|
15729
|
+
}
|
|
15730
|
+
if (token.t === "id" && token.v === "has") {
|
|
15731
|
+
this.position += 1;
|
|
15732
|
+
this.attributePath();
|
|
15733
|
+
return UNKNOWN;
|
|
15734
|
+
}
|
|
15735
|
+
if (token.t === "id" && token.v === "is") {
|
|
15736
|
+
this.position += 1;
|
|
15737
|
+
this.namePath();
|
|
15738
|
+
if (this.take("id", "in")) this.additive(depth);
|
|
15739
|
+
return UNKNOWN;
|
|
15740
|
+
}
|
|
15741
|
+
return left;
|
|
15742
|
+
}
|
|
15743
|
+
attributePath() {
|
|
15744
|
+
const first = this.peek();
|
|
15745
|
+
if (first === void 0 || first.t !== "id" && first.t !== "str") throw new SyntaxError("expected attribute");
|
|
15746
|
+
this.position += 1;
|
|
15747
|
+
while (this.take("p", ".")) {
|
|
15748
|
+
const part = this.peek();
|
|
15749
|
+
if (part === void 0 || part.t !== "id" && part.t !== "str") throw new SyntaxError("expected attribute");
|
|
15750
|
+
this.position += 1;
|
|
15751
|
+
}
|
|
15752
|
+
}
|
|
15753
|
+
namePath() {
|
|
15754
|
+
this.next("id");
|
|
15755
|
+
while (this.take("p", "::")) this.next("id");
|
|
15756
|
+
}
|
|
15757
|
+
additive(depth) {
|
|
15758
|
+
let result = this.multiplicative(depth);
|
|
15759
|
+
while (this.is("p", "+") || this.is("p", "-")) {
|
|
15760
|
+
this.position += 1;
|
|
15761
|
+
this.multiplicative(depth);
|
|
15762
|
+
result = UNKNOWN;
|
|
15763
|
+
}
|
|
15764
|
+
return result;
|
|
15765
|
+
}
|
|
15766
|
+
multiplicative(depth) {
|
|
15767
|
+
let result = this.unary(depth);
|
|
15768
|
+
while (this.take("p", "*")) {
|
|
15769
|
+
this.unary(depth);
|
|
15770
|
+
result = UNKNOWN;
|
|
15771
|
+
}
|
|
15772
|
+
return result;
|
|
15773
|
+
}
|
|
15774
|
+
unary(depth) {
|
|
15775
|
+
const prefixes = [];
|
|
15776
|
+
while (this.is("p", "!") || this.is("p", "-")) {
|
|
15777
|
+
prefixes.push(this.peek().v);
|
|
15778
|
+
this.position += 1;
|
|
15779
|
+
if (prefixes.length > MAX_NESTING) throw new SyntaxError("too deep");
|
|
15780
|
+
}
|
|
15781
|
+
let result = this.member(depth);
|
|
15782
|
+
for (let i = prefixes.length - 1; i >= 0; i -= 1) result = prefixes[i] === "!" ? {
|
|
15783
|
+
k: "not",
|
|
15784
|
+
operand: result
|
|
15785
|
+
} : UNKNOWN;
|
|
15786
|
+
return result;
|
|
15787
|
+
}
|
|
15788
|
+
member(depth) {
|
|
15789
|
+
let result = this.primary(depth);
|
|
15790
|
+
let links = 0;
|
|
15791
|
+
for (;;) {
|
|
15792
|
+
if (this.take("p", ".")) {
|
|
15793
|
+
const method = this.next("id").v;
|
|
15794
|
+
if (method === "getTag") this.readsTag = true;
|
|
15795
|
+
result = this.is("p", "(") ? {
|
|
15796
|
+
k: "call",
|
|
15797
|
+
method,
|
|
15798
|
+
receiver: result,
|
|
15799
|
+
args: this.arguments(depth)
|
|
15800
|
+
} : attribute(result, method);
|
|
15801
|
+
} else if (this.take("p", "[")) {
|
|
15802
|
+
const key = this.next("str").v;
|
|
15803
|
+
this.expect("p", "]");
|
|
15804
|
+
result = attribute(result, decodeCedarString(key));
|
|
15805
|
+
} else return result;
|
|
15806
|
+
links += 1;
|
|
15807
|
+
if (links > MAX_NESTING) throw new SyntaxError("too deep");
|
|
15808
|
+
}
|
|
15809
|
+
}
|
|
15810
|
+
arguments(depth) {
|
|
15811
|
+
this.expect("p", "(");
|
|
15812
|
+
return this.list(")", depth + 1);
|
|
15813
|
+
}
|
|
15814
|
+
list(close, depth) {
|
|
15815
|
+
const items = [];
|
|
15816
|
+
while (!this.take("p", close)) {
|
|
15817
|
+
items.push(this.expression(depth));
|
|
15818
|
+
if (!this.is("p", close)) this.expect("p", ",");
|
|
15819
|
+
}
|
|
15820
|
+
return items;
|
|
15821
|
+
}
|
|
15822
|
+
primary(depth) {
|
|
15823
|
+
const token = this.peek();
|
|
15824
|
+
if (token === void 0) throw new SyntaxError("unexpected end");
|
|
15825
|
+
this.position += 1;
|
|
15826
|
+
if (token.t === "str") return {
|
|
15827
|
+
k: "str",
|
|
15828
|
+
raw: token.v
|
|
15829
|
+
};
|
|
15830
|
+
if (token.t === "num") return UNKNOWN;
|
|
15831
|
+
if (token.t === "id") {
|
|
15832
|
+
if (token.v === "true" || token.v === "false") return {
|
|
15833
|
+
k: "lit",
|
|
15834
|
+
v: token.v === "true"
|
|
15835
|
+
};
|
|
15836
|
+
if ([
|
|
15837
|
+
"principal",
|
|
15838
|
+
"resource",
|
|
15839
|
+
"action",
|
|
15840
|
+
"context"
|
|
15841
|
+
].includes(token.v)) return {
|
|
15842
|
+
k: "var",
|
|
15843
|
+
name: token.v
|
|
15844
|
+
};
|
|
15845
|
+
while (this.take("p", "::")) {
|
|
15846
|
+
if (this.peek()?.t === "str") {
|
|
15847
|
+
this.position += 1;
|
|
15848
|
+
return UNKNOWN;
|
|
15849
|
+
}
|
|
15850
|
+
this.next("id");
|
|
15851
|
+
}
|
|
15852
|
+
if (this.is("p", "(")) this.arguments(depth);
|
|
15853
|
+
return UNKNOWN;
|
|
15854
|
+
}
|
|
15855
|
+
if (token.v === "(") {
|
|
15856
|
+
const inner = this.expression(depth + 1);
|
|
15857
|
+
this.expect("p", ")");
|
|
15858
|
+
return inner;
|
|
15859
|
+
}
|
|
15860
|
+
if (token.v === "[") return {
|
|
15861
|
+
k: "set",
|
|
15862
|
+
items: this.list("]", depth + 1)
|
|
15863
|
+
};
|
|
15864
|
+
if (token.v === "{") {
|
|
15865
|
+
while (!this.take("p", "}")) {
|
|
15866
|
+
const key = this.peek();
|
|
15867
|
+
if (key === void 0 || key.t !== "id" && key.t !== "str") throw new SyntaxError("expected key");
|
|
15868
|
+
this.position += 1;
|
|
15869
|
+
this.expect("p", ":");
|
|
15870
|
+
this.expression(depth + 1);
|
|
15871
|
+
if (!this.is("p", "}")) this.expect("p", ",");
|
|
15872
|
+
}
|
|
15873
|
+
return UNKNOWN;
|
|
15874
|
+
}
|
|
15875
|
+
throw new SyntaxError("unexpected token");
|
|
15876
|
+
}
|
|
15877
|
+
};
|
|
15878
|
+
function attribute(target, name) {
|
|
15879
|
+
if (target.k !== "var" || name === null) return UNKNOWN;
|
|
15880
|
+
if (target.name === "principal" && (name === "category" || name === "name")) return { k: name };
|
|
15881
|
+
return target.name === "resource" && name === "path" ? { k: "path" } : UNKNOWN;
|
|
15882
|
+
}
|
|
15883
|
+
const parseExpression = (text) => new Parser(tokenize(text)).parseAll();
|
|
15884
|
+
const triOf = (value) => value ? "yes" : "no";
|
|
15885
|
+
const invert = (value) => value === "maybe" ? "maybe" : value === "yes" ? "no" : "yes";
|
|
15886
|
+
const constantSets = /* @__PURE__ */ new WeakMap();
|
|
15887
|
+
function valueOf(expr, facts, read) {
|
|
15888
|
+
switch (expr.k) {
|
|
15889
|
+
case "str": {
|
|
15890
|
+
const decoded = decodeCedarString(expr.raw);
|
|
15891
|
+
return decoded === null ? { k: "unknown" } : {
|
|
15892
|
+
k: "str",
|
|
15893
|
+
v: decoded
|
|
15894
|
+
};
|
|
15895
|
+
}
|
|
15896
|
+
case "category": return {
|
|
15897
|
+
k: "str",
|
|
15898
|
+
v: read
|
|
15899
|
+
};
|
|
15900
|
+
case "path": return facts.path === void 0 ? { k: "unknown" } : {
|
|
15901
|
+
k: "str",
|
|
15902
|
+
v: facts.path
|
|
15903
|
+
};
|
|
15904
|
+
case "name": return { k: "name" };
|
|
15905
|
+
case "set": {
|
|
15906
|
+
const known = constantSets.get(expr);
|
|
15907
|
+
if (known !== void 0) return known;
|
|
15908
|
+
const items = expr.items.map((item) => valueOf(item, facts, read));
|
|
15909
|
+
const value = items.some((item) => item.k === "set") ? { k: "unknown" } : {
|
|
15910
|
+
k: "set",
|
|
15911
|
+
items
|
|
15912
|
+
};
|
|
15913
|
+
if (expr.items.every((item) => item.k === "str")) constantSets.set(expr, value);
|
|
15914
|
+
return value;
|
|
15915
|
+
}
|
|
15916
|
+
case "if": {
|
|
15917
|
+
const cond = evaluateExpression(expr.cond, facts);
|
|
15918
|
+
if (cond === "maybe") return { k: "unknown" };
|
|
15919
|
+
return valueOf(cond === "yes" ? expr.then : expr.otherwise, facts, read);
|
|
15920
|
+
}
|
|
15921
|
+
case "lit":
|
|
15922
|
+
case "and":
|
|
15923
|
+
case "or":
|
|
15924
|
+
case "not":
|
|
15925
|
+
case "cmp":
|
|
15926
|
+
case "like":
|
|
15927
|
+
case "call": return {
|
|
15928
|
+
k: "tri",
|
|
15929
|
+
v: evaluateExpression(expr, facts)
|
|
15930
|
+
};
|
|
15931
|
+
default: return { k: "unknown" };
|
|
15932
|
+
}
|
|
15933
|
+
}
|
|
15934
|
+
function sameValue(left, right) {
|
|
15935
|
+
if (left.k === "unknown" || right.k === "unknown") return "maybe";
|
|
15936
|
+
if (left.k === "name" || right.k === "name") {
|
|
15937
|
+
const other = left.k === "name" ? right : left;
|
|
15938
|
+
if (other.k !== "str") return other.k === "name" ? "maybe" : "no";
|
|
15939
|
+
return HUMAN_NAMES.includes(other.v.trim().toLowerCase()) ? "maybe" : "no";
|
|
15940
|
+
}
|
|
15941
|
+
if (left.k === "tri" && right.k === "tri") return left.v === "maybe" || right.v === "maybe" ? "maybe" : triOf(left.v === right.v);
|
|
15942
|
+
if (left.k === "tri" || right.k === "tri") return "no";
|
|
15943
|
+
if (left.k === "str" && right.k === "str") return triOf(left.v === right.v);
|
|
15944
|
+
if (left.k === "set" && right.k === "set") {
|
|
15945
|
+
const [leftIndex, rightIndex] = [indexItems(left.items), indexItems(right.items)];
|
|
15946
|
+
if (leftIndex.pure && rightIndex.pure) return triOf(leftIndex.strings.size === rightIndex.strings.size && holdsAll(leftIndex, rightIndex));
|
|
15947
|
+
const covers = (from, into) => {
|
|
15948
|
+
const index = indexItems(into);
|
|
15949
|
+
return combine(from.map((item) => member(item, index)), "and");
|
|
15950
|
+
};
|
|
15951
|
+
return combine([covers(left.items, right.items), covers(right.items, left.items)], "and");
|
|
15952
|
+
}
|
|
15953
|
+
return "no";
|
|
15954
|
+
}
|
|
15955
|
+
function holdsAll(index, other) {
|
|
15956
|
+
for (const value of other.strings) if (!index.strings.has(value)) return false;
|
|
15957
|
+
return true;
|
|
15958
|
+
}
|
|
15959
|
+
function shareAny(left, right) {
|
|
15960
|
+
const [small, large] = left.strings.size <= right.strings.size ? [left, right] : [right, left];
|
|
15961
|
+
for (const value of small.strings) if (large.strings.has(value)) return true;
|
|
15962
|
+
return false;
|
|
15963
|
+
}
|
|
15964
|
+
const indexes = /* @__PURE__ */ new WeakMap();
|
|
15965
|
+
function indexItems(items) {
|
|
15966
|
+
const known = indexes.get(items);
|
|
15967
|
+
if (known !== void 0) return known;
|
|
15968
|
+
const index = buildIndex(items);
|
|
15969
|
+
indexes.set(items, index);
|
|
15970
|
+
return index;
|
|
15971
|
+
}
|
|
15972
|
+
function buildIndex(items) {
|
|
15973
|
+
const strings = /* @__PURE__ */ new Set();
|
|
15974
|
+
const representatives = /* @__PURE__ */ new Map();
|
|
15975
|
+
for (const item of items) if (item.k === "str") {
|
|
15976
|
+
strings.add(item.v);
|
|
15977
|
+
representatives.set(HUMAN_NAMES.includes(item.v.trim().toLowerCase()) ? "human" : "str", item);
|
|
15978
|
+
} else representatives.set(item.k === "tri" ? `tri:${item.v}` : item.k, item);
|
|
15979
|
+
return {
|
|
15980
|
+
strings,
|
|
15981
|
+
representatives: [...representatives.values()],
|
|
15982
|
+
pure: items.every((item) => item.k === "str")
|
|
15983
|
+
};
|
|
15984
|
+
}
|
|
15985
|
+
function member(item, index) {
|
|
15986
|
+
if (item.k === "str" && index.strings.has(item.v)) return "yes";
|
|
15987
|
+
return combine(index.representatives.map((candidate) => sameValue(item, candidate)), "or");
|
|
15988
|
+
}
|
|
15989
|
+
function combine(results, op) {
|
|
15990
|
+
const decisive = op === "and" ? "no" : "yes";
|
|
15991
|
+
if (results.includes(decisive)) return decisive;
|
|
15992
|
+
return results.includes("maybe") ? "maybe" : invert(decisive);
|
|
15993
|
+
}
|
|
15994
|
+
function setCall(method, receiver, args) {
|
|
15995
|
+
if (receiver.k !== "set") return "maybe";
|
|
15996
|
+
if (method === "isEmpty" && args.length === 0) return triOf(receiver.items.length === 0);
|
|
15997
|
+
const [argument] = args;
|
|
15998
|
+
if (args.length !== 1) return "maybe";
|
|
15999
|
+
const index = indexItems(receiver.items);
|
|
16000
|
+
if (method === "contains") return member(argument, index);
|
|
16001
|
+
if (argument.k !== "set") return "maybe";
|
|
16002
|
+
if (method === "containsAny" || method === "containsAll") {
|
|
16003
|
+
const other = indexItems(argument.items);
|
|
16004
|
+
if (index.pure && other.pure) return triOf(method === "containsAny" ? shareAny(index, other) : other.strings.size <= index.strings.size && holdsAll(index, other));
|
|
16005
|
+
return combine(argument.items.map((item) => member(item, index)), method === "containsAny" ? "or" : "and");
|
|
16006
|
+
}
|
|
16007
|
+
return "maybe";
|
|
16008
|
+
}
|
|
16009
|
+
const leaves = (expr) => expr.k === "set" ? expr.items.flatMap(leaves) : expr.k === "if" ? [...leaves(expr.then), ...leaves(expr.otherwise)] : [expr];
|
|
16010
|
+
function strings(exprs) {
|
|
16011
|
+
const found = [];
|
|
16012
|
+
for (const part of exprs.flatMap(leaves)) {
|
|
16013
|
+
const decoded = part.k === "str" ? decodeCedarString(part.raw) : null;
|
|
16014
|
+
if (decoded !== null) found.push(decoded);
|
|
16015
|
+
}
|
|
16016
|
+
return found;
|
|
16017
|
+
}
|
|
16018
|
+
const readsCategory = (exprs) => exprs.flatMap(leaves).some((part) => part.k === "category");
|
|
16019
|
+
const spelledAtoms = /* @__PURE__ */ new WeakMap();
|
|
16020
|
+
function spelledBy(expr) {
|
|
16021
|
+
let spelled = spelledAtoms.get(expr);
|
|
16022
|
+
if (spelled === void 0) {
|
|
16023
|
+
const sides = expr.k === "cmp" ? [expr.left, expr.right] : [expr.receiver, ...expr.args];
|
|
16024
|
+
spelled = {
|
|
16025
|
+
reads: readsCategory(sides),
|
|
16026
|
+
names: new Set(strings(sides))
|
|
16027
|
+
};
|
|
16028
|
+
spelledAtoms.set(expr, spelled);
|
|
16029
|
+
}
|
|
16030
|
+
return spelled;
|
|
16031
|
+
}
|
|
16032
|
+
function mentions(expr, name) {
|
|
16033
|
+
if (name === void 0) return false;
|
|
16034
|
+
if (expr.k === "like") {
|
|
16035
|
+
const segments = cedarLikeSegments(expr.pattern);
|
|
16036
|
+
return readsCategory([expr.operand]) && segments.some((segment) => segment.includes(name)) && globMatches(segments, name);
|
|
16037
|
+
}
|
|
16038
|
+
const { reads, names } = spelledBy(expr);
|
|
16039
|
+
return reads && names.has(name);
|
|
16040
|
+
}
|
|
16041
|
+
const readOf = (expr, facts) => mentions(expr, facts.unnamed) ? UNNAMED_CATEGORY : facts.category;
|
|
16042
|
+
function evaluateExpression(expr, facts) {
|
|
16043
|
+
switch (expr.k) {
|
|
16044
|
+
case "lit": return triOf(expr.v);
|
|
16045
|
+
case "not": return invert(evaluateExpression(expr.operand, facts));
|
|
16046
|
+
case "and":
|
|
16047
|
+
case "or": return combine(expr.terms.map((term) => evaluateExpression(term, facts)), expr.k);
|
|
16048
|
+
case "if": {
|
|
16049
|
+
const cond = evaluateExpression(expr.cond, facts);
|
|
16050
|
+
if (cond !== "maybe") return evaluateExpression(cond === "yes" ? expr.then : expr.otherwise, facts);
|
|
16051
|
+
const [then, otherwise] = [expr.then, expr.otherwise].map((branch) => evaluateExpression(branch, facts));
|
|
16052
|
+
return then === otherwise ? then : "maybe";
|
|
16053
|
+
}
|
|
16054
|
+
case "cmp": {
|
|
16055
|
+
const read = readOf(expr, facts);
|
|
16056
|
+
const same = sameValue(valueOf(expr.left, facts, read), valueOf(expr.right, facts, read));
|
|
16057
|
+
return expr.equals ? same : invert(same);
|
|
16058
|
+
}
|
|
16059
|
+
case "like": {
|
|
16060
|
+
const subject = valueOf(expr.operand, facts, readOf(expr, facts));
|
|
16061
|
+
if (UNSUPPORTED_PATTERN_ESCAPE.test(expr.pattern)) return "maybe";
|
|
16062
|
+
const segments = cedarLikeSegments(expr.pattern);
|
|
16063
|
+
if (subject.k === "name") return HUMAN_NAMES.some((candidate) => globMatches(segments, candidate)) ? "maybe" : "no";
|
|
16064
|
+
if (subject.k !== "str") return "maybe";
|
|
16065
|
+
return triOf(globMatches(segments, subject.v));
|
|
16066
|
+
}
|
|
16067
|
+
case "call": {
|
|
16068
|
+
const read = readOf(expr, facts);
|
|
16069
|
+
return setCall(expr.method, valueOf(expr.receiver, facts, read), expr.args.map((arg) => valueOf(arg, facts, read)));
|
|
16070
|
+
}
|
|
16071
|
+
default: return "maybe";
|
|
16072
|
+
}
|
|
16073
|
+
}
|
|
16074
|
+
|
|
16075
|
+
//#endregion
|
|
16076
|
+
//#region src/policy/cedar-principal-scope.ts
|
|
16077
|
+
const PROBE_CLASSES = ["human", NO_EVIDENCE_CATEGORY];
|
|
16078
|
+
const ANONYMOUS_PRINCIPAL_ID = "anonymous";
|
|
16079
|
+
const S = CEDAR_SPACE_CLASS;
|
|
16080
|
+
const HEAD = new RegExp(`\\b(forbid|permit)${S}*\\(`, "g");
|
|
16081
|
+
const isAnnotationName = (code, index) => {
|
|
16082
|
+
let position = index - 1;
|
|
16083
|
+
while (position >= 0 && isCedarSpace(code[position])) position -= 1;
|
|
16084
|
+
return code[position] === "@";
|
|
16085
|
+
};
|
|
16086
|
+
const skipSpace = (text, from) => {
|
|
16087
|
+
let index = from;
|
|
16088
|
+
while (index < text.length && isCedarSpace(text[index])) index += 1;
|
|
16089
|
+
return index;
|
|
16090
|
+
};
|
|
16091
|
+
const conditionAt = (text, from) => {
|
|
16092
|
+
const keywordStart = skipSpace(text, from);
|
|
16093
|
+
const kind = text.startsWith("when", keywordStart) ? "when" : text.startsWith("unless", keywordStart) ? "unless" : null;
|
|
16094
|
+
if (kind === null) return null;
|
|
16095
|
+
const braceOpen = skipSpace(text, keywordStart + kind.length);
|
|
16096
|
+
return text[braceOpen] === "{" ? {
|
|
16097
|
+
kind,
|
|
16098
|
+
braceOpen
|
|
16099
|
+
} : null;
|
|
16100
|
+
};
|
|
16101
|
+
function matching(code, openIndex, open, close) {
|
|
16102
|
+
let depth = 0;
|
|
16103
|
+
for (let i = openIndex; i < code.length; i++) if (code[i] === open) depth++;
|
|
16104
|
+
else if (code[i] === close) {
|
|
16105
|
+
depth--;
|
|
16106
|
+
if (depth === 0) return i;
|
|
16107
|
+
}
|
|
16108
|
+
return -1;
|
|
16109
|
+
}
|
|
16110
|
+
function parseCedarStatements(cedar) {
|
|
16111
|
+
const { visible, code } = maskCedar(cedar);
|
|
16112
|
+
const statements = [];
|
|
16113
|
+
const heads = new RegExp(HEAD.source, "g");
|
|
16114
|
+
let previousEnd = 0;
|
|
16115
|
+
let match = heads.exec(code);
|
|
16116
|
+
while (match !== null) {
|
|
16117
|
+
if (isAnnotationName(code, match.index)) {
|
|
16118
|
+
match = heads.exec(code);
|
|
16119
|
+
continue;
|
|
16120
|
+
}
|
|
16121
|
+
const open = match.index + match[0].length - 1;
|
|
16122
|
+
const scopeEnd = matching(code, open, "(", ")");
|
|
16123
|
+
if (scopeEnd < 0) break;
|
|
16124
|
+
const conditions = [];
|
|
16125
|
+
let position = scopeEnd + 1;
|
|
16126
|
+
for (;;) {
|
|
16127
|
+
const condition = conditionAt(code, position);
|
|
16128
|
+
if (condition === null) break;
|
|
16129
|
+
const braceClose = matching(code, condition.braceOpen, "{", "}");
|
|
16130
|
+
if (braceClose < 0) {
|
|
16131
|
+
position = code.length;
|
|
16132
|
+
break;
|
|
16133
|
+
}
|
|
16134
|
+
conditions.push({
|
|
16135
|
+
kind: condition.kind,
|
|
16136
|
+
body: visible.slice(condition.braceOpen + 1, braceClose)
|
|
16137
|
+
});
|
|
16138
|
+
position = braceClose + 1;
|
|
16139
|
+
}
|
|
16140
|
+
const terminatorAt = skipSpace(code, position);
|
|
16141
|
+
const end = code[terminatorAt] === ";" ? terminatorAt + 1 : position;
|
|
16142
|
+
statements.push({
|
|
16143
|
+
effect: match[1],
|
|
16144
|
+
blockStart: Math.min(skipSpace(cedar, previousEnd), match.index),
|
|
16145
|
+
start: match.index,
|
|
16146
|
+
end,
|
|
16147
|
+
text: visible.slice(match.index, end),
|
|
16148
|
+
scope: visible.slice(open + 1, scopeEnd),
|
|
16149
|
+
conditions,
|
|
16150
|
+
annotations: visible.slice(previousEnd, match.index)
|
|
16151
|
+
});
|
|
16152
|
+
previousEnd = end;
|
|
16153
|
+
heads.lastIndex = end;
|
|
16154
|
+
match = heads.exec(code);
|
|
16155
|
+
}
|
|
16156
|
+
return statements;
|
|
16157
|
+
}
|
|
16158
|
+
const TRUE_BODY = new RegExp(`^${S}*true${S}*$`);
|
|
16159
|
+
const PRINCIPAL_EQUALS = new RegExp(`\\bprincipal${S}*==`);
|
|
16160
|
+
const ENTITY_ID = new RegExp(`::${S}*"((?:\\\\.|[^"\\\\])*)"`, "g");
|
|
16161
|
+
const IS_TYPE = new RegExp(`\\bis${S}+([\\w:]+)`);
|
|
16162
|
+
const ID_ANNOTATION = new RegExp(`@id\\(${S}*"((?:\\\\.|[^"\\\\])*)"${S}*\\)`, "g");
|
|
16163
|
+
function principalScope(scope) {
|
|
16164
|
+
const { visible, code } = maskCedar(scope);
|
|
16165
|
+
let depth = 0;
|
|
16166
|
+
let end = code.length;
|
|
16167
|
+
for (let i = 0; i < code.length; i++) {
|
|
16168
|
+
const char = code[i];
|
|
16169
|
+
if (char === "(" || char === "[" || char === "{") depth++;
|
|
16170
|
+
else if (char === ")" || char === "]" || char === "}") depth--;
|
|
16171
|
+
else if (char === "," && depth === 0) {
|
|
16172
|
+
end = i;
|
|
16173
|
+
break;
|
|
16174
|
+
}
|
|
16175
|
+
}
|
|
16176
|
+
const text = visible.slice(0, end);
|
|
16177
|
+
const masked = code.slice(0, end);
|
|
16178
|
+
if (PRINCIPAL_EQUALS.test(masked) || /\bin\b/.test(masked)) return Array.from(text.matchAll(ENTITY_ID), (m) => decodeCedarString(m[1])).some((id) => id === null || id === ANONYMOUS_PRINCIPAL_ID) ? "maybe" : "no";
|
|
16179
|
+
const isType = IS_TYPE.exec(masked);
|
|
16180
|
+
if (isType) return isType[1].split("::").pop() === "Agent" ? "maybe" : "no";
|
|
16181
|
+
return "yes";
|
|
16182
|
+
}
|
|
16183
|
+
const prepared = /* @__PURE__ */ new WeakMap();
|
|
16184
|
+
function parsedCondition(body) {
|
|
16185
|
+
try {
|
|
16186
|
+
return parseExpression(body);
|
|
16187
|
+
} catch {
|
|
16188
|
+
return null;
|
|
16189
|
+
}
|
|
16190
|
+
}
|
|
16191
|
+
function evaluableOf(statement) {
|
|
16192
|
+
return {
|
|
16193
|
+
scope: principalScope(statement.scope),
|
|
16194
|
+
conditions: statement.conditions.map(({ kind, body }) => ({
|
|
16195
|
+
kind,
|
|
16196
|
+
node: parsedCondition(body)
|
|
16197
|
+
}))
|
|
16198
|
+
};
|
|
16199
|
+
}
|
|
16200
|
+
function preparedOf(statement) {
|
|
16201
|
+
let entry = prepared.get(statement);
|
|
16202
|
+
if (entry === void 0) {
|
|
16203
|
+
const named = namesNoEvidence(statement.text);
|
|
16204
|
+
entry = {
|
|
16205
|
+
namesNoEvidence: named,
|
|
16206
|
+
substituted: !named && withNoEvidenceExclusion(statement.text) !== statement.text,
|
|
16207
|
+
evaluable: evaluableOf(statement)
|
|
16208
|
+
};
|
|
16209
|
+
prepared.set(statement, entry);
|
|
16210
|
+
}
|
|
16211
|
+
return entry;
|
|
16212
|
+
}
|
|
16213
|
+
function statementApplies(statement, facts) {
|
|
16214
|
+
const { substituted, evaluable } = preparedOf(statement);
|
|
16215
|
+
const read = facts.category === "no_evidence" && substituted ? {
|
|
16216
|
+
...facts,
|
|
16217
|
+
category: "human"
|
|
16218
|
+
} : facts;
|
|
16219
|
+
const effective = {
|
|
16220
|
+
category: read.category,
|
|
16221
|
+
path: read.path,
|
|
16222
|
+
unnamed: facts.discountNaming ? read.category : void 0
|
|
16223
|
+
};
|
|
16224
|
+
if (evaluable.scope === "no") return false;
|
|
16225
|
+
for (const { kind, node } of evaluable.conditions) {
|
|
16226
|
+
const result = node === null ? "maybe" : evaluateExpression(node, effective);
|
|
16227
|
+
if (kind === "when" && result === "no") return false;
|
|
16228
|
+
if (kind === "unless" && result === "yes") return false;
|
|
16229
|
+
}
|
|
16230
|
+
return true;
|
|
16231
|
+
}
|
|
16232
|
+
function reachesClassOnlyByNaming(statement, probe, path) {
|
|
16233
|
+
return statementApplies(statement, {
|
|
16234
|
+
category: probe,
|
|
16235
|
+
path
|
|
16236
|
+
}) && !statementApplies(statement, {
|
|
16237
|
+
category: probe,
|
|
16238
|
+
path,
|
|
16239
|
+
discountNaming: true
|
|
16240
|
+
});
|
|
16241
|
+
}
|
|
16242
|
+
function statementId(statement) {
|
|
16243
|
+
return Array.from(statement.annotations.matchAll(ID_ANNOTATION), (m) => unescapeCedarString(m[1])).at(-1);
|
|
16244
|
+
}
|
|
16245
|
+
let memoText;
|
|
16246
|
+
let memoParsed = {
|
|
16247
|
+
text: "",
|
|
16248
|
+
statements: []
|
|
16249
|
+
};
|
|
16250
|
+
function parsedOf(cedar) {
|
|
16251
|
+
if (memoText !== cedar) {
|
|
16252
|
+
const text = withoutNoEvidenceExclusion(cedar);
|
|
16253
|
+
memoParsed = {
|
|
16254
|
+
text,
|
|
16255
|
+
statements: parseCedarStatements(text)
|
|
16256
|
+
};
|
|
16257
|
+
memoText = cedar;
|
|
16258
|
+
}
|
|
16259
|
+
return memoParsed;
|
|
16260
|
+
}
|
|
16261
|
+
function analyzePolicyScope(cedar) {
|
|
16262
|
+
const { text, statements } = parsedOf(cedar);
|
|
16263
|
+
return {
|
|
16264
|
+
unnarrowedDeny(path) {
|
|
16265
|
+
const found = [];
|
|
16266
|
+
let line = 1;
|
|
16267
|
+
let counted = 0;
|
|
16268
|
+
for (const statement of statements) {
|
|
16269
|
+
if (statement.effect !== "forbid") continue;
|
|
16270
|
+
const classes = PROBE_CLASSES.filter((probe) => statementApplies(statement, {
|
|
16271
|
+
category: probe,
|
|
16272
|
+
path
|
|
16273
|
+
}) && !reachesClassOnlyByNaming(statement, probe, path));
|
|
16274
|
+
if (classes.length > 0) {
|
|
16275
|
+
for (; counted < statement.blockStart; counted++) if (text.charCodeAt(counted) === 10) line++;
|
|
16276
|
+
found.push({
|
|
16277
|
+
statement,
|
|
16278
|
+
classes,
|
|
16279
|
+
line
|
|
16280
|
+
});
|
|
16281
|
+
}
|
|
16282
|
+
}
|
|
16283
|
+
return found;
|
|
16284
|
+
},
|
|
16285
|
+
denyNamingClass(path, probe) {
|
|
16286
|
+
return statements.filter((statement) => statement.effect === "forbid" && (probe !== "no_evidence" || preparedOf(statement).namesNoEvidence) && reachesClassOnlyByNaming(statement, probe, path));
|
|
16287
|
+
},
|
|
16288
|
+
lacksBaselinePermit() {
|
|
16289
|
+
return statements.length > 0 && !statements.some(isBaselinePermit);
|
|
16290
|
+
}
|
|
16291
|
+
};
|
|
16292
|
+
}
|
|
16293
|
+
const unnarrowedDenyStatements = (cedar, path) => analyzePolicyScope(cedar).unnarrowedDeny(path);
|
|
16294
|
+
const lacksBaselinePermit = (cedar) => analyzePolicyScope(cedar).lacksBaselinePermit();
|
|
16295
|
+
function isBaselinePermit(statement) {
|
|
16296
|
+
return statement.effect === "permit" && principalScope(statement.scope) === "yes" && statement.conditions.every((condition) => condition.kind === "when" && TRUE_BODY.test(condition.body));
|
|
16297
|
+
}
|
|
14708
16298
|
|
|
14709
16299
|
//#endregion
|
|
14710
16300
|
//#region src/policy/cedar-rule-match.ts
|
|
@@ -14720,6 +16310,8 @@ function cedarQuotedValueRegExp(prefixSource, flags = "") {
|
|
|
14720
16310
|
* engine (`name = agentName`, `category = scraper|detectionClass`), so the
|
|
14721
16311
|
* narrowing mirrors the engine's own evaluation. An UNKNOWN fact never narrows.
|
|
14722
16312
|
*/
|
|
16313
|
+
const UNLESS_BRACE = new RegExp(`unless${CEDAR_SPACE_CLASS}*\\{`);
|
|
16314
|
+
const FORBID_HEAD = new RegExp(`\\bforbid${CEDAR_SPACE_CLASS}*\\(`, "g");
|
|
14723
16315
|
/**
|
|
14724
16316
|
* A block applies when its path AND principal conditions all match the KNOWN
|
|
14725
16317
|
* request facts. An unknown fact never narrows (so the no-`request` case unions
|
|
@@ -14728,9 +16320,16 @@ function cedarQuotedValueRegExp(prefixSource, flags = "") {
|
|
|
14728
16320
|
function blockApplies(block, request) {
|
|
14729
16321
|
if (request?.path !== void 0 && !blockMatchesPath(block, request.path)) return false;
|
|
14730
16322
|
if (request?.name !== void 0 && !blockMatchesEquality(block, "principal.name", request.name)) return false;
|
|
14731
|
-
if (request?.category !== void 0
|
|
16323
|
+
if (request?.category !== void 0) {
|
|
16324
|
+
if (!blockMatchesEquality(block, "principal.category", categoryRead(block, request.category))) return false;
|
|
16325
|
+
}
|
|
14732
16326
|
return true;
|
|
14733
16327
|
}
|
|
16328
|
+
function categoryRead(block, category) {
|
|
16329
|
+
if (category !== "no_evidence") return category;
|
|
16330
|
+
const original = withoutNoEvidenceExclusion(block);
|
|
16331
|
+
return withNoEvidenceExclusion(original) !== original ? "human" : category;
|
|
16332
|
+
}
|
|
14734
16333
|
/** The `resource.path` literals appearing anywhere in `text` (no `when`/
|
|
14735
16334
|
* `unless` scoping — callers that care about scope use `splitWhenUnless`
|
|
14736
16335
|
* first). Shared regex extraction for `pathLiteralsInBlock` and the
|
|
@@ -14770,7 +16369,7 @@ function pathLiteralsInBlock(block) {
|
|
|
14770
16369
|
* the text contains.
|
|
14771
16370
|
*/
|
|
14772
16371
|
function splitWhenUnless(block) {
|
|
14773
|
-
const unlessIndex = block.search(
|
|
16372
|
+
const unlessIndex = block.search(UNLESS_BRACE);
|
|
14774
16373
|
if (unlessIndex === -1) return {
|
|
14775
16374
|
whenText: block,
|
|
14776
16375
|
unlessText: ""
|
|
@@ -14853,67 +16452,79 @@ function blockMatchesEquality(block, attr, value) {
|
|
|
14853
16452
|
* literal maps each `*` (and `**`) to `.*`, anchored.
|
|
14854
16453
|
*/
|
|
14855
16454
|
function pathLiteralMatches(literal, path) {
|
|
14856
|
-
|
|
14857
|
-
const pattern = escapeRegExp(literal).replace(/\\\*/g, ".*");
|
|
14858
|
-
try {
|
|
14859
|
-
return new RegExp(`^${pattern}$`).test(path);
|
|
14860
|
-
} catch {
|
|
14861
|
-
return false;
|
|
14862
|
-
}
|
|
16455
|
+
return globMatches(literal.split("*"), path);
|
|
14863
16456
|
}
|
|
14864
16457
|
/**
|
|
14865
16458
|
* True when the block contains a Cedar `forbid` statement (a deny rule). A bare
|
|
14866
16459
|
* `forbid` defaults to BLOCK; a `@verdict(...)` annotation refines the kind.
|
|
14867
16460
|
*/
|
|
14868
16461
|
function isForbidBlock(block) {
|
|
14869
|
-
|
|
14870
|
-
}
|
|
14871
|
-
/** True when the block narrows the principal — by category/name equality, a
|
|
14872
|
-
* Cedar entity-type test (`principal is X`), or a scope-position binding
|
|
14873
|
-
* (`forbid(principal == X::"…"`). An un-narrowed deny matches every principal.
|
|
14874
|
-
*
|
|
14875
|
-
* Cursor Bugbot (2026-09-11, High): this used to scan the WHOLE block for
|
|
14876
|
-
* a principal literal, `when`/`unless` alike — the exact same class of bug
|
|
14877
|
-
* `blockMatchesPath` above was already fixed for on the path dimension
|
|
14878
|
-
* (see that function's doc comment). `unless { principal.category ==
|
|
14879
|
-
* "search_engine" }` on an otherwise site-wide `forbid` only exempts
|
|
14880
|
-
* search engines from the deny — the rule still denies every OTHER
|
|
14881
|
-
* principal, humans included — but scanning the whole block found the
|
|
14882
|
-
* `==` literal and called the rule "narrowed," so `pathHasUnnarrowedDenyRule`
|
|
14883
|
-
* missed it and a real browser hitting that path reached Cedar only to be
|
|
14884
|
-
* denied by the very rule this check exists to catch. Split `when`/`unless`
|
|
14885
|
-
* first: a WHEN-scope (or scope-position) literal genuinely targets the
|
|
14886
|
-
* deny, narrowing it away from every principal not named — whatever value
|
|
14887
|
-
* it names, since an un-narrowed literal search wouldn't have found one at
|
|
14888
|
-
* all. An UNLESS-scope literal does the opposite: it exempts ONLY that
|
|
14889
|
-
* specific principal, so it narrows the rule away from humans only when
|
|
14890
|
-
* the exempted value is literally `"human"` (the #3297 carve-out idiom) —
|
|
14891
|
-
* exempting anyone else leaves the deny fully un-narrowed with respect to
|
|
14892
|
-
* humans. */
|
|
14893
|
-
function narrowsPrincipal(block) {
|
|
14894
|
-
const { whenText, unlessText } = splitWhenUnless(block);
|
|
14895
|
-
if (blockEqualityLiterals(whenText, "principal.category").length > 0) return true;
|
|
14896
|
-
if (blockExclusionLiterals(whenText, "principal.category").includes("human")) return true;
|
|
14897
|
-
if (blockEqualityLiterals(whenText, "principal.name").length > 0) return true;
|
|
14898
|
-
if (/principal\s+is\s+\w/.test(whenText)) return true;
|
|
14899
|
-
if (/forbid\s*\(\s*principal\s*==/.test(whenText)) return true;
|
|
14900
|
-
if (blockEqualityLiterals(unlessText, "principal.category").includes("human")) return true;
|
|
14901
|
-
return false;
|
|
16462
|
+
const { code } = maskCedar(block);
|
|
16463
|
+
return Array.from(code.matchAll(FORBID_HEAD)).some(({ index }) => !isAnnotationName(code, index));
|
|
14902
16464
|
}
|
|
14903
|
-
/** A deny rule that targets EVERY principal — the silent-human-impact footgun. */
|
|
14904
16465
|
function isUnnarrowedDenyBlock(block) {
|
|
14905
|
-
return
|
|
16466
|
+
return unnarrowedDenyStatements(block).some(({ classes }) => classes.includes("human"));
|
|
16467
|
+
}
|
|
16468
|
+
function analyzePolicySource(cedar) {
|
|
16469
|
+
const scope = analyzePolicyScope(cedar);
|
|
16470
|
+
const analysis = {
|
|
16471
|
+
unnarrowedDenyFor: (path, probe) => scope.unnarrowedDeny(path).some(({ classes }) => classes.includes(probe)),
|
|
16472
|
+
explicitDenyFor: (path, probe) => scope.denyNamingClass(path, probe).length > 0,
|
|
16473
|
+
humanHazard: (path) => analysis.unnarrowedDenyFor(path, "human"),
|
|
16474
|
+
noEvidenceHazard: (path) => analysis.unnarrowedDenyFor(path, "no_evidence") && !analysis.noEvidenceNamed(path),
|
|
16475
|
+
noEvidenceNamed: (path) => analysis.explicitDenyFor(path, NO_EVIDENCE_CATEGORY)
|
|
16476
|
+
};
|
|
16477
|
+
return analysis;
|
|
16478
|
+
}
|
|
16479
|
+
function pathHasUnnarrowedDenyRuleFor(cedar, path, probe) {
|
|
16480
|
+
return analyzePolicySource(cedar).unnarrowedDenyFor(path, probe);
|
|
16481
|
+
}
|
|
16482
|
+
function pathHasExplicitDenyRuleFor(cedar, path, probe) {
|
|
16483
|
+
return analyzePolicySource(cedar).explicitDenyFor(path, probe);
|
|
14906
16484
|
}
|
|
14907
|
-
/**
|
|
14908
|
-
* True when some un-narrowed deny rule in the bundle matches `path` — i.e. a
|
|
14909
|
-
* human hitting `path` is denied by a rule that never narrowed the principal.
|
|
14910
|
-
* The single shared definition of "this path catches humans by accident,"
|
|
14911
|
-
* used by the deploy gate AND the preview banner.
|
|
14912
|
-
*/
|
|
14913
16485
|
function pathHasUnnarrowedDenyRule(cedar, path) {
|
|
14914
|
-
return
|
|
16486
|
+
return analyzePolicySource(cedar).humanHazard(path);
|
|
14915
16487
|
}
|
|
14916
16488
|
|
|
16489
|
+
//#endregion
|
|
16490
|
+
//#region src/policy/byte-bounded-memo.ts
|
|
16491
|
+
var ByteBoundedMemo = class {
|
|
16492
|
+
budgetBytes;
|
|
16493
|
+
entries = /* @__PURE__ */ new Map();
|
|
16494
|
+
used = 0;
|
|
16495
|
+
constructor(budgetBytes) {
|
|
16496
|
+
this.budgetBytes = budgetBytes;
|
|
16497
|
+
}
|
|
16498
|
+
remember(key, bytes, make) {
|
|
16499
|
+
const hit = this.entries.get(key);
|
|
16500
|
+
if (hit !== void 0) {
|
|
16501
|
+
this.entries.delete(key);
|
|
16502
|
+
this.entries.set(key, hit);
|
|
16503
|
+
return hit.value;
|
|
16504
|
+
}
|
|
16505
|
+
const value = make();
|
|
16506
|
+
if (bytes > this.budgetBytes) return value;
|
|
16507
|
+
this.entries.set(key, {
|
|
16508
|
+
value,
|
|
16509
|
+
bytes
|
|
16510
|
+
});
|
|
16511
|
+
this.used += bytes;
|
|
16512
|
+
for (const [oldest, entry] of this.entries) {
|
|
16513
|
+
if (this.used <= this.budgetBytes) break;
|
|
16514
|
+
this.entries.delete(oldest);
|
|
16515
|
+
this.used -= entry.bytes;
|
|
16516
|
+
}
|
|
16517
|
+
return value;
|
|
16518
|
+
}
|
|
16519
|
+
};
|
|
16520
|
+
|
|
16521
|
+
//#endregion
|
|
16522
|
+
//#region src/policy/unsubstituted-source.ts
|
|
16523
|
+
const BUDGET_BYTES = 4194304;
|
|
16524
|
+
const BYTES_PER_CHARACTER = 4;
|
|
16525
|
+
const memo = new ByteBoundedMemo(BUDGET_BYTES);
|
|
16526
|
+
const unsubstitutedSource = (source) => memo.remember(source, source.length * BYTES_PER_CHARACTER, () => withoutNoEvidenceExclusion(source));
|
|
16527
|
+
|
|
14917
16528
|
//#endregion
|
|
14918
16529
|
//#region src/policy/required-scopes.ts
|
|
14919
16530
|
/**
|
|
@@ -14943,7 +16554,7 @@ function pathHasUnnarrowedDenyRule(cedar, path) {
|
|
|
14943
16554
|
function requiredScopesForRequest(policySource, request) {
|
|
14944
16555
|
if (!policySource || !policySource.trim()) return [];
|
|
14945
16556
|
const out = /* @__PURE__ */ new Set();
|
|
14946
|
-
for (const block of policySource.split(/\n\s*\n/)) {
|
|
16557
|
+
for (const block of unsubstitutedSource(policySource).split(/\n\s*\n/)) {
|
|
14947
16558
|
if (!/@verdict\("CHALLENGE"\)/.test(block)) continue;
|
|
14948
16559
|
const scopesMatch = block.match(cedarQuotedValueRegExp("@scopes\\("));
|
|
14949
16560
|
if (!scopesMatch) continue;
|
|
@@ -15026,32 +16637,24 @@ function nonNavigablePolicyLabel(policyId) {
|
|
|
15026
16637
|
|
|
15027
16638
|
//#endregion
|
|
15028
16639
|
//#region src/policy/policy-lint.ts
|
|
15029
|
-
const
|
|
15030
|
-
|
|
15031
|
-
|
|
15032
|
-
|
|
15033
|
-
|
|
15034
|
-
/**
|
|
15035
|
-
* Flag every un-narrowed deny rule in a composed Cedar bundle. Pure and
|
|
15036
|
-
* parity-irrelevant: a heuristic author-time WARNING, never an enforcement
|
|
15037
|
-
* decision. Shares its "un-narrowed deny" definition with the deploy gate
|
|
15038
|
-
* (`pathHasUnnarrowedDenyRule`) so the editor and the gate agree.
|
|
15039
|
-
*/
|
|
16640
|
+
const NARROW_ADVICE = "Add a `principal.category == \"ai_agent\"` (or `principal.name`) condition, or confirm you intend to affect them.";
|
|
16641
|
+
const EVERYONE_MESSAGE = `This rule denies every visitor, including humans and ${NO_EVIDENCE_CATEGORY} visitors, because it does not narrow the principal. ${NARROW_ADVICE}`;
|
|
16642
|
+
const HUMAN_MESSAGE = `This rule denies human visitors because it does not narrow the principal. ${NARROW_ADVICE}`;
|
|
16643
|
+
const NO_EVIDENCE_MESSAGE = `This rule also applies to ${NO_EVIDENCE_CATEGORY} visitors, who are real people whose browser sent no evidence to classify. Add a \`${NO_EVIDENCE_EXCLUSION_TERM}\` condition, or confirm you intend to affect them.`;
|
|
16644
|
+
const messageFor = (classes) => classes.length === PROBE_CLASSES.length ? EVERYONE_MESSAGE : classes.includes("no_evidence") ? NO_EVIDENCE_MESSAGE : HUMAN_MESSAGE;
|
|
15040
16645
|
function lintUnnarrowedDenyRules(cedar) {
|
|
15041
|
-
|
|
15042
|
-
|
|
15043
|
-
|
|
15044
|
-
|
|
15045
|
-
|
|
15046
|
-
|
|
15047
|
-
|
|
15048
|
-
|
|
15049
|
-
|
|
15050
|
-
|
|
15051
|
-
|
|
15052
|
-
|
|
15053
|
-
}
|
|
15054
|
-
return findings;
|
|
16646
|
+
return unnarrowedDenyStatements(cedar).map(({ statement, classes, line }) => ({
|
|
16647
|
+
ruleId: statementId(statement),
|
|
16648
|
+
line,
|
|
16649
|
+
message: messageFor(classes)
|
|
16650
|
+
}));
|
|
16651
|
+
}
|
|
16652
|
+
const MISSING_BASELINE_MESSAGE = `This policy has no baseline permit, so every visitor that no permit rule covers is denied, humans and ${NO_EVIDENCE_CATEGORY} visitors included. Add \`permit(principal, action, resource);\` if you want unmatched traffic allowed.`;
|
|
16653
|
+
function lintMissingBaselinePermit(cedar) {
|
|
16654
|
+
return lacksBaselinePermit(cedar) ? [{
|
|
16655
|
+
line: 1,
|
|
16656
|
+
message: MISSING_BASELINE_MESSAGE
|
|
16657
|
+
}] : [];
|
|
15055
16658
|
}
|
|
15056
16659
|
|
|
15057
16660
|
//#endregion
|
|
@@ -15092,7 +16695,7 @@ function lintUnnarrowedDenyRules(cedar) {
|
|
|
15092
16695
|
function approvalQuorumForRequest(policySource, request) {
|
|
15093
16696
|
if (!policySource || !policySource.trim()) return null;
|
|
15094
16697
|
let chosen = null;
|
|
15095
|
-
for (const block of policySource.split(/\n\s*\n/)) {
|
|
16698
|
+
for (const block of unsubstitutedSource(policySource).split(/\n\s*\n/)) {
|
|
15096
16699
|
if (!/@verdict\("CHALLENGE"\)/.test(block)) continue;
|
|
15097
16700
|
if (!blockApplies(block, request)) continue;
|
|
15098
16701
|
const approvers = parseApprovers(block);
|
|
@@ -15168,6 +16771,11 @@ function validateStepUpQuorum(quorum) {
|
|
|
15168
16771
|
* - Fallback to default policy on errors
|
|
15169
16772
|
* - Configurable API endpoints
|
|
15170
16773
|
*/
|
|
16774
|
+
function looksLikePolicyApiBody(data) {
|
|
16775
|
+
if (typeof data !== "object" || data === null) return false;
|
|
16776
|
+
const threshold = data.blockThreshold;
|
|
16777
|
+
return typeof threshold === "number" && Number.isFinite(threshold);
|
|
16778
|
+
}
|
|
15171
16779
|
var PolicyUnavailableError = class extends Error {
|
|
15172
16780
|
code = "POLICY_UNAVAILABLE";
|
|
15173
16781
|
constructor() {
|
|
@@ -15324,6 +16932,7 @@ var PolicyFetcher = class {
|
|
|
15324
16932
|
});
|
|
15325
16933
|
if (!response.ok) throw new Error(`API returned ${response.status}: ${response.statusText}`);
|
|
15326
16934
|
const data = await response.json();
|
|
16935
|
+
if (!looksLikePolicyApiBody(data)) throw new Error("Policy response is not from the policy API");
|
|
15327
16936
|
const policy = safeParsePolicyConfig(data);
|
|
15328
16937
|
if (!policy) throw new Error("Invalid policy response format");
|
|
15329
16938
|
return policy;
|
|
@@ -16108,9 +17717,9 @@ function deriveMcpiOrgKid(slug) {
|
|
|
16108
17717
|
* surface stay unchanged.
|
|
16109
17718
|
*
|
|
16110
17719
|
* Throws on an invalid slug (same boundary as {@link deriveMcpiOrgDid}) rather
|
|
16111
|
-
* than returning `[]`: an empty list
|
|
16112
|
-
*
|
|
16113
|
-
*
|
|
17720
|
+
* than returning `[]`: an empty list makes the engine reject every delegation,
|
|
17721
|
+
* so an org with a broken slug is a configuration error to surface loudly
|
|
17722
|
+
* server-side, not a silent outage of every delegated agent.
|
|
16114
17723
|
*/
|
|
16115
17724
|
function resolveTrustedDelegationRoots(org) {
|
|
16116
17725
|
return [deriveMcpiOrgDid(org.slug)];
|
|
@@ -16133,11 +17742,10 @@ function deriveMcpiUserDid(slug, userId) {
|
|
|
16133
17742
|
* Delegation-proof request detection (P2 / DR-1).
|
|
16134
17743
|
*
|
|
16135
17744
|
* The engine's L2 delegation-root pinning (`ContextSpec.trustedDelegationRoots`)
|
|
16136
|
-
* is
|
|
16137
|
-
*
|
|
16138
|
-
*
|
|
16139
|
-
*
|
|
16140
|
-
* human / no-delegation hot path stays a precise no-op.
|
|
17745
|
+
* is consulted for every credential the engine verifies: the delegation-proof
|
|
17746
|
+
* headers below AND an `Authorization: Bearer` VC-JWT. Consumers gate root
|
|
17747
|
+
* resolution on `requestPresentedCredential`, so the human / no-credential hot
|
|
17748
|
+
* path stays a precise no-op.
|
|
16141
17749
|
*
|
|
16142
17750
|
* Keeping the header set here (rather than re-listing the literals at each site)
|
|
16143
17751
|
* is the whole point: a new delegation transport header is added in one place
|
|
@@ -16173,6 +17781,73 @@ function requestCarriesDelegationProof(headers) {
|
|
|
16173
17781
|
for (const key of Object.keys(record)) lowerKeyed.set(key.toLowerCase(), record[key]);
|
|
16174
17782
|
return DELEGATION_PROOF_HEADERS.some((name) => isPresent(lowerKeyed.get(name)));
|
|
16175
17783
|
}
|
|
17784
|
+
const MAX_VC_JWT_PAYLOAD_CHARS = 16384;
|
|
17785
|
+
function headerText(headers, name) {
|
|
17786
|
+
if (typeof headers.get === "function") return headers.get(name) ?? void 0;
|
|
17787
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
17788
|
+
if (key.toLowerCase() !== name) continue;
|
|
17789
|
+
if (Array.isArray(value)) return value.join(", ");
|
|
17790
|
+
return typeof value === "string" ? value : void 0;
|
|
17791
|
+
}
|
|
17792
|
+
}
|
|
17793
|
+
function isMemberDelimiter(c) {
|
|
17794
|
+
return c === "=" || c === ";" || c === "," || c === " " || c === " ";
|
|
17795
|
+
}
|
|
17796
|
+
function hasKyaMember(value) {
|
|
17797
|
+
let memberStart = true;
|
|
17798
|
+
let quoted = false;
|
|
17799
|
+
let escaped = false;
|
|
17800
|
+
for (let i = 0; i < value.length; i++) {
|
|
17801
|
+
const c = value[i];
|
|
17802
|
+
if (quoted) {
|
|
17803
|
+
if (escaped) escaped = false;
|
|
17804
|
+
else if (c === "\\") escaped = true;
|
|
17805
|
+
else if (c === "\"") quoted = false;
|
|
17806
|
+
continue;
|
|
17807
|
+
}
|
|
17808
|
+
if (memberStart) {
|
|
17809
|
+
if (c === " " || c === " ") continue;
|
|
17810
|
+
if (value.startsWith("kya", i) && (i + 3 === value.length || isMemberDelimiter(value[i + 3]))) return true;
|
|
17811
|
+
memberStart = false;
|
|
17812
|
+
}
|
|
17813
|
+
if (c === "\"") quoted = true;
|
|
17814
|
+
else if (c === ",") memberStart = true;
|
|
17815
|
+
}
|
|
17816
|
+
return false;
|
|
17817
|
+
}
|
|
17818
|
+
function decodeBase64UrlJson(segment) {
|
|
17819
|
+
const padded = segment.replace(/-/g, "+").replace(/_/g, "/");
|
|
17820
|
+
const binary = atob(padded + "=".repeat((4 - padded.length % 4) % 4));
|
|
17821
|
+
const bytes = Uint8Array.from(binary, (ch) => ch.charCodeAt(0));
|
|
17822
|
+
return JSON.parse(new TextDecoder().decode(bytes));
|
|
17823
|
+
}
|
|
17824
|
+
function isDelegationCredentialPayload(payload) {
|
|
17825
|
+
if (typeof payload !== "object" || payload === null) return false;
|
|
17826
|
+
if ("vc" in payload) return true;
|
|
17827
|
+
const type = payload.type;
|
|
17828
|
+
return Array.isArray(type) && type.includes("DelegationCredential");
|
|
17829
|
+
}
|
|
17830
|
+
function looksLikeVcJwt(token) {
|
|
17831
|
+
const parts = token.split(".");
|
|
17832
|
+
if (parts.length !== 3 || parts.some((part) => part.length === 0)) return false;
|
|
17833
|
+
if (parts[1].length > MAX_VC_JWT_PAYLOAD_CHARS) return true;
|
|
17834
|
+
try {
|
|
17835
|
+
return isDelegationCredentialPayload(decodeBase64UrlJson(parts[1]));
|
|
17836
|
+
} catch {
|
|
17837
|
+
return false;
|
|
17838
|
+
}
|
|
17839
|
+
}
|
|
17840
|
+
/** Same definition as the .NET / Java `IsCredentialPresented`. */
|
|
17841
|
+
function requestPresentedCredential(headers) {
|
|
17842
|
+
if (!headers) return false;
|
|
17843
|
+
for (const name of ["signature-input", "signature"]) {
|
|
17844
|
+
const value = headerText(headers, name);
|
|
17845
|
+
if (value && hasKyaMember(value)) return true;
|
|
17846
|
+
}
|
|
17847
|
+
if (requestCarriesDelegationProof(headers)) return true;
|
|
17848
|
+
const bearer = headerText(headers, "authorization")?.match(/^bearer\s+(\S+)/i);
|
|
17849
|
+
return bearer !== null && bearer !== void 0 && looksLikeVcJwt(bearer[1]);
|
|
17850
|
+
}
|
|
16176
17851
|
|
|
16177
17852
|
//#endregion
|
|
16178
17853
|
//#region src/mcpi/principal.ts
|
|
@@ -18322,6 +19997,77 @@ const TrackingReadinessSchema = require_schemas.object({
|
|
|
18322
19997
|
}).strict())
|
|
18323
19998
|
}).strict();
|
|
18324
19999
|
|
|
20000
|
+
//#endregion
|
|
20001
|
+
//#region src/api/cli-registration.ts
|
|
20002
|
+
const CLI_PAIRING_PROTOCOL_VERSION = 2;
|
|
20003
|
+
const CLI_PAIRING_UPGRADE_MESSAGE = "Upgrade the KYA-OS CLI and run checkpoint init again. This pairing requires independent terminal proof.";
|
|
20004
|
+
const CliPairingProofSchema = require_schemas.string().regex(/^[A-Za-z0-9_-]{42}[AEIMQUYcgkosw048]$/);
|
|
20005
|
+
const CLI_PAIRING_FRAMEWORKS = [
|
|
20006
|
+
"nextjs",
|
|
20007
|
+
"express",
|
|
20008
|
+
"static",
|
|
20009
|
+
"unknown"
|
|
20010
|
+
];
|
|
20011
|
+
const readable = require_schemas.string().max(255).regex(READABLE_TEXT, READABLE_TEXT_MESSAGE);
|
|
20012
|
+
const label = readable.min(1);
|
|
20013
|
+
const hint = require_schemas.string().trim().min(1).max(255).regex(READABLE_TEXT, READABLE_TEXT_MESSAGE);
|
|
20014
|
+
const uuid = require_schemas.string().uuid();
|
|
20015
|
+
const CliPairingRegisterRequestSchema = require_schemas.object({
|
|
20016
|
+
protocolVersion: require_schemas.literal(2),
|
|
20017
|
+
exchangeChallenge: CliPairingProofSchema,
|
|
20018
|
+
domainHint: hint.optional(),
|
|
20019
|
+
repoName: hint.optional(),
|
|
20020
|
+
framework: require_schemas._enum(CLI_PAIRING_FRAMEWORKS).optional()
|
|
20021
|
+
}).strict();
|
|
20022
|
+
const CliPairingApprovedClaimSchema = require_schemas.object({
|
|
20023
|
+
userId: uuid,
|
|
20024
|
+
organizationId: uuid,
|
|
20025
|
+
projectId: uuid
|
|
20026
|
+
}).strict();
|
|
20027
|
+
const CliPairingClaimSchema = require_schemas.object({
|
|
20028
|
+
userId: uuid,
|
|
20029
|
+
userEmail: label,
|
|
20030
|
+
userName: readable.nullable(),
|
|
20031
|
+
organizationId: uuid,
|
|
20032
|
+
organizationName: label,
|
|
20033
|
+
organizationSlug: readable.nullable(),
|
|
20034
|
+
projectId: uuid,
|
|
20035
|
+
projectName: label,
|
|
20036
|
+
projectDomain: readable.nullable()
|
|
20037
|
+
}).strict();
|
|
20038
|
+
const CliPairingExchangeRequestSchema = require_schemas.object({
|
|
20039
|
+
protocolVersion: require_schemas.literal(2),
|
|
20040
|
+
registrationId: uuid,
|
|
20041
|
+
exchangeVerifier: CliPairingProofSchema,
|
|
20042
|
+
approvedClaim: CliPairingApprovedClaimSchema
|
|
20043
|
+
}).strict();
|
|
20044
|
+
const CliPairingRegisterDataSchema = require_schemas.object({
|
|
20045
|
+
protocolVersion: require_schemas.literal(2),
|
|
20046
|
+
registrationId: uuid,
|
|
20047
|
+
claimToken: require_schemas.string().regex(/^cliclaim_[a-f0-9]{64}$/),
|
|
20048
|
+
claimUrl: require_schemas.string().url(),
|
|
20049
|
+
confirmationCode: require_schemas.string().regex(/^[BCDFGHJKLMNPQRSTVWXZ]{4}-[BCDFGHJKLMNPQRSTVWXZ]{4}$/),
|
|
20050
|
+
expiresAt: require_schemas.string().datetime()
|
|
20051
|
+
}).strict();
|
|
20052
|
+
const CliPairingPrivateStatusDataSchema = require_schemas.discriminatedUnion("status", [require_schemas.object({
|
|
20053
|
+
protocolVersion: require_schemas.literal(2),
|
|
20054
|
+
status: require_schemas.literal("pending"),
|
|
20055
|
+
claimed: require_schemas._null()
|
|
20056
|
+
}).strict(), require_schemas.object({
|
|
20057
|
+
protocolVersion: require_schemas.literal(2),
|
|
20058
|
+
status: require_schemas.literal("claimed"),
|
|
20059
|
+
claimed: CliPairingClaimSchema
|
|
20060
|
+
}).strict()]);
|
|
20061
|
+
const CliPairingExchangeDataSchema = require_schemas.object({
|
|
20062
|
+
protocolVersion: require_schemas.literal(2),
|
|
20063
|
+
userId: uuid,
|
|
20064
|
+
projectId: uuid,
|
|
20065
|
+
organizationId: uuid,
|
|
20066
|
+
friendlyId: require_schemas.string().nullable(),
|
|
20067
|
+
apiKey: require_schemas.string().regex(/^sk_[a-f0-9]{64}$/),
|
|
20068
|
+
dashboardUrl: require_schemas.string().url()
|
|
20069
|
+
}).strict();
|
|
20070
|
+
|
|
18325
20071
|
//#endregion
|
|
18326
20072
|
//#region src/index.ts
|
|
18327
20073
|
const VERSION = "0.1.0";
|
|
@@ -18334,12 +20080,16 @@ exports.A2ATaskRequestSchema = A2ATaskRequestSchema;
|
|
|
18334
20080
|
exports.A2ATaskSourceConfigSchema = A2ATaskSourceConfigSchema;
|
|
18335
20081
|
exports.A2ATaskStateSchema = A2ATaskStateSchema;
|
|
18336
20082
|
exports.ACCEPT_CHALLENGE_HEADER = ACCEPT_CHALLENGE_HEADER;
|
|
20083
|
+
exports.ADMIN_ACCOUNTS_STATUS_FILTERS = ADMIN_ACCOUNTS_STATUS_FILTERS;
|
|
20084
|
+
exports.ADMIN_ACCOUNT_STATUSES = ADMIN_ACCOUNT_STATUSES;
|
|
18337
20085
|
exports.ADMIN_DELTA_BASES = ADMIN_DELTA_BASES;
|
|
20086
|
+
exports.ADMIN_ORG_EXCLUSION_REASONS = ADMIN_ORG_EXCLUSION_REASONS;
|
|
18338
20087
|
exports.ADMIN_OVERVIEW_CACHE_STATUSES = ADMIN_OVERVIEW_CACHE_STATUSES;
|
|
18339
20088
|
exports.ADMIN_OVERVIEW_LIST_LIMIT_DEFAULT = ADMIN_OVERVIEW_LIST_LIMIT_DEFAULT;
|
|
18340
20089
|
exports.ADMIN_OVERVIEW_LIST_LIMIT_MAX = ADMIN_OVERVIEW_LIST_LIMIT_MAX;
|
|
18341
20090
|
exports.ADMIN_OVERVIEW_SECTIONS = ADMIN_OVERVIEW_SECTIONS;
|
|
18342
20091
|
exports.ADMIN_OVERVIEW_WINDOWS = ADMIN_OVERVIEW_WINDOWS;
|
|
20092
|
+
exports.ADMIN_TRUSTED_METRICS = ADMIN_TRUSTED_METRICS;
|
|
18343
20093
|
exports.AGENT_CATEGORY_META = AGENT_CATEGORY_META;
|
|
18344
20094
|
exports.AI_AGENT_HEADERS = AI_AGENT_HEADERS;
|
|
18345
20095
|
exports.ANALYTICS_ERRORS = ANALYTICS_ERRORS;
|
|
@@ -18380,6 +20130,7 @@ exports.AgentTypeDefinitionSchema = AgentTypeDefinitionSchema;
|
|
|
18380
20130
|
exports.AgentTypeSchema = AgentTypeSchema;
|
|
18381
20131
|
exports.AggregationTypeSchema = AggregationTypeSchema;
|
|
18382
20132
|
exports.AllowListEntrySchema = AllowListEntrySchema;
|
|
20133
|
+
exports.AllowedDomainsSchema = AllowedDomainsSchema;
|
|
18383
20134
|
exports.AnalyticsAgentSourcesQuerySchema = AnalyticsAgentSourcesQuerySchema;
|
|
18384
20135
|
exports.AnalyticsAgentTypesQuerySchema = AnalyticsAgentTypesQuerySchema;
|
|
18385
20136
|
exports.AnalyticsChartDataSchema = AnalyticsChartDataSchema;
|
|
@@ -18451,8 +20202,12 @@ exports.BulkOperationResultSchema = BulkOperationResultSchema;
|
|
|
18451
20202
|
exports.BulkOperationTypeSchema = BulkOperationTypeSchema;
|
|
18452
20203
|
exports.BulkResponseSchema = BulkResponseSchema;
|
|
18453
20204
|
exports.BulkResultItemSchema = BulkResultItemSchema;
|
|
20205
|
+
exports.ByteBoundedMemo = ByteBoundedMemo;
|
|
18454
20206
|
exports.CACHE_LIMITS = CACHE_LIMITS;
|
|
18455
20207
|
exports.CACHE_TTL = CACHE_TTL;
|
|
20208
|
+
exports.CLI_PAIRING_FRAMEWORKS = CLI_PAIRING_FRAMEWORKS;
|
|
20209
|
+
exports.CLI_PAIRING_PROTOCOL_VERSION = CLI_PAIRING_PROTOCOL_VERSION;
|
|
20210
|
+
exports.CLI_PAIRING_UPGRADE_MESSAGE = CLI_PAIRING_UPGRADE_MESSAGE;
|
|
18456
20211
|
exports.CLOUD_PROVIDER_RANGES = CLOUD_PROVIDER_RANGES;
|
|
18457
20212
|
exports.CONDITION_FIELDS = CONDITION_FIELDS;
|
|
18458
20213
|
exports.CONDITION_OPERATORS = CONDITION_OPERATORS;
|
|
@@ -18470,6 +20225,14 @@ exports.ClaimVerificationSchema = ClaimVerificationSchema;
|
|
|
18470
20225
|
exports.CliIdentityQuerySchema = CliIdentityQuerySchema;
|
|
18471
20226
|
exports.CliIdentityServiceSchema = CliIdentityServiceSchema;
|
|
18472
20227
|
exports.CliIdentitySummarySchema = CliIdentitySummarySchema;
|
|
20228
|
+
exports.CliPairingApprovedClaimSchema = CliPairingApprovedClaimSchema;
|
|
20229
|
+
exports.CliPairingClaimSchema = CliPairingClaimSchema;
|
|
20230
|
+
exports.CliPairingExchangeDataSchema = CliPairingExchangeDataSchema;
|
|
20231
|
+
exports.CliPairingExchangeRequestSchema = CliPairingExchangeRequestSchema;
|
|
20232
|
+
exports.CliPairingPrivateStatusDataSchema = CliPairingPrivateStatusDataSchema;
|
|
20233
|
+
exports.CliPairingProofSchema = CliPairingProofSchema;
|
|
20234
|
+
exports.CliPairingRegisterDataSchema = CliPairingRegisterDataSchema;
|
|
20235
|
+
exports.CliPairingRegisterRequestSchema = CliPairingRegisterRequestSchema;
|
|
18473
20236
|
exports.ClickEventSchema = ClickEventSchema;
|
|
18474
20237
|
exports.ClientDetectionSchema = ClientDetectionSchema;
|
|
18475
20238
|
exports.CollectFingerprintRequestSchema = CollectFingerprintRequestSchema;
|
|
@@ -18492,6 +20255,12 @@ exports.ConsentCapabilityGroupSchema = ConsentCapabilityGroupSchema;
|
|
|
18492
20255
|
exports.ConsentCapabilitySchema = ConsentCapabilitySchema;
|
|
18493
20256
|
exports.ConsentConfigMetadataSchema = ConsentConfigMetadataSchema;
|
|
18494
20257
|
exports.ConsentConfigSchema = ConsentConfigSchema;
|
|
20258
|
+
exports.ConsentInputCopySchema = ConsentInputCopySchema;
|
|
20259
|
+
exports.ConsentPolicyCapabilitySchema = ConsentPolicyCapabilitySchema;
|
|
20260
|
+
exports.ConsentPolicyResponseSchema = ConsentPolicyResponseSchema;
|
|
20261
|
+
exports.ConsentPolicyRiskLevelSchema = ConsentPolicyRiskLevelSchema;
|
|
20262
|
+
exports.ConsentScopeLabelsSchema = ConsentScopeLabelsSchema;
|
|
20263
|
+
exports.ConsentSignInCopySchema = ConsentSignInCopySchema;
|
|
18495
20264
|
exports.ConsentTermsSchema = ConsentTermsSchema;
|
|
18496
20265
|
exports.ConsentUISchema = ConsentUISchema;
|
|
18497
20266
|
exports.ConsumedArtifactSchema = ConsumedArtifactSchema;
|
|
@@ -18622,6 +20391,9 @@ exports.EventTrackingRequestSchema = EventTrackingRequestSchema;
|
|
|
18622
20391
|
exports.EventTrackingResponseSchema = EventTrackingResponseSchema;
|
|
18623
20392
|
exports.ExportAnalyticsSchema = ExportAnalyticsSchema;
|
|
18624
20393
|
exports.ExpressMiddlewareOptionsSchema = ExpressMiddlewareOptionsSchema;
|
|
20394
|
+
exports.FAIL_CLOSED_BODY = FAIL_CLOSED_BODY;
|
|
20395
|
+
exports.FAIL_CLOSED_HEADERS = FAIL_CLOSED_HEADERS;
|
|
20396
|
+
exports.FAIL_CLOSED_STATUS = FAIL_CLOSED_STATUS;
|
|
18625
20397
|
exports.FallbackOptionsSchema = FallbackOptionsSchema;
|
|
18626
20398
|
exports.FilterOperatorSchema = FilterOperatorSchema;
|
|
18627
20399
|
exports.FingerprintAnalysisSchema = FingerprintAnalysisSchema;
|
|
@@ -18632,6 +20404,7 @@ exports.FingerprintResponseSchema = FingerprintResponseSchema;
|
|
|
18632
20404
|
exports.FingerprintSearchQuerySchema = FingerprintSearchQuerySchema;
|
|
18633
20405
|
exports.FleetPullRequestReceiptSchema = FleetPullRequestReceiptSchema;
|
|
18634
20406
|
exports.ForgeabilityRiskSchema = ForgeabilityRiskSchema;
|
|
20407
|
+
exports.GATEWAY_VAULT_ERRORS = GATEWAY_VAULT_ERRORS;
|
|
18635
20408
|
exports.GitHubTaskSourceConfigSchema = GitHubTaskSourceConfigSchema;
|
|
18636
20409
|
exports.GrowthBatchRequestSchema = GrowthBatchRequestSchema;
|
|
18637
20410
|
exports.GrowthConfigurationResetSchema = GrowthConfigurationResetSchema;
|
|
@@ -18692,6 +20465,8 @@ exports.MANAGEMENT_DEVICE_INTERVAL = MANAGEMENT_DEVICE_INTERVAL;
|
|
|
18692
20465
|
exports.MANAGEMENT_REFRESH_PREFIX = MANAGEMENT_REFRESH_PREFIX;
|
|
18693
20466
|
exports.MANAGEMENT_USER_CODE_ALPHABET = MANAGEMENT_USER_CODE_ALPHABET;
|
|
18694
20467
|
exports.MATCH_ACTIONS = MATCH_ACTIONS;
|
|
20468
|
+
exports.MAX_ALLOWED_DOMAINS = MAX_ALLOWED_DOMAINS;
|
|
20469
|
+
exports.MAX_ALLOWED_DOMAIN_LENGTH = MAX_ALLOWED_DOMAIN_LENGTH;
|
|
18695
20470
|
exports.MAX_BULK_BATCH_SIZE = MAX_BULK_BATCH_SIZE;
|
|
18696
20471
|
exports.MAX_ED25519_KEY_BODY_LENGTH = MAX_ED25519_KEY_BODY_LENGTH;
|
|
18697
20472
|
exports.MAX_REASON_CODES_HEADER_BYTES = MAX_REASON_CODES_HEADER_BYTES;
|
|
@@ -18748,6 +20523,9 @@ exports.ModelCredentialRevocationSchema = ModelCredentialRevocationSchema;
|
|
|
18748
20523
|
exports.ModelCredentialSchema = ModelCredentialSchema;
|
|
18749
20524
|
exports.MouseEventSchema = MouseEventSchema;
|
|
18750
20525
|
exports.NETWORK_ERRORS = NETWORK_ERRORS;
|
|
20526
|
+
exports.NO_EVIDENCE_CATEGORY = NO_EVIDENCE_CATEGORY;
|
|
20527
|
+
exports.NO_EVIDENCE_EQUALITY_TERM = NO_EVIDENCE_EQUALITY_TERM;
|
|
20528
|
+
exports.NO_EVIDENCE_EXCLUSION_TERM = NO_EVIDENCE_EXCLUSION_TERM;
|
|
18751
20529
|
exports.NetworkConfigSchema = NetworkConfigSchema;
|
|
18752
20530
|
exports.NetworkContextSchema = NetworkContextSchema;
|
|
18753
20531
|
exports.NetworkInfoSchema = NetworkInfoSchema;
|
|
@@ -18856,9 +20634,14 @@ Object.defineProperty(exports, 'ProviderRegistryDefinitionSchema', {
|
|
|
18856
20634
|
exports.ProvidersResponseSchema = ProvidersResponseSchema;
|
|
18857
20635
|
exports.ProvisionKeyRequestSchema = ProvisionKeyRequestSchema;
|
|
18858
20636
|
exports.ProvisionKeyResponseSchema = ProvisionKeyResponseSchema;
|
|
20637
|
+
exports.ProvisioningAccountLinkRequestSchema = ProvisioningAccountLinkRequestSchema;
|
|
20638
|
+
exports.ProvisioningAccountLinkResponseSchema = ProvisioningAccountLinkResponseSchema;
|
|
20639
|
+
exports.ProvisioningIdentityProofSchema = ProvisioningIdentityProofSchema;
|
|
18859
20640
|
exports.ProvisioningModeSchema = ProvisioningModeSchema;
|
|
18860
20641
|
exports.ProvisioningOrganizationRoleSchema = ProvisioningOrganizationRoleSchema;
|
|
18861
20642
|
exports.ProvisioningOrganizationSummarySchema = ProvisioningOrganizationSummarySchema;
|
|
20643
|
+
exports.ProxyAssertionSchema = ProxyAssertionSchema;
|
|
20644
|
+
exports.ProxyCollectionStateSchema = ProxyCollectionStateSchema;
|
|
18862
20645
|
exports.ProxyInfoSchema = ProxyInfoSchema;
|
|
18863
20646
|
exports.ProxyTypeSchema = ProxyTypeSchema;
|
|
18864
20647
|
exports.PublicAnalyticsBotTypeSchema = PublicAnalyticsBotTypeSchema;
|
|
@@ -19063,6 +20846,7 @@ exports.UserSchema = UserSchema;
|
|
|
19063
20846
|
exports.VALIDATION_ERRORS = VALIDATION_ERRORS;
|
|
19064
20847
|
exports.VALIDATION_MODES = VALIDATION_MODES;
|
|
19065
20848
|
exports.VALIDATION_PATTERNS = require_posture_origins.VALIDATION_PATTERNS;
|
|
20849
|
+
exports.VAULT_ERRORS = VAULT_ERRORS;
|
|
19066
20850
|
exports.VERDICT_COOKIE_NAME = VERDICT_COOKIE_NAME;
|
|
19067
20851
|
exports.VERSION = VERSION;
|
|
19068
20852
|
exports.VerdictEvidenceSchema = VerdictEvidenceSchema;
|
|
@@ -19099,7 +20883,9 @@ exports.WorkloadEnrollmentRevocationSchema = WorkloadEnrollmentRevocationSchema;
|
|
|
19099
20883
|
exports.WorkloadEnrollmentSchema = WorkloadEnrollmentSchema;
|
|
19100
20884
|
exports.WorkloadRotationProofPayloadSchema = WorkloadRotationProofPayloadSchema;
|
|
19101
20885
|
exports.acceptsHtml = acceptsHtml;
|
|
20886
|
+
exports.adminAccountsQuerySchema = adminAccountsQuerySchema;
|
|
19102
20887
|
exports.adminOverviewQuerySchema = adminOverviewQuerySchema;
|
|
20888
|
+
exports.analyzePolicySource = analyzePolicySource;
|
|
19103
20889
|
exports.approvalQuorumForRequest = approvalQuorumForRequest;
|
|
19104
20890
|
exports.assertVendorRangesFresh = assertVendorRangesFresh;
|
|
19105
20891
|
exports.assignmentChangeRequestSchema = assignmentChangeRequestSchema;
|
|
@@ -19200,12 +20986,14 @@ exports.hasClaudeCodeToken = hasClaudeCodeToken;
|
|
|
19200
20986
|
exports.hasClaudeSearchBotToken = hasClaudeSearchBotToken;
|
|
19201
20987
|
exports.hasClaudeUserToken = hasClaudeUserToken;
|
|
19202
20988
|
exports.hasPinnedSigningVendor = hasPinnedSigningVendor;
|
|
20989
|
+
exports.hostMatchesAllowedDomains = hostMatchesAllowedDomains;
|
|
19203
20990
|
exports.initializePolicyFetcher = initializePolicyFetcher;
|
|
19204
20991
|
exports.ipAddressSchema = ipAddressSchema;
|
|
19205
20992
|
exports.isAuthorizedLead = isAuthorizedLead;
|
|
19206
20993
|
exports.isBespokePolicyId = isBespokePolicyId;
|
|
19207
20994
|
exports.isBlockingAction = isBlockingAction;
|
|
19208
20995
|
exports.isClaudeProductLabel = isClaudeProductLabel;
|
|
20996
|
+
exports.isEngineEnforcing = isEngineEnforcing;
|
|
19209
20997
|
exports.isForbidBlock = isForbidBlock;
|
|
19210
20998
|
exports.isHighConfidenceVerification = isHighConfidenceVerification;
|
|
19211
20999
|
exports.isKnownAgentType = isKnownAgentType;
|
|
@@ -19227,10 +21015,12 @@ exports.isValidFingerprintResponse = isValidFingerprintResponse;
|
|
|
19227
21015
|
exports.isValidMcpiOrgSlug = isValidMcpiOrgSlug;
|
|
19228
21016
|
exports.isValidWasmDetectionResult = isValidWasmDetectionResult;
|
|
19229
21017
|
exports.isValidWasmRequestMetadata = isValidWasmRequestMetadata;
|
|
21018
|
+
exports.lintMissingBaselinePermit = lintMissingBaselinePermit;
|
|
19230
21019
|
exports.lintUnnarrowedDenyRules = lintUnnarrowedDenyRules;
|
|
19231
21020
|
exports.loadRulesAsync = loadRulesAsync;
|
|
19232
21021
|
exports.mapDetectionToReasonCodes = mapDetectionToReasonCodes;
|
|
19233
21022
|
exports.mapLegacyAuthType = mapLegacyAuthType;
|
|
21023
|
+
exports.mapProxyAssertions = mapProxyAssertions;
|
|
19234
21024
|
exports.mapToLegacyAuthType = mapToLegacyAuthType;
|
|
19235
21025
|
exports.matchPath = matchPath;
|
|
19236
21026
|
exports.mergeWithDefaults = mergeWithDefaults;
|
|
@@ -19238,6 +21028,8 @@ exports.migrateLegacyDetectionClass = migrateLegacyDetectionClass;
|
|
|
19238
21028
|
exports.modelCredentialFingerprint = modelCredentialFingerprint;
|
|
19239
21029
|
exports.nonNavigablePolicyLabel = nonNavigablePolicyLabel;
|
|
19240
21030
|
exports.normalizeAgentName = normalizeAgentName;
|
|
21031
|
+
exports.normalizeAllowedDomainForWrite = normalizeAllowedDomainForWrite;
|
|
21032
|
+
exports.normalizeAllowedDomainList = normalizeAllowedDomainList;
|
|
19241
21033
|
exports.normalizeChallengeType = normalizeChallengeType;
|
|
19242
21034
|
exports.normalizeClientIp = require_client_ip.normalizeClientIp;
|
|
19243
21035
|
exports.normalizeConfidence = normalizeConfidence;
|
|
@@ -19245,10 +21037,12 @@ exports.normalizeDetectionClass = normalizeDetectionClass;
|
|
|
19245
21037
|
exports.normalizeDetectionClassEnum = normalizeDetectionClassEnum;
|
|
19246
21038
|
exports.normalizeHandshakeMethod = normalizeHandshakeMethod;
|
|
19247
21039
|
exports.normalizeOrganizationName = normalizeOrganizationName;
|
|
21040
|
+
exports.normalizeStoredAllowedDomain = normalizeStoredAllowedDomain;
|
|
19248
21041
|
exports.normalizeWireMethod = normalizeWireMethod;
|
|
19249
21042
|
exports.oauthClientSchema = oauthClientSchema;
|
|
19250
21043
|
exports.parseAcceptedArtifactRevision = parseAcceptedArtifactRevision;
|
|
19251
21044
|
exports.parseAgentName = parseAgentName;
|
|
21045
|
+
exports.parseCedarStatements = parseCedarStatements;
|
|
19252
21046
|
exports.parseClaimVerification = parseClaimVerification;
|
|
19253
21047
|
exports.parseDependencyBinding = parseDependencyBinding;
|
|
19254
21048
|
exports.parseEvaluationContext = parseEvaluationContext;
|
|
@@ -19260,7 +21054,9 @@ exports.parsePolicyConfig = parsePolicyConfig;
|
|
|
19260
21054
|
exports.parseRules = parseRules;
|
|
19261
21055
|
exports.partial = partial;
|
|
19262
21056
|
exports.passwordSchema = passwordSchema;
|
|
21057
|
+
exports.pathHasExplicitDenyRuleFor = pathHasExplicitDenyRuleFor;
|
|
19263
21058
|
exports.pathHasUnnarrowedDenyRule = pathHasUnnarrowedDenyRule;
|
|
21059
|
+
exports.pathHasUnnarrowedDenyRuleFor = pathHasUnnarrowedDenyRuleFor;
|
|
19264
21060
|
exports.pathLiteralsInBlock = pathLiteralsInBlock;
|
|
19265
21061
|
exports.permitDelegationVerdict = permitDelegationVerdict;
|
|
19266
21062
|
exports.projectResetRequestSchema = projectResetRequestSchema;
|
|
@@ -19269,6 +21065,7 @@ exports.reconstructConfidenceFromEvidence = reconstructConfidenceFromEvidence;
|
|
|
19269
21065
|
exports.refineClaudeDisplayLabel = refineClaudeDisplayLabel;
|
|
19270
21066
|
exports.refineSessionGrainClaudeLabel = refineSessionGrainClaudeLabel;
|
|
19271
21067
|
exports.requestCarriesDelegationProof = requestCarriesDelegationProof;
|
|
21068
|
+
exports.requestPresentedCredential = requestPresentedCredential;
|
|
19272
21069
|
exports.requiredScopesForRequest = requiredScopesForRequest;
|
|
19273
21070
|
exports.resetPasswordSchema = resetPasswordSchema;
|
|
19274
21071
|
exports.resetPolicyFetcher = resetPolicyFetcher;
|
|
@@ -19287,6 +21084,8 @@ exports.serveBodyReadable200 = serveBodyReadable200;
|
|
|
19287
21084
|
exports.signInSchema = signInSchema;
|
|
19288
21085
|
exports.signUpSchema = signUpSchema;
|
|
19289
21086
|
exports.splitCedarBlocks = splitCedarBlocks;
|
|
21087
|
+
exports.statementApplies = statementApplies;
|
|
21088
|
+
exports.statementId = statementId;
|
|
19290
21089
|
exports.strict = strict;
|
|
19291
21090
|
exports.supportsClientSide = supportsClientSide;
|
|
19292
21091
|
exports.supportsHeaders = supportsHeaders;
|
|
@@ -19333,4 +21132,5 @@ exports.vaultResolveResponseSchema = vaultResolveResponseSchema;
|
|
|
19333
21132
|
exports.vaultResolveSuccessSchema = vaultResolveSuccessSchema;
|
|
19334
21133
|
exports.verifyContractRecordIdentity = verifyContractRecordIdentity;
|
|
19335
21134
|
exports.verifyEmailSchema = verifyEmailSchema;
|
|
19336
|
-
exports.wasmToDetectionResult = wasmToDetectionResult;
|
|
21135
|
+
exports.wasmToDetectionResult = wasmToDetectionResult;
|
|
21136
|
+
exports.withNoEvidenceExclusion = withNoEvidenceExclusion;
|