Skip to content

Commit 504d4b6

Browse files
committed
fix(Editor): fix logging sensitive information
1 parent 54cb195 commit 504d4b6

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

src/unityEditor.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@ class UnityEditor {
126126
}
127127

128128
const editorArgs = [...args];
129+
const redactedArgs = redactSensitiveArgs(editorArgs);
129130

130-
console.debug(`Executing Unity Editor command: ${unityPath} ${editorArgs.join(" ")}`);
131+
console.debug(`Executing Unity Editor command: ${unityPath} ${redactedArgs.join(" ")}`);
131132

132133
return await executeCommand(unityPath, editorArgs, options);
133134
} catch (error) {
@@ -621,4 +622,39 @@ class UnityEditor {
621622
}
622623
}
623624

625+
/**
626+
* Redacts sensitive arguments from the command line arguments.
627+
*
628+
* @param argv - The array of command line arguments
629+
* @param sensitiveKeys - The keys that should be redacted
630+
* @returns - The array of arguments with sensitive information redacted
631+
* @internal
632+
*/
633+
function redactSensitiveArgs(argv: string[], sensitiveKeys: string[] = ["password", "token", "secret"]): string[] {
634+
const redacted = [...argv];
635+
636+
for (let i = 0; i < redacted.length; i++) {
637+
const arg = redacted[i];
638+
639+
if (arg.startsWith("--") || arg.startsWith("-")) {
640+
const key = arg.replace(/^--?/, "");
641+
if (sensitiveKeys.includes(key.toLowerCase())) {
642+
if (i + 1 < redacted.length && !redacted[i + 1].startsWith("-")) {
643+
redacted[i + 1] = "[REDACTED]";
644+
}
645+
}
646+
} else {
647+
const match = arg.match(/^--?([^=]+)=(.+)$/);
648+
if (match) {
649+
const key = match[1];
650+
if (sensitiveKeys.includes(key.toLowerCase())) {
651+
redacted[i] = `--${key}=[REDACTED]`;
652+
}
653+
}
654+
}
655+
}
656+
657+
return redacted;
658+
}
659+
624660
export default UnityEditor;

0 commit comments

Comments
 (0)