@kya-os/checkpoint-shared 1.0.0 → 1.1.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/dist/index.js CHANGED
@@ -5061,7 +5061,7 @@ var EngineInfoSchema = external_exports.object({
5061
5061
  buildSha: external_exports.string().optional(),
5062
5062
  extras: external_exports.record(external_exports.unknown()).optional()
5063
5063
  });
5064
- var DetectionResultSchema = external_exports.object({
5064
+ var DetectionDetailSchema = external_exports.object({
5065
5065
  // Core fields
5066
5066
  /**
5067
5067
  * @deprecated Use detectionClass instead. Will be removed in v2.0.0
@@ -5122,6 +5122,7 @@ var DetectionResultSchema = external_exports.object({
5122
5122
  * pre-Phase-0.1 SDKs; dashboard treats absence as "legacy SDK." */
5123
5123
  engine: EngineInfoSchema.optional()
5124
5124
  });
5125
+ var DetectionResultSchema = DetectionDetailSchema;
5125
5126
  var DetectionModeSchema = external_exports.enum(["strict", "balanced", "lenient"]);
5126
5127
  var CustomRuleSchema = external_exports.object({
5127
5128
  id: external_exports.string(),
@@ -5206,62 +5207,12 @@ var AI_CRAWLER_NAMES = [
5206
5207
  "amazon bedrock",
5207
5208
  "vertex"
5208
5209
  ];
5209
- function shouldEnforce(result) {
5210
- if (result.isAgent || result.isAiCrawler) return true;
5211
- const name = (result.agentName || result.agent || result.detectedAgent?.name || "").toLowerCase();
5212
- if (!name) return false;
5213
- return AI_CRAWLER_NAMES.some((crawler) => name.includes(crawler));
5214
- }
5215
5210
  function isKnownAiCrawler(agentName) {
5216
5211
  if (!agentName) return false;
5217
5212
  const lower = agentName.toLowerCase();
5218
5213
  return AI_CRAWLER_NAMES.some((crawler) => lower.includes(crawler));
5219
5214
  }
5220
5215
 
5221
- // src/core/enforcement.ts
5222
- function evaluateEnforcement(result, config = {}) {
5223
- const {
5224
- enabled = true,
5225
- confidenceThreshold = 70,
5226
- defaultAction = "allow",
5227
- redirectUrl,
5228
- allowList = [],
5229
- denyList = []
5230
- } = config;
5231
- if (!enabled) {
5232
- return { action: "allow", reason: "enforcement_disabled", shouldNotify: false };
5233
- }
5234
- if (!shouldEnforce(result)) {
5235
- return { action: "allow", reason: "not_enforced", shouldNotify: false };
5236
- }
5237
- const agentName = result.agentName || result.agent || result.detectedAgent?.name || void 0;
5238
- if (allowList.length > 0 && agentName) {
5239
- const lower = agentName.toLowerCase();
5240
- if (allowList.some((a) => lower.includes(a.toLowerCase()))) {
5241
- return { action: "allow", reason: "allow_list", shouldNotify: false };
5242
- }
5243
- }
5244
- if (denyList.length > 0 && agentName) {
5245
- const lower = agentName.toLowerCase();
5246
- if (denyList.some((d) => lower.includes(d.toLowerCase()))) {
5247
- return {
5248
- action: "block",
5249
- reason: "deny_list",
5250
- shouldNotify: true
5251
- };
5252
- }
5253
- }
5254
- if (result.confidence >= confidenceThreshold) {
5255
- return {
5256
- action: defaultAction,
5257
- reason: "threshold",
5258
- shouldNotify: true,
5259
- redirectUrl: defaultAction === "redirect" || defaultAction === "instruct" ? redirectUrl : void 0
5260
- };
5261
- }
5262
- return { action: "allow", reason: "below_threshold", shouldNotify: false };
5263
- }
5264
-
5265
5216
  // src/core/agent.ts
5266
5217
  var AgentTypeSchema = external_exports.enum([
5267
5218
  // OpenAI
@@ -5554,6 +5505,32 @@ var KNOWN_AGENT_PATTERNS = [
5554
5505
  category: "ai_assistant",
5555
5506
  isLegitimate: true
5556
5507
  },
5508
+ // GPT-Crawler — distinct from GPTBot (OpenAI's official training crawler);
5509
+ // tracked separately so the classifier can attribute hits to the
5510
+ // right entity. PDM-2 promoted from the INTERACTIVE_AGENT_PATTERNS
5511
+ // supplement.
5512
+ {
5513
+ id: "openai-gpt-crawler",
5514
+ type: "openai",
5515
+ name: "GPT Crawler",
5516
+ patterns: ["GPT-Crawler"],
5517
+ confidence: 0.95,
5518
+ category: "scraper",
5519
+ isLegitimate: true
5520
+ },
5521
+ // OpenAI generic vendor fallback — catches UAs that mention OpenAI
5522
+ // but use an undocumented sub-token (e.g. `OpenAI-Foo/1.0`,
5523
+ // `OpenAI-Web/2.0`). Word-boundary anchored (post-#2599). Lower
5524
+ // confidence than the strict per-token entries above. PDM-2.
5525
+ {
5526
+ id: "openai-generic",
5527
+ type: "openai",
5528
+ name: "OpenAI",
5529
+ patterns: ["OpenAI"],
5530
+ confidence: 0.9,
5531
+ category: "ai_assistant",
5532
+ isLegitimate: true
5533
+ },
5557
5534
  // Anthropic — split into interactive assistant vs training crawler.
5558
5535
  // The 'anthropic-ai' UA token used to live in this entry's patterns
5559
5536
  // alongside 'Claude-Web', which made every anthropic-ai crawler hit
@@ -5609,8 +5586,24 @@ var KNOWN_AGENT_PATTERNS = [
5609
5586
  category: "scraper",
5610
5587
  isLegitimate: true
5611
5588
  },
5589
+ // Anthropic generic vendor fallback — catches UAs that mention
5590
+ // Anthropic but use an undocumented sub-token (e.g. `Anthropic-Web`,
5591
+ // future variants). Word-boundary anchored (post-#2599) — only
5592
+ // matches when `Anthropic` is a standalone token, not embedded in
5593
+ // e.g. `AnthropicAssistant`. Lower confidence than the per-token
5594
+ // entries above. PDM-2 promoted from the INTERACTIVE_AGENT_PATTERNS
5595
+ // supplement.
5596
+ {
5597
+ id: "anthropic-generic",
5598
+ type: "anthropic",
5599
+ name: "Anthropic",
5600
+ patterns: ["Anthropic"],
5601
+ confidence: 0.9,
5602
+ category: "ai_assistant",
5603
+ isLegitimate: true
5604
+ },
5612
5605
  // Perplexity (training crawler, distinct from the interactive Perplexity-User
5613
- // session captured by seed-agent-types-data.ts:perplexity)
5606
+ // session captured by perplexity-user below)
5614
5607
  {
5615
5608
  id: "perplexity-bot",
5616
5609
  type: "perplexity",
@@ -5620,6 +5613,34 @@ var KNOWN_AGENT_PATTERNS = [
5620
5613
  category: "scraper",
5621
5614
  isLegitimate: true
5622
5615
  },
5616
+ // Interactive Perplexity fetcher — parallel to ChatGPT-User shape;
5617
+ // the assistant pulls a URL on a human's behalf. Distinct from
5618
+ // PerplexityBot (training crawler). PDM-2 promoted this from the
5619
+ // INTERACTIVE_AGENT_PATTERNS supplement that #2599 carved out.
5620
+ {
5621
+ id: "perplexity-user",
5622
+ type: "perplexity",
5623
+ name: "Perplexity",
5624
+ patterns: ["Perplexity-User", "Perplexity-AI"],
5625
+ confidence: 0.95,
5626
+ category: "ai_assistant",
5627
+ isLegitimate: true
5628
+ },
5629
+ // Perplexity generic vendor fallback — catches UAs that mention
5630
+ // Perplexity but use an undocumented sub-token (future variants).
5631
+ // Lower confidence than the strict per-token entries above; the
5632
+ // matcher picks the highest-confidence match, so this only wins on
5633
+ // truly unknown shapes. Word-boundary anchored (post-#2599) so
5634
+ // `perplexity` only matches as a standalone token, not embedded.
5635
+ {
5636
+ id: "perplexity-generic",
5637
+ type: "perplexity",
5638
+ name: "Perplexity",
5639
+ patterns: ["Perplexity"],
5640
+ confidence: 0.85,
5641
+ category: "ai_assistant",
5642
+ isLegitimate: true
5643
+ },
5623
5644
  // Google — split into crawler (Google-Extended) vs interactive (Bard, Gemini, etc.) (PR-C)
5624
5645
  {
5625
5646
  id: "google-extended",
@@ -5918,6 +5939,21 @@ var BOT_USER_AGENT_PATTERNS = [
5918
5939
  /yi(-?[0-9]+b)?/i,
5919
5940
  /stablelm/i,
5920
5941
  /\bphind\b/i,
5942
+ // `you.com` is detected as a UA SUBSTRING — the pattern is consumed
5943
+ // only by `BOT_USER_AGENT_PATTERNS.some(p => p.test(userAgent))`
5944
+ // (UA context, not URL). CodeQL js/regex/missing-regexp-anchor
5945
+ // speculated about URL misuse on PR #2576; PR #2591's tightened
5946
+ // consuming-class form (`[\s;()]`) introduced a real false-negative
5947
+ // for legit UA shapes containing `/`:
5948
+ // - `you.com/1.0` (You.com bot, version-suffixed)
5949
+ // - `Mozilla/5.0 you.com/bot` (token-with-version)
5950
+ // - `+https://you.com)` (token after URL inside parens)
5951
+ // Cursor caught the regression on PR #2591. Reverting to `\b` —
5952
+ // word-boundary is the correct anchor for UA-substring matching;
5953
+ // the original CodeQL flag is a context-blind false positive (the
5954
+ // codebase does not apply BOT_USER_AGENT_PATTERNS to URL strings).
5955
+ // If CodeQL re-flags, dismiss in the UI as "false positive" with
5956
+ // pointer to this comment.
5921
5957
  /\byou\.com\b/i,
5922
5958
  /\bneeva\b/i,
5923
5959
  /jasper/i,
@@ -6913,10 +6949,13 @@ var SUSPICIOUS_PATTERNS = {
6913
6949
  URL_ENCODED: /%[0-9a-f]{2}/i,
6914
6950
  BASE64_DATA: /data:[^;]+;base64,/i
6915
6951
  };
6952
+ var MAX_PATTERN_INPUT_LENGTH = 4096;
6916
6953
  function testPattern(pattern, value) {
6954
+ if (value.length > MAX_PATTERN_INPUT_LENGTH) return false;
6917
6955
  return pattern.test(value);
6918
6956
  }
6919
6957
  function extractMatch(pattern, value) {
6958
+ if (value.length > MAX_PATTERN_INPUT_LENGTH) return null;
6920
6959
  const match = value.match(pattern);
6921
6960
  return match ? match[1] || match[0] : null;
6922
6961
  }
@@ -11336,62 +11375,6 @@ function createValidationErrorResponse(message, details, meta) {
11336
11375
  }
11337
11376
 
11338
11377
  // src/utils/verification.ts
11339
- function mapVerificationMethod(method) {
11340
- if (!method) return "none";
11341
- const normalized = method.toLowerCase().trim();
11342
- switch (normalized) {
11343
- // Signature-based verification
11344
- case "signature":
11345
- case "sig":
11346
- case "signature_verified":
11347
- case "http_signature":
11348
- return "signature";
11349
- // Pattern-based detection
11350
- case "pattern":
11351
- case "useragent":
11352
- case "user_agent":
11353
- case "pattern_matching":
11354
- case "ua_pattern":
11355
- return "pattern";
11356
- // Behavioral analysis
11357
- case "behavioral":
11358
- case "behavior":
11359
- case "behavioral_analysis":
11360
- case "mouse_keyboard":
11361
- return "behavioral";
11362
- // Network-based detection
11363
- case "network":
11364
- case "ip":
11365
- case "ip_analysis":
11366
- case "cloud_provider":
11367
- return "network";
11368
- // MCP handshake detection
11369
- case "mcp_i_handshake":
11370
- case "mcp":
11371
- case "handshake":
11372
- return "mcp_i_handshake";
11373
- // Error states
11374
- case "error":
11375
- case "failed":
11376
- case "timeout":
11377
- return "error";
11378
- // Default fallback
11379
- default:
11380
- if (normalized.includes("signature") || normalized.includes("sig")) {
11381
- return "signature";
11382
- }
11383
- if (normalized.includes("pattern") || normalized.includes("ua")) {
11384
- return "pattern";
11385
- }
11386
- if (normalized.includes("behavior") || normalized.includes("mouse")) {
11387
- return "behavioral";
11388
- }
11389
- if (normalized.includes("network") || normalized.includes("ip")) {
11390
- return "network";
11391
- }
11392
- return "none";
11393
- }
11394
- }
11395
11378
  function getVerificationMethodDescription(method) {
11396
11379
  switch (method) {
11397
11380
  case "signature":
@@ -12569,9 +12552,6 @@ var RuleLoader = class _RuleLoader {
12569
12552
  }
12570
12553
  }
12571
12554
  };
12572
- function loadRulesSync() {
12573
- return RuleLoader.loadSync();
12574
- }
12575
12555
  async function loadRulesAsync(options) {
12576
12556
  const loader = RuleLoader.getInstance();
12577
12557
  return loader.loadRules(options);
@@ -13782,6 +13762,58 @@ function base64UrlDecodeToString(s) {
13782
13762
  return Buffer.from(base64UrlDecodeToBytes(s)).toString("utf-8");
13783
13763
  }
13784
13764
 
13765
+ // src/parsers/jafar.ts
13766
+ var IPV4_CIDR_RE = /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d?\d)\/(?:3[0-2]|[12]?\d)$/;
13767
+ var IPV6_CIDR_RE = /^[0-9a-fA-F:]+\/(?:12[0-8]|1[01]\d|\d{1,2})$/;
13768
+ var HAS_OFFSET_RE = /[zZ]|[+-]\d{2}:?\d{2}$/;
13769
+ var creationTimeSchema = external_exports.string().min(1).transform((raw, ctx) => {
13770
+ const normalized = HAS_OFFSET_RE.test(raw) ? raw : `${raw}Z`;
13771
+ const ms = Date.parse(normalized);
13772
+ if (Number.isNaN(ms)) {
13773
+ ctx.addIssue({
13774
+ code: external_exports.ZodIssueCode.custom,
13775
+ message: `creationTime is not a parseable ISO 8601 timestamp: ${raw}`
13776
+ });
13777
+ return external_exports.NEVER;
13778
+ }
13779
+ return new Date(ms);
13780
+ });
13781
+ var prefixSchema = external_exports.object({
13782
+ ipv4Prefix: external_exports.string().regex(IPV4_CIDR_RE).optional(),
13783
+ ipv6Prefix: external_exports.string().regex(IPV6_CIDR_RE).optional()
13784
+ }).strict().refine((p) => p.ipv4Prefix != null !== (p.ipv6Prefix != null), {
13785
+ message: "prefix entry must have exactly one of ipv4Prefix or ipv6Prefix"
13786
+ });
13787
+ var jafarFeedSchema = external_exports.object({
13788
+ creationTime: creationTimeSchema,
13789
+ prefixes: external_exports.array(prefixSchema),
13790
+ synctoken: external_exports.string().optional(),
13791
+ notes: external_exports.string().optional()
13792
+ }).passthrough();
13793
+ var JafarParseError = class extends Error {
13794
+ constructor(message, cause) {
13795
+ super(message);
13796
+ this.cause = cause;
13797
+ this.name = "JafarParseError";
13798
+ }
13799
+ };
13800
+ function parseJafarFeed(json) {
13801
+ let raw;
13802
+ try {
13803
+ raw = JSON.parse(json);
13804
+ } catch (err) {
13805
+ throw new JafarParseError("JAFAR feed is not valid JSON", err);
13806
+ }
13807
+ const result = jafarFeedSchema.safeParse(raw);
13808
+ if (!result.success) {
13809
+ throw new JafarParseError(
13810
+ `JAFAR feed failed schema validation: ${result.error.message}`,
13811
+ result.error
13812
+ );
13813
+ }
13814
+ return result.data;
13815
+ }
13816
+
13785
13817
  // src/index.ts
13786
13818
  var VERSION = "0.1.0";
13787
13819
  var PACKAGE_NAME = "@kya-os/checkpoint-shared";
@@ -13993,6 +14025,7 @@ exports.DeployStepStateSchema = DeployStepStateSchema;
13993
14025
  exports.DeployStepStatusSchema = DeployStepStatusSchema;
13994
14026
  exports.DeploymentMetadataSchema = DeploymentMetadataSchema;
13995
14027
  exports.DetectionClassSchema = DetectionClassSchema;
14028
+ exports.DetectionDetailSchema = DetectionDetailSchema;
13996
14029
  exports.DetectionErrorDetailsSchema = DetectionErrorDetailsSchema;
13997
14030
  exports.DetectionEventSchema = DetectionEventSchema;
13998
14031
  exports.DetectionInputSchema = DetectionInputSchema;
@@ -14055,6 +14088,7 @@ exports.IntegrationTypeSchema = IntegrationTypeSchema;
14055
14088
  exports.InternalProcessingFlagsSchema = InternalProcessingFlagsSchema;
14056
14089
  exports.IpRangeCollectionSchema = IpRangeCollectionSchema;
14057
14090
  exports.IpRangeRuleSchema = IpRangeRuleSchema;
14091
+ exports.JafarParseError = JafarParseError;
14058
14092
  exports.JwsParseError = JwsParseError;
14059
14093
  exports.KNOWN_AGENT_PATTERNS = KNOWN_AGENT_PATTERNS;
14060
14094
  exports.KeyboardEventSchema = KeyboardEventSchema;
@@ -14308,7 +14342,6 @@ exports.detectionClassToEnum = detectionClassToEnum;
14308
14342
  exports.discoveredToolSchema = discoveredToolSchema;
14309
14343
  exports.encodeVerdictCookie = encodeVerdictCookie;
14310
14344
  exports.enumToDetectionClass = enumToDetectionClass;
14311
- exports.evaluateEnforcement = evaluateEnforcement;
14312
14345
  exports.evaluatePolicy = evaluatePolicy;
14313
14346
  exports.extractMatch = extractMatch;
14314
14347
  exports.fetchPolicy = fetchPolicy;
@@ -14354,10 +14387,8 @@ exports.isValidFingerprintResponse = isValidFingerprintResponse;
14354
14387
  exports.isValidWasmDetectionResult = isValidWasmDetectionResult;
14355
14388
  exports.isValidWasmRequestMetadata = isValidWasmRequestMetadata;
14356
14389
  exports.loadRulesAsync = loadRulesAsync;
14357
- exports.loadRulesSync = loadRulesSync;
14358
14390
  exports.mapLegacyAuthType = mapLegacyAuthType;
14359
14391
  exports.mapToLegacyAuthType = mapToLegacyAuthType;
14360
- exports.mapVerificationMethod = mapVerificationMethod;
14361
14392
  exports.matchPath = matchPath;
14362
14393
  exports.mergeWithDefaults = mergeWithDefaults;
14363
14394
  exports.migrateLegacyDetectionClass = migrateLegacyDetectionClass;
@@ -14369,6 +14400,7 @@ exports.normalizeOrganizationName = normalizeOrganizationName;
14369
14400
  exports.oauthClientSchema = oauthClientSchema;
14370
14401
  exports.parseAgentName = parseAgentName;
14371
14402
  exports.parseEvaluationContext = parseEvaluationContext;
14403
+ exports.parseJafarFeed = parseJafarFeed;
14372
14404
  exports.parseJwsCompact = parseJwsCompact;
14373
14405
  exports.parsePolicyConfig = parsePolicyConfig;
14374
14406
  exports.parseRules = parseRules;
@@ -14380,7 +14412,6 @@ exports.resetPasswordSchema = resetPasswordSchema;
14380
14412
  exports.resetPolicyFetcher = resetPolicyFetcher;
14381
14413
  exports.safeParsePolicyConfig = safeParsePolicyConfig;
14382
14414
  exports.safeUrl = safeUrl;
14383
- exports.shouldEnforce = shouldEnforce;
14384
14415
  exports.signInSchema = signInSchema;
14385
14416
  exports.signMcpiEnvelope = signMcpiEnvelope;
14386
14417
  exports.signUpSchema = signUpSchema;
@@ -14412,5 +14443,3 @@ exports.vaultResolveResponseSchema = vaultResolveResponseSchema;
14412
14443
  exports.vaultResolveSuccessSchema = vaultResolveSuccessSchema;
14413
14444
  exports.verifyEmailSchema = verifyEmailSchema;
14414
14445
  exports.wasmToDetectionResult = wasmToDetectionResult;
14415
- //# sourceMappingURL=index.js.map
14416
- //# sourceMappingURL=index.js.map