MCPcopy Create free account
hub / github.com/cortexkit/magic-context / sanitizeString

Function sanitizeString

packages/cli/src/lib/diagnostics-pi.ts:186–201  ·  view source on GitHub ↗
(value: string)

Source from the content-addressed store, hash-verified

184 * without leaking the account name.
185 */
186export function sanitizeString(value: string): string {
187 const home = process.env.HOME || homedir();
188 const username = userInfo().username;
189 const userHash = `<USER:${currentUserHash()}>`;
190 let sanitized = redactSecretString(value);
191 if (home) {
192 sanitized = sanitized.replace(new RegExp(escapeRegex(home), "g"), "<HOME>");
193 }
194 sanitized = sanitized.replace(/\/Users\/[^/]+\//g, `/Users/${userHash}/`);
195 sanitized = sanitized.replace(/\/home\/[^/]+\//g, `/home/${userHash}/`);
196 sanitized = sanitized.replace(/C:\\Users\\[^\\]+\\/g, `C:\\Users\\${userHash}\\`);
197 if (username) {
198 sanitized = sanitized.replace(new RegExp(escapeRegex(username), "g"), userHash);
199 }
200 return sanitized;
201}
202
203function shouldRedactKey(key: string): boolean {
204 return /api[_-]?key|token|secret|password|authorization|cookie/i.test(key);

Callers 4

sanitizeLogContentFunction · 0.90
bundleIssueReportFunction · 0.90
sanitizeValueFunction · 0.70

Calls 3

currentUserHashFunction · 0.85
redactSecretStringFunction · 0.85
escapeRegexFunction · 0.70

Tested by

no test coverage detected