@agent-inspect/eval 6.31.2 → 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.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,99 @@ 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 UUID_SEGMENT = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
299
+ var HEX_SEGMENT = /^[0-9a-f]{12,}$/i;
300
+ var NUMERIC_SEGMENT = /^\d{5,}$/;
301
+ var OPAQUE_SEGMENT = /^[A-Za-z0-9_-]{20,}$/;
302
+ function looksLikeHttpUrl(value) {
303
+ return HTTP_URL.test(value.trim());
304
+ }
305
+ function parseHttpUrl(value) {
306
+ try {
307
+ const url = new URL(value.trim());
308
+ return url.protocol === "http:" || url.protocol === "https:" ? url : void 0;
309
+ } catch {
310
+ return void 0;
311
+ }
312
+ }
313
+ function isIdentifierSegment(segment) {
314
+ if (UUID_SEGMENT.test(segment)) return true;
315
+ if (HEX_SEGMENT.test(segment)) return true;
316
+ if (NUMERIC_SEGMENT.test(segment)) return true;
317
+ return OPAQUE_SEGMENT.test(segment) && /\d/.test(segment) && /[A-Za-z]/.test(segment);
318
+ }
319
+ function decodeParam(value) {
320
+ try {
321
+ return decodeURIComponent(value.replace(/\+/g, " "));
322
+ } catch {
323
+ return value;
324
+ }
325
+ }
326
+ function redactParams(raw, options, replacement) {
327
+ let redacted = false;
328
+ const parts = raw.split("&").map((part) => {
329
+ if (part.length === 0) return part;
330
+ const separator = part.indexOf("=");
331
+ if (separator < 0) return part;
332
+ const rawKey = part.slice(0, separator);
333
+ const rawValue = part.slice(separator + 1);
334
+ const key = decodeParam(rawKey);
335
+ const value = decodeParam(rawValue);
336
+ if (isCredentialSensitiveKey(key, options.sensitiveKeys) || options.isSensitiveValue(value)) {
337
+ redacted = true;
338
+ return `${rawKey}=${replacement}`;
339
+ }
340
+ return part;
341
+ });
342
+ return { value: parts.join("&"), redacted };
343
+ }
344
+ function redactUrlString(value, options) {
345
+ const unchanged = {
346
+ value,
347
+ credentialRedacted: false,
348
+ identifiersMasked: false
349
+ };
350
+ if (!looksLikeHttpUrl(value)) return unchanged;
351
+ const url = parseHttpUrl(value);
352
+ if (!url) return unchanged;
353
+ const replacement = options.replacement ?? "[REDACTED]";
354
+ const idPlaceholder = options.idPlaceholder ?? "[id]";
355
+ let credentialRedacted = url.username.length > 0 || url.password.length > 0;
356
+ let identifiersMasked = false;
357
+ let pathname = url.pathname;
358
+ if (options.maskPathIds === true) {
359
+ pathname = url.pathname.split("/").map((segment) => {
360
+ if (segment.length === 0 || !isIdentifierSegment(decodeParam(segment))) {
361
+ return segment;
362
+ }
363
+ identifiersMasked = true;
364
+ return idPlaceholder;
365
+ }).join("/");
366
+ }
367
+ let search = "";
368
+ if (url.search.length > 1) {
369
+ const params = redactParams(url.search.slice(1), options, replacement);
370
+ if (params.redacted) credentialRedacted = true;
371
+ search = `?${params.value}`;
372
+ } else if (url.search.length === 1) {
373
+ search = "?";
374
+ }
375
+ let hash = url.hash;
376
+ if (url.hash.includes("=")) {
377
+ const params = redactParams(url.hash.slice(1), options, replacement);
378
+ if (params.redacted) credentialRedacted = true;
379
+ hash = `#${params.value}`;
380
+ }
381
+ if (!credentialRedacted && !identifiersMasked) return unchanged;
382
+ return {
383
+ value: `${url.protocol}//${url.host}${pathname}${search}${hash}`,
384
+ credentialRedacted,
385
+ identifiersMasked
386
+ };
387
+ }
388
+
296
389
  // packages/redact/src/index.ts
297
390
  var DEFAULT_REDACT_KEYS = [
298
391
  "authorization",
@@ -359,7 +452,9 @@ function findCompiledKeyRule(key, rules) {
359
452
  const exact = toKey(key);
360
453
  const direct = rules.find((candidate) => candidate.key === exact);
361
454
  if (direct) return direct;
362
- return rules.find((candidate) => isCredentialSensitiveKey(key, [candidate.key]));
455
+ return rules.find(
456
+ (candidate) => isCredentialSensitiveKey(key, [candidate.raw ?? candidate.key])
457
+ );
363
458
  }
364
459
  function stableHash(value) {
365
460
  const hash = crypto__default.default.createHash("sha256").update(value, "utf8").digest("hex");
@@ -558,7 +653,7 @@ function compileRules(rules, extraKeys) {
558
653
  const out = /* @__PURE__ */ new Map();
559
654
  const set = (rule) => {
560
655
  const key = toKey(rule.key);
561
- out.set(key, { ...rule, key });
656
+ out.set(key, { ...rule, key, raw: rule.raw ?? rule.key });
562
657
  };
563
658
  for (const key of DEFAULT_REDACT_KEYS) {
564
659
  set({ key, strategy: "full" });
@@ -637,6 +732,7 @@ function createRedactionProfile(profile = "local") {
637
732
  }
638
733
  var Redactor = class {
639
734
  #rules;
735
+ #sensitiveKeys;
640
736
  #detectors;
641
737
  #profile;
642
738
  #replacement;
@@ -649,6 +745,7 @@ var Redactor = class {
649
745
  ...resolved.extraKeys,
650
746
  ...options?.extraKeys ?? []
651
747
  ]);
748
+ this.#sensitiveKeys = this.#rules.map((rule) => rule.raw ?? rule.key);
652
749
  this.#detectors = [
653
750
  ...builtInDetectorsForProfile(this.#profile),
654
751
  ...options?.detectors ?? []
@@ -682,6 +779,14 @@ var Redactor = class {
682
779
  #recordFinding(state, finding) {
683
780
  if (this.#collectFindings) state.findings.push(finding);
684
781
  }
782
+ #detect(value, key, path) {
783
+ for (const detector of this.#detectors) {
784
+ for (const detection of detector.detect({ path, key, value })) {
785
+ if ((detection.action ?? "replace") !== "keep") return { detector, detection };
786
+ }
787
+ }
788
+ return void 0;
789
+ }
685
790
  #redactValue(value, key, path, depth, state) {
686
791
  if (depth > this.#maxDepth) {
687
792
  this.#recordFinding(
@@ -700,6 +805,43 @@ var Redactor = class {
700
805
  return applyRule(rule, value, this.#replacement);
701
806
  }
702
807
  }
808
+ if (typeof value === "string" && looksLikeHttpUrl(value)) {
809
+ const url = redactUrlString(value, {
810
+ sensitiveKeys: this.#sensitiveKeys,
811
+ isSensitiveValue: (candidate) => this.#detect(candidate, key, path) !== void 0,
812
+ replacement: this.#replacement,
813
+ maskPathIds: this.#profile !== "local"
814
+ });
815
+ if (url.value !== value) {
816
+ this.#recordFinding(
817
+ state,
818
+ makeFinding(
819
+ path,
820
+ url.credentialRedacted ? "value.urlCredential" : "value.urlIdentifier",
821
+ "replace",
822
+ "value",
823
+ url.credentialRedacted ? "error" : "warning"
824
+ )
825
+ );
826
+ const residual = this.#detect(
827
+ url.value.split(this.#replacement).join(""),
828
+ key,
829
+ path
830
+ );
831
+ if (residual === void 0) return url.value;
832
+ this.#recordFinding(
833
+ state,
834
+ makeFinding(
835
+ path,
836
+ residual.detector.id,
837
+ "replace",
838
+ residual.detection.matchKind ?? residual.detector.matchKind ?? "custom",
839
+ residual.detection.severity ?? residual.detector.severity ?? "warning"
840
+ )
841
+ );
842
+ return this.#replacement;
843
+ }
844
+ }
703
845
  for (const detector of this.#detectors) {
704
846
  const detections = detector.detect({ path, key, value });
705
847
  for (const detection of detections) {