MCPcopy
hub / github.com/Doorman11991/smallcode / redactString

Function redactString

src/security/sanitize.js:64–76  ·  view source on GitHub ↗

* Redact secrets from a string. Returns the string with sensitive * substrings replaced by [REDACTED: ]. Original input is never mutated. * Empty/non-string inputs pass through unchanged.

(input)

Source from the content-addressed store, hash-verified

62 * Empty/non-string inputs pass through unchanged.
63 */
64function redactString(input) {
65 if (typeof input !== 'string' || input.length === 0) return input;
66 let out = input;
67 for (const { name, re } of SECRET_PATTERNS) {
68 if (name === 'env_api_key') {
69 // Preserve the variable name, redact the value.
70 out = out.replace(re, (_, k) => `${k}=[REDACTED:env_value]`);
71 } else {
72 out = out.replace(re, `[REDACTED:${name}]`);
73 }
74 }
75 return out;
76}
77
78/**
79 * Recursively redact a value (object, array, or primitive).

Callers 7

redactValueFunction · 0.85
sanitizeToolOutputFunction · 0.85
exportToGistFunction · 0.85
chatCompletionFunction · 0.85
recordToolCallMethod · 0.85
recordModelResponseMethod · 0.85
stopMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected