@agent-inspect/eval 6.31.3 → 6.31.4

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.mjs CHANGED
@@ -277,7 +277,7 @@ function isCredentialSensitiveKey(key, sensitiveKeys) {
277
277
  }
278
278
 
279
279
  // packages/redact/src/key-value-secret.ts
280
- var KEY_VALUE_SECRET_PATTERN_SOURCE = String.raw`\b(?:api[_-]?key|internal[_-]?token|access[_-]?token|auth[_-]?token|password|secret|token)=([^\s"'\\]{8,})`;
280
+ 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,})`;
281
281
  var KEY_VALUE_SECRET_PATTERN = new RegExp(
282
282
  KEY_VALUE_SECRET_PATTERN_SOURCE,
283
283
  "i"
@@ -287,6 +287,99 @@ function valueContainsKeyValueSecret(value) {
287
287
  return KEY_VALUE_SECRET_PATTERN.test(value);
288
288
  }
289
289
 
290
+ // packages/redact/src/url-redaction.ts
291
+ var HTTP_URL = /^https?:\/\/[^\s]+$/i;
292
+ var UUID_SEGMENT = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
293
+ var HEX_SEGMENT = /^[0-9a-f]{12,}$/i;
294
+ var NUMERIC_SEGMENT = /^\d{5,}$/;
295
+ var OPAQUE_SEGMENT = /^[A-Za-z0-9_-]{20,}$/;
296
+ function looksLikeHttpUrl(value) {
297
+ return HTTP_URL.test(value.trim());
298
+ }
299
+ function parseHttpUrl(value) {
300
+ try {
301
+ const url = new URL(value.trim());
302
+ return url.protocol === "http:" || url.protocol === "https:" ? url : void 0;
303
+ } catch {
304
+ return void 0;
305
+ }
306
+ }
307
+ function isIdentifierSegment(segment) {
308
+ if (UUID_SEGMENT.test(segment)) return true;
309
+ if (HEX_SEGMENT.test(segment)) return true;
310
+ if (NUMERIC_SEGMENT.test(segment)) return true;
311
+ return OPAQUE_SEGMENT.test(segment) && /\d/.test(segment) && /[A-Za-z]/.test(segment);
312
+ }
313
+ function decodeParam(value) {
314
+ try {
315
+ return decodeURIComponent(value.replace(/\+/g, " "));
316
+ } catch {
317
+ return value;
318
+ }
319
+ }
320
+ function redactParams(raw, options, replacement) {
321
+ let redacted = false;
322
+ const parts = raw.split("&").map((part) => {
323
+ if (part.length === 0) return part;
324
+ const separator = part.indexOf("=");
325
+ if (separator < 0) return part;
326
+ const rawKey = part.slice(0, separator);
327
+ const rawValue = part.slice(separator + 1);
328
+ const key = decodeParam(rawKey);
329
+ const value = decodeParam(rawValue);
330
+ if (isCredentialSensitiveKey(key, options.sensitiveKeys) || options.isSensitiveValue(value)) {
331
+ redacted = true;
332
+ return `${rawKey}=${replacement}`;
333
+ }
334
+ return part;
335
+ });
336
+ return { value: parts.join("&"), redacted };
337
+ }
338
+ function redactUrlString(value, options) {
339
+ const unchanged = {
340
+ value,
341
+ credentialRedacted: false,
342
+ identifiersMasked: false
343
+ };
344
+ if (!looksLikeHttpUrl(value)) return unchanged;
345
+ const url = parseHttpUrl(value);
346
+ if (!url) return unchanged;
347
+ const replacement = options.replacement ?? "[REDACTED]";
348
+ const idPlaceholder = options.idPlaceholder ?? "[id]";
349
+ let credentialRedacted = url.username.length > 0 || url.password.length > 0;
350
+ let identifiersMasked = false;
351
+ let pathname = url.pathname;
352
+ if (options.maskPathIds === true) {
353
+ pathname = url.pathname.split("/").map((segment) => {
354
+ if (segment.length === 0 || !isIdentifierSegment(decodeParam(segment))) {
355
+ return segment;
356
+ }
357
+ identifiersMasked = true;
358
+ return idPlaceholder;
359
+ }).join("/");
360
+ }
361
+ let search = "";
362
+ if (url.search.length > 1) {
363
+ const params = redactParams(url.search.slice(1), options, replacement);
364
+ if (params.redacted) credentialRedacted = true;
365
+ search = `?${params.value}`;
366
+ } else if (url.search.length === 1) {
367
+ search = "?";
368
+ }
369
+ let hash = url.hash;
370
+ if (url.hash.includes("=")) {
371
+ const params = redactParams(url.hash.slice(1), options, replacement);
372
+ if (params.redacted) credentialRedacted = true;
373
+ hash = `#${params.value}`;
374
+ }
375
+ if (!credentialRedacted && !identifiersMasked) return unchanged;
376
+ return {
377
+ value: `${url.protocol}//${url.host}${pathname}${search}${hash}`,
378
+ credentialRedacted,
379
+ identifiersMasked
380
+ };
381
+ }
382
+
290
383
  // packages/redact/src/index.ts
291
384
  var DEFAULT_REDACT_KEYS = [
292
385
  "authorization",
@@ -353,7 +446,9 @@ function findCompiledKeyRule(key, rules) {
353
446
  const exact = toKey(key);
354
447
  const direct = rules.find((candidate) => candidate.key === exact);
355
448
  if (direct) return direct;
356
- return rules.find((candidate) => isCredentialSensitiveKey(key, [candidate.key]));
449
+ return rules.find(
450
+ (candidate) => isCredentialSensitiveKey(key, [candidate.raw ?? candidate.key])
451
+ );
357
452
  }
358
453
  function stableHash(value) {
359
454
  const hash = crypto.createHash("sha256").update(value, "utf8").digest("hex");
@@ -552,7 +647,7 @@ function compileRules(rules, extraKeys) {
552
647
  const out = /* @__PURE__ */ new Map();
553
648
  const set = (rule) => {
554
649
  const key = toKey(rule.key);
555
- out.set(key, { ...rule, key });
650
+ out.set(key, { ...rule, key, raw: rule.raw ?? rule.key });
556
651
  };
557
652
  for (const key of DEFAULT_REDACT_KEYS) {
558
653
  set({ key, strategy: "full" });
@@ -631,6 +726,7 @@ function createRedactionProfile(profile = "local") {
631
726
  }
632
727
  var Redactor = class {
633
728
  #rules;
729
+ #sensitiveKeys;
634
730
  #detectors;
635
731
  #profile;
636
732
  #replacement;
@@ -643,6 +739,7 @@ var Redactor = class {
643
739
  ...resolved.extraKeys,
644
740
  ...options?.extraKeys ?? []
645
741
  ]);
742
+ this.#sensitiveKeys = this.#rules.map((rule) => rule.raw ?? rule.key);
646
743
  this.#detectors = [
647
744
  ...builtInDetectorsForProfile(this.#profile),
648
745
  ...options?.detectors ?? []
@@ -676,6 +773,14 @@ var Redactor = class {
676
773
  #recordFinding(state, finding) {
677
774
  if (this.#collectFindings) state.findings.push(finding);
678
775
  }
776
+ #detect(value, key, path) {
777
+ for (const detector of this.#detectors) {
778
+ for (const detection of detector.detect({ path, key, value })) {
779
+ if ((detection.action ?? "replace") !== "keep") return { detector, detection };
780
+ }
781
+ }
782
+ return void 0;
783
+ }
679
784
  #redactValue(value, key, path, depth, state) {
680
785
  if (depth > this.#maxDepth) {
681
786
  this.#recordFinding(
@@ -694,6 +799,43 @@ var Redactor = class {
694
799
  return applyRule(rule, value, this.#replacement);
695
800
  }
696
801
  }
802
+ if (typeof value === "string" && looksLikeHttpUrl(value)) {
803
+ const url = redactUrlString(value, {
804
+ sensitiveKeys: this.#sensitiveKeys,
805
+ isSensitiveValue: (candidate) => this.#detect(candidate, key, path) !== void 0,
806
+ replacement: this.#replacement,
807
+ maskPathIds: this.#profile !== "local"
808
+ });
809
+ if (url.value !== value) {
810
+ this.#recordFinding(
811
+ state,
812
+ makeFinding(
813
+ path,
814
+ url.credentialRedacted ? "value.urlCredential" : "value.urlIdentifier",
815
+ "replace",
816
+ "value",
817
+ url.credentialRedacted ? "error" : "warning"
818
+ )
819
+ );
820
+ const residual = this.#detect(
821
+ url.value.split(this.#replacement).join(""),
822
+ key,
823
+ path
824
+ );
825
+ if (residual === void 0) return url.value;
826
+ this.#recordFinding(
827
+ state,
828
+ makeFinding(
829
+ path,
830
+ residual.detector.id,
831
+ "replace",
832
+ residual.detection.matchKind ?? residual.detector.matchKind ?? "custom",
833
+ residual.detection.severity ?? residual.detector.severity ?? "warning"
834
+ )
835
+ );
836
+ return this.#replacement;
837
+ }
838
+ }
697
839
  for (const detector of this.#detectors) {
698
840
  const detections = detector.detect({ path, key, value });
699
841
  for (const detection of detections) {