MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / sanitizeErrorMessage

Function sanitizeErrorMessage

speedlink/speedlink.ts:119–153  ·  view source on GitHub ↗
(error: string, server?: ServerConfig)

Source from the content-addressed store, hash-verified

117 child.on("close", () => { clearTimeout(timer); });
118 });
119}
120
121// --- Sanitize sensitive information from error messages ---
122function sanitizeErrorMessage(error: string, server?: ServerConfig): string {
123 let sanitized = error;
124
125 // Remove passwords
126 sanitized = sanitized.replace(/sshpass -p '[^']*'/gi, "sshpass -p '***'");
127 sanitized = sanitized.replace(/password[:\s]+\S+/gi, "password: ***");
128
129 // Mask IP addresses (full mask)
130 sanitized = sanitized.replace(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/g, '***.***.***.***');
131
132 // Mask IPv6 addresses (more aggressive)
133 sanitized = sanitized.replace(/([0-9a-fA-F]{1,4}:){2,}[0-9a-fA-F:.]+/g, '***:***:***:***');
134
135 // Remove SSH key paths
136 sanitized = sanitized.replace(/ssh -i [^\s]+/gi, "ssh -i ***");
137
138 // Remove usernames in connection strings
139 sanitized = sanitized.replace(/\b[a-zA-Z0-9_-]+@/g, "***@");
140
141 // If server config is provided, also remove specific server details
142 if (server) {
143 sanitized = sanitized.replace(new RegExp(server.host, 'g'), '***');
144 sanitized = sanitized.replace(new RegExp(server.username, 'g'), '***');
145 if (server.auth_method === 'password') {
146 try {
147 const password = decrypt(server.credentials);
148 sanitized = sanitized.replace(new RegExp(password, 'g'), '***');
149 } catch (e) {
150 // Ignore decryption errors
151 }
152 }
153 }
154
155 return sanitized;
156}

Callers 1

speedtestFunction · 0.85

Calls 1

decryptFunction · 0.85

Tested by

no test coverage detected