Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: hide sensitive data from debug logs #1797

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 16 additions & 4 deletions lib/utils/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,24 @@ export default function genDebugFunction(
return; // no-op
}

let sanitizeString = false;
// we skip the first arg because that is the message
for (let i = 1; i < args.length; i++) {
const str = getStringValue(args[i]);
if (typeof str === "string" && str.length > MAX_ARGUMENT_LENGTH) {
args[i] = genRedactedString(str, MAX_ARGUMENT_LENGTH);
}
const str = getStringValue(args[i]);
if(sanitizeString) {
// The previous array index indicates this current index
// needs to be removed from the logs.
args[i] = '***********';
sanitizeString = false;
continue;
}
if(typeof str === "string" && str === 'auth') {
kinueng marked this conversation as resolved.
Show resolved Hide resolved
// Expect the next array index will contain
// sensitive data that should not be in plaintext
sanitizeString = true;
} else if (typeof str === "string" && str.length > MAX_ARGUMENT_LENGTH) {
args[i] = genRedactedString(str, MAX_ARGUMENT_LENGTH);
}
}

return fn.apply(null, args);
Expand Down