@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 +170 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +170 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
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,124 @@ 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 CONNECTION_PROTOCOLS = /* @__PURE__ */ new Set([
|
|
293
|
+
"postgres:",
|
|
294
|
+
"postgresql:",
|
|
295
|
+
"mysql:",
|
|
296
|
+
"mariadb:",
|
|
297
|
+
"mongodb:",
|
|
298
|
+
"mongodb+srv:",
|
|
299
|
+
"redis:",
|
|
300
|
+
"rediss:",
|
|
301
|
+
"amqp:",
|
|
302
|
+
"amqps:"
|
|
303
|
+
]);
|
|
304
|
+
var CONNECTION_URI = /^(?:postgres|postgresql|mysql|mariadb|mongodb(?:\+srv)?|rediss?|amqps?):\/\/[^\s]+$/i;
|
|
305
|
+
var UUID_SEGMENT = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
306
|
+
var HEX_SEGMENT = /^[0-9a-f]{12,}$/i;
|
|
307
|
+
var NUMERIC_SEGMENT = /^\d{5,}$/;
|
|
308
|
+
var OPAQUE_SEGMENT = /^[A-Za-z0-9_-]{20,}$/;
|
|
309
|
+
function looksLikeHttpUrl(value) {
|
|
310
|
+
return HTTP_URL.test(value.trim());
|
|
311
|
+
}
|
|
312
|
+
function looksLikeConnectionUri(value) {
|
|
313
|
+
return CONNECTION_URI.test(value.trim());
|
|
314
|
+
}
|
|
315
|
+
function looksLikeUrlForRedaction(value) {
|
|
316
|
+
return looksLikeHttpUrl(value) || looksLikeConnectionUri(value);
|
|
317
|
+
}
|
|
318
|
+
function parseRedactableUrl(value) {
|
|
319
|
+
try {
|
|
320
|
+
const url = new URL(value.trim());
|
|
321
|
+
if (url.protocol === "http:" || url.protocol === "https:") return url;
|
|
322
|
+
if (CONNECTION_PROTOCOLS.has(url.protocol)) return url;
|
|
323
|
+
return void 0;
|
|
324
|
+
} catch {
|
|
325
|
+
return void 0;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
function isHttpProtocol(protocol) {
|
|
329
|
+
return protocol === "http:" || protocol === "https:";
|
|
330
|
+
}
|
|
331
|
+
function isIdentifierSegment(segment) {
|
|
332
|
+
if (UUID_SEGMENT.test(segment)) return true;
|
|
333
|
+
if (HEX_SEGMENT.test(segment)) return true;
|
|
334
|
+
if (NUMERIC_SEGMENT.test(segment)) return true;
|
|
335
|
+
return OPAQUE_SEGMENT.test(segment) && /\d/.test(segment) && /[A-Za-z]/.test(segment);
|
|
336
|
+
}
|
|
337
|
+
function decodeParam(value) {
|
|
338
|
+
try {
|
|
339
|
+
return decodeURIComponent(value.replace(/\+/g, " "));
|
|
340
|
+
} catch {
|
|
341
|
+
return value;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
function redactParams(raw, options, replacement) {
|
|
345
|
+
let redacted = false;
|
|
346
|
+
const parts = raw.split("&").map((part) => {
|
|
347
|
+
if (part.length === 0) return part;
|
|
348
|
+
const separator = part.indexOf("=");
|
|
349
|
+
if (separator < 0) return part;
|
|
350
|
+
const rawKey = part.slice(0, separator);
|
|
351
|
+
const rawValue = part.slice(separator + 1);
|
|
352
|
+
const key = decodeParam(rawKey);
|
|
353
|
+
const value = decodeParam(rawValue);
|
|
354
|
+
if (isCredentialSensitiveKey(key, options.sensitiveKeys) || options.isSensitiveValue(value)) {
|
|
355
|
+
redacted = true;
|
|
356
|
+
return `${rawKey}=${replacement}`;
|
|
357
|
+
}
|
|
358
|
+
return part;
|
|
359
|
+
});
|
|
360
|
+
return { value: parts.join("&"), redacted };
|
|
361
|
+
}
|
|
362
|
+
function redactUrlString(value, options) {
|
|
363
|
+
const unchanged = {
|
|
364
|
+
value,
|
|
365
|
+
credentialRedacted: false,
|
|
366
|
+
identifiersMasked: false
|
|
367
|
+
};
|
|
368
|
+
if (!looksLikeUrlForRedaction(value)) return unchanged;
|
|
369
|
+
const url = parseRedactableUrl(value);
|
|
370
|
+
if (!url) return unchanged;
|
|
371
|
+
const replacement = options.replacement ?? "[REDACTED]";
|
|
372
|
+
const idPlaceholder = options.idPlaceholder ?? "[id]";
|
|
373
|
+
const http = isHttpProtocol(url.protocol);
|
|
374
|
+
let credentialRedacted = url.username.length > 0 || url.password.length > 0;
|
|
375
|
+
let identifiersMasked = false;
|
|
376
|
+
let pathname = url.pathname;
|
|
377
|
+
if (http && options.maskPathIds === true) {
|
|
378
|
+
pathname = url.pathname.split("/").map((segment) => {
|
|
379
|
+
if (segment.length === 0 || !isIdentifierSegment(decodeParam(segment))) {
|
|
380
|
+
return segment;
|
|
381
|
+
}
|
|
382
|
+
identifiersMasked = true;
|
|
383
|
+
return idPlaceholder;
|
|
384
|
+
}).join("/");
|
|
385
|
+
}
|
|
386
|
+
let search = "";
|
|
387
|
+
if (url.search.length > 1) {
|
|
388
|
+
const params = redactParams(url.search.slice(1), options, replacement);
|
|
389
|
+
if (params.redacted) credentialRedacted = true;
|
|
390
|
+
search = `?${params.value}`;
|
|
391
|
+
} else if (url.search.length === 1) {
|
|
392
|
+
search = "?";
|
|
393
|
+
}
|
|
394
|
+
let hash = url.hash;
|
|
395
|
+
if (url.hash.includes("=")) {
|
|
396
|
+
const params = redactParams(url.hash.slice(1), options, replacement);
|
|
397
|
+
if (params.redacted) credentialRedacted = true;
|
|
398
|
+
hash = `#${params.value}`;
|
|
399
|
+
}
|
|
400
|
+
if (!credentialRedacted && !identifiersMasked) return unchanged;
|
|
401
|
+
return {
|
|
402
|
+
value: `${url.protocol}//${url.host}${pathname}${search}${hash}`,
|
|
403
|
+
credentialRedacted,
|
|
404
|
+
identifiersMasked
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
|
|
290
408
|
// packages/redact/src/index.ts
|
|
291
409
|
var DEFAULT_REDACT_KEYS = [
|
|
292
410
|
"authorization",
|
|
@@ -353,7 +471,9 @@ function findCompiledKeyRule(key, rules) {
|
|
|
353
471
|
const exact = toKey(key);
|
|
354
472
|
const direct = rules.find((candidate) => candidate.key === exact);
|
|
355
473
|
if (direct) return direct;
|
|
356
|
-
return rules.find(
|
|
474
|
+
return rules.find(
|
|
475
|
+
(candidate) => isCredentialSensitiveKey(key, [candidate.raw ?? candidate.key])
|
|
476
|
+
);
|
|
357
477
|
}
|
|
358
478
|
function stableHash(value) {
|
|
359
479
|
const hash = crypto.createHash("sha256").update(value, "utf8").digest("hex");
|
|
@@ -552,7 +672,7 @@ function compileRules(rules, extraKeys) {
|
|
|
552
672
|
const out = /* @__PURE__ */ new Map();
|
|
553
673
|
const set = (rule) => {
|
|
554
674
|
const key = toKey(rule.key);
|
|
555
|
-
out.set(key, { ...rule, key });
|
|
675
|
+
out.set(key, { ...rule, key, raw: rule.raw ?? rule.key });
|
|
556
676
|
};
|
|
557
677
|
for (const key of DEFAULT_REDACT_KEYS) {
|
|
558
678
|
set({ key, strategy: "full" });
|
|
@@ -631,6 +751,7 @@ function createRedactionProfile(profile = "local") {
|
|
|
631
751
|
}
|
|
632
752
|
var Redactor = class {
|
|
633
753
|
#rules;
|
|
754
|
+
#sensitiveKeys;
|
|
634
755
|
#detectors;
|
|
635
756
|
#profile;
|
|
636
757
|
#replacement;
|
|
@@ -643,6 +764,7 @@ var Redactor = class {
|
|
|
643
764
|
...resolved.extraKeys,
|
|
644
765
|
...options?.extraKeys ?? []
|
|
645
766
|
]);
|
|
767
|
+
this.#sensitiveKeys = this.#rules.map((rule) => rule.raw ?? rule.key);
|
|
646
768
|
this.#detectors = [
|
|
647
769
|
...builtInDetectorsForProfile(this.#profile),
|
|
648
770
|
...options?.detectors ?? []
|
|
@@ -676,6 +798,14 @@ var Redactor = class {
|
|
|
676
798
|
#recordFinding(state, finding) {
|
|
677
799
|
if (this.#collectFindings) state.findings.push(finding);
|
|
678
800
|
}
|
|
801
|
+
#detect(value, key, path) {
|
|
802
|
+
for (const detector of this.#detectors) {
|
|
803
|
+
for (const detection of detector.detect({ path, key, value })) {
|
|
804
|
+
if ((detection.action ?? "replace") !== "keep") return { detector, detection };
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
return void 0;
|
|
808
|
+
}
|
|
679
809
|
#redactValue(value, key, path, depth, state) {
|
|
680
810
|
if (depth > this.#maxDepth) {
|
|
681
811
|
this.#recordFinding(
|
|
@@ -694,6 +824,43 @@ var Redactor = class {
|
|
|
694
824
|
return applyRule(rule, value, this.#replacement);
|
|
695
825
|
}
|
|
696
826
|
}
|
|
827
|
+
if (typeof value === "string" && looksLikeUrlForRedaction(value)) {
|
|
828
|
+
const url = redactUrlString(value, {
|
|
829
|
+
sensitiveKeys: this.#sensitiveKeys,
|
|
830
|
+
isSensitiveValue: (candidate) => this.#detect(candidate, key, path) !== void 0,
|
|
831
|
+
replacement: this.#replacement,
|
|
832
|
+
maskPathIds: this.#profile !== "local"
|
|
833
|
+
});
|
|
834
|
+
if (url.value !== value) {
|
|
835
|
+
this.#recordFinding(
|
|
836
|
+
state,
|
|
837
|
+
makeFinding(
|
|
838
|
+
path,
|
|
839
|
+
url.credentialRedacted ? "value.urlCredential" : "value.urlIdentifier",
|
|
840
|
+
"replace",
|
|
841
|
+
"value",
|
|
842
|
+
url.credentialRedacted ? "error" : "warning"
|
|
843
|
+
)
|
|
844
|
+
);
|
|
845
|
+
const residual = this.#detect(
|
|
846
|
+
url.value.split(this.#replacement).join(""),
|
|
847
|
+
key,
|
|
848
|
+
path
|
|
849
|
+
);
|
|
850
|
+
if (residual === void 0) return url.value;
|
|
851
|
+
this.#recordFinding(
|
|
852
|
+
state,
|
|
853
|
+
makeFinding(
|
|
854
|
+
path,
|
|
855
|
+
residual.detector.id,
|
|
856
|
+
"replace",
|
|
857
|
+
residual.detection.matchKind ?? residual.detector.matchKind ?? "custom",
|
|
858
|
+
residual.detection.severity ?? residual.detector.severity ?? "warning"
|
|
859
|
+
)
|
|
860
|
+
);
|
|
861
|
+
return this.#replacement;
|
|
862
|
+
}
|
|
863
|
+
}
|
|
697
864
|
for (const detector of this.#detectors) {
|
|
698
865
|
const detections = detector.detect({ path, key, value });
|
|
699
866
|
for (const detection of detections) {
|