@agent-inspect/eval 6.31.3 → 6.31.5

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.cjs CHANGED
@@ -283,7 +283,7 @@ function isCredentialSensitiveKey(key, sensitiveKeys) {
283
283
  }
284
284
 
285
285
  // packages/redact/src/key-value-secret.ts
286
- var KEY_VALUE_SECRET_PATTERN_SOURCE = String.raw`\b(?:api[_-]?key|internal[_-]?token|access[_-]?token|auth[_-]?token|password|secret|token)=([^\s"'\\]{8,})`;
286
+ var KEY_VALUE_SECRET_PATTERN_SOURCE = String.raw`\b(?:api[_-]?key|internal[_-]?token|access[_-]?token|auth[_-]?token|password|secret|token)=(?!\[(?:REDACTED(?::[^\]]*)?|HASH:[0-9a-f]{8})\](?![^\s"'\\&#?;/]))([^\s"'\\]{8,})`;
287
287
  var KEY_VALUE_SECRET_PATTERN = new RegExp(
288
288
  KEY_VALUE_SECRET_PATTERN_SOURCE,
289
289
  "i"
@@ -293,6 +293,124 @@ function valueContainsKeyValueSecret(value) {
293
293
  return KEY_VALUE_SECRET_PATTERN.test(value);
294
294
  }
295
295
 
296
+ // packages/redact/src/url-redaction.ts
297
+ var HTTP_URL = /^https?:\/\/[^\s]+$/i;
298
+ var CONNECTION_PROTOCOLS = /* @__PURE__ */ new Set([
299
+ "postgres:",
300
+ "postgresql:",
301
+ "mysql:",
302
+ "mariadb:",
303
+ "mongodb:",
304
+ "mongodb+srv:",
305
+ "redis:",
306
+ "rediss:",
307
+ "amqp:",
308
+ "amqps:"
309
+ ]);
310
+ var CONNECTION_URI = /^(?:postgres|postgresql|mysql|mariadb|mongodb(?:\+srv)?|rediss?|amqps?):\/\/[^\s]+$/i;
311
+ var UUID_SEGMENT = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
312
+ var HEX_SEGMENT = /^[0-9a-f]{12,}$/i;
313
+ var NUMERIC_SEGMENT = /^\d{5,}$/;
314
+ var OPAQUE_SEGMENT = /^[A-Za-z0-9_-]{20,}$/;
315
+ function looksLikeHttpUrl(value) {
316
+ return HTTP_URL.test(value.trim());
317
+ }
318
+ function looksLikeConnectionUri(value) {
319
+ return CONNECTION_URI.test(value.trim());
320
+ }
321
+ function looksLikeUrlForRedaction(value) {
322
+ return looksLikeHttpUrl(value) || looksLikeConnectionUri(value);
323
+ }
324
+ function parseRedactableUrl(value) {
325
+ try {
326
+ const url = new URL(value.trim());
327
+ if (url.protocol === "http:" || url.protocol === "https:") return url;
328
+ if (CONNECTION_PROTOCOLS.has(url.protocol)) return url;
329
+ return void 0;
330
+ } catch {
331
+ return void 0;
332
+ }
333
+ }
334
+ function isHttpProtocol(protocol) {
335
+ return protocol === "http:" || protocol === "https:";
336
+ }
337
+ function isIdentifierSegment(segment) {
338
+ if (UUID_SEGMENT.test(segment)) return true;
339
+ if (HEX_SEGMENT.test(segment)) return true;
340
+ if (NUMERIC_SEGMENT.test(segment)) return true;
341
+ return OPAQUE_SEGMENT.test(segment) && /\d/.test(segment) && /[A-Za-z]/.test(segment);
342
+ }
343
+ function decodeParam(value) {
344
+ try {
345
+ return decodeURIComponent(value.replace(/\+/g, " "));
346
+ } catch {
347
+ return value;
348
+ }
349
+ }
350
+ function redactParams(raw, options, replacement) {
351
+ let redacted = false;
352
+ const parts = raw.split("&").map((part) => {
353
+ if (part.length === 0) return part;
354
+ const separator = part.indexOf("=");
355
+ if (separator < 0) return part;
356
+ const rawKey = part.slice(0, separator);
357
+ const rawValue = part.slice(separator + 1);
358
+ const key = decodeParam(rawKey);
359
+ const value = decodeParam(rawValue);
360
+ if (isCredentialSensitiveKey(key, options.sensitiveKeys) || options.isSensitiveValue(value)) {
361
+ redacted = true;
362
+ return `${rawKey}=${replacement}`;
363
+ }
364
+ return part;
365
+ });
366
+ return { value: parts.join("&"), redacted };
367
+ }
368
+ function redactUrlString(value, options) {
369
+ const unchanged = {
370
+ value,
371
+ credentialRedacted: false,
372
+ identifiersMasked: false
373
+ };
374
+ if (!looksLikeUrlForRedaction(value)) return unchanged;
375
+ const url = parseRedactableUrl(value);
376
+ if (!url) return unchanged;
377
+ const replacement = options.replacement ?? "[REDACTED]";
378
+ const idPlaceholder = options.idPlaceholder ?? "[id]";
379
+ const http = isHttpProtocol(url.protocol);
380
+ let credentialRedacted = url.username.length > 0 || url.password.length > 0;
381
+ let identifiersMasked = false;
382
+ let pathname = url.pathname;
383
+ if (http && options.maskPathIds === true) {
384
+ pathname = url.pathname.split("/").map((segment) => {
385
+ if (segment.length === 0 || !isIdentifierSegment(decodeParam(segment))) {
386
+ return segment;
387
+ }
388
+ identifiersMasked = true;
389
+ return idPlaceholder;
390
+ }).join("/");
391
+ }
392
+ let search = "";
393
+ if (url.search.length > 1) {
394
+ const params = redactParams(url.search.slice(1), options, replacement);
395
+ if (params.redacted) credentialRedacted = true;
396
+ search = `?${params.value}`;
397
+ } else if (url.search.length === 1) {
398
+ search = "?";
399
+ }
400
+ let hash = url.hash;
401
+ if (url.hash.includes("=")) {
402
+ const params = redactParams(url.hash.slice(1), options, replacement);
403
+ if (params.redacted) credentialRedacted = true;
404
+ hash = `#${params.value}`;
405
+ }
406
+ if (!credentialRedacted && !identifiersMasked) return unchanged;
407
+ return {
408
+ value: `${url.protocol}//${url.host}${pathname}${search}${hash}`,
409
+ credentialRedacted,
410
+ identifiersMasked
411
+ };
412
+ }
413
+
296
414
  // packages/redact/src/index.ts
297
415
  var DEFAULT_REDACT_KEYS = [
298
416
  "authorization",
@@ -359,7 +477,9 @@ function findCompiledKeyRule(key, rules) {
359
477
  const exact = toKey(key);
360
478
  const direct = rules.find((candidate) => candidate.key === exact);
361
479
  if (direct) return direct;
362
- return rules.find((candidate) => isCredentialSensitiveKey(key, [candidate.key]));
480
+ return rules.find(
481
+ (candidate) => isCredentialSensitiveKey(key, [candidate.raw ?? candidate.key])
482
+ );
363
483
  }
364
484
  function stableHash(value) {
365
485
  const hash = crypto__default.default.createHash("sha256").update(value, "utf8").digest("hex");
@@ -558,7 +678,7 @@ function compileRules(rules, extraKeys) {
558
678
  const out = /* @__PURE__ */ new Map();
559
679
  const set = (rule) => {
560
680
  const key = toKey(rule.key);
561
- out.set(key, { ...rule, key });
681
+ out.set(key, { ...rule, key, raw: rule.raw ?? rule.key });
562
682
  };
563
683
  for (const key of DEFAULT_REDACT_KEYS) {
564
684
  set({ key, strategy: "full" });
@@ -637,6 +757,7 @@ function createRedactionProfile(profile = "local") {
637
757
  }
638
758
  var Redactor = class {
639
759
  #rules;
760
+ #sensitiveKeys;
640
761
  #detectors;
641
762
  #profile;
642
763
  #replacement;
@@ -649,6 +770,7 @@ var Redactor = class {
649
770
  ...resolved.extraKeys,
650
771
  ...options?.extraKeys ?? []
651
772
  ]);
773
+ this.#sensitiveKeys = this.#rules.map((rule) => rule.raw ?? rule.key);
652
774
  this.#detectors = [
653
775
  ...builtInDetectorsForProfile(this.#profile),
654
776
  ...options?.detectors ?? []
@@ -682,6 +804,14 @@ var Redactor = class {
682
804
  #recordFinding(state, finding) {
683
805
  if (this.#collectFindings) state.findings.push(finding);
684
806
  }
807
+ #detect(value, key, path) {
808
+ for (const detector of this.#detectors) {
809
+ for (const detection of detector.detect({ path, key, value })) {
810
+ if ((detection.action ?? "replace") !== "keep") return { detector, detection };
811
+ }
812
+ }
813
+ return void 0;
814
+ }
685
815
  #redactValue(value, key, path, depth, state) {
686
816
  if (depth > this.#maxDepth) {
687
817
  this.#recordFinding(
@@ -700,6 +830,43 @@ var Redactor = class {
700
830
  return applyRule(rule, value, this.#replacement);
701
831
  }
702
832
  }
833
+ if (typeof value === "string" && looksLikeUrlForRedaction(value)) {
834
+ const url = redactUrlString(value, {
835
+ sensitiveKeys: this.#sensitiveKeys,
836
+ isSensitiveValue: (candidate) => this.#detect(candidate, key, path) !== void 0,
837
+ replacement: this.#replacement,
838
+ maskPathIds: this.#profile !== "local"
839
+ });
840
+ if (url.value !== value) {
841
+ this.#recordFinding(
842
+ state,
843
+ makeFinding(
844
+ path,
845
+ url.credentialRedacted ? "value.urlCredential" : "value.urlIdentifier",
846
+ "replace",
847
+ "value",
848
+ url.credentialRedacted ? "error" : "warning"
849
+ )
850
+ );
851
+ const residual = this.#detect(
852
+ url.value.split(this.#replacement).join(""),
853
+ key,
854
+ path
855
+ );
856
+ if (residual === void 0) return url.value;
857
+ this.#recordFinding(
858
+ state,
859
+ makeFinding(
860
+ path,
861
+ residual.detector.id,
862
+ "replace",
863
+ residual.detection.matchKind ?? residual.detector.matchKind ?? "custom",
864
+ residual.detection.severity ?? residual.detector.severity ?? "warning"
865
+ )
866
+ );
867
+ return this.#replacement;
868
+ }
869
+ }
703
870
  for (const detector of this.#detectors) {
704
871
  const detections = detector.detect({ path, key, value });
705
872
  for (const detection of detections) {