Skip to content

Commit cb536ce

Browse files
committed
enh: improve sensitive data masking in maskTmqConfigForLog function
1 parent 2df2236 commit cb536ce

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

nodejs/src/common/utils.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,17 @@ export function maskTmqConfigForLog(config: TmqConfig): string {
225225
...config,
226226
otherConfigs: Object.fromEntries(config.otherConfigs)
227227
};
228-
if (masked.token) {
229-
masked.token = "[REDACTED]";
230-
}
231-
if (masked.password) {
232-
masked.password = "[REDACTED]";
233-
}
234-
return JSON.stringify(masked, (key, value) =>
235-
(key === "url" || key === "sql_url")
236-
? maskUrlForLog(value) : (key === "td.connect.token" ? "[REDACTED]" : value)
237-
);
228+
return JSON.stringify(masked, (key, value) => {
229+
switch (key) {
230+
case 'url':
231+
case 'sql_url':
232+
return maskUrlForLog(value);
233+
case 'token':
234+
case 'password':
235+
case 'td.connect.token':
236+
return value ? '[REDACTED]' : value;
237+
default:
238+
return value;
239+
}
240+
});
238241
}

0 commit comments

Comments
 (0)