MCPcopy Index your code
hub / github.com/callstack/agent-device / redactString

Function redactString

src/kernel/redaction.ts:36–53  ·  view source on GitHub ↗
(value: string, keyHint?: string)

Source from the content-addressed store, hash-verified

34}
35
36function redactString(value: string, keyHint?: string): string {
37 const trimmed = value.trim();
38 if (!trimmed) return value;
39 if (keyHint && SENSITIVE_KEY_RE.test(keyHint)) return '[REDACTED]';
40 let output = redactUrls(trimmed);
41 output = output.replace(SECRET_TOKEN_RE, '[REDACTED]');
42 output = output.replace(
43 SENSITIVE_ASSIGNMENT_RE,
44 (match, key: string, separator: string, rawValue: string, offset: number, input: string) => {
45 if (isSafeSetupUrlAssignment({ key, separator, rawValue, offset, input })) return match;
46 if (isDocumentedTokenPlaceholder(rawValue)) return match;
47 return `${key}${separator}[REDACTED]`;
48 },
49 );
50 if (output !== trimmed) return output;
51 if (trimmed.length > 400) return `${trimmed.slice(0, 200)}...<truncated>`;
52 return trimmed;
53}
54
55function redactUrls(value: string): string {
56 return value.replace(URL_RE, (url) => redactUrl(url) ?? url);

Callers 2

redactValueFunction · 0.85
redactValueFunction · 0.85

Calls 3

redactUrlsFunction · 0.85
isSafeSetupUrlAssignmentFunction · 0.85

Tested by

no test coverage detected