Repository navigation
Conversation
gstepniewski-google
left a comment
There was a problem hiding this comment.
Hi, thanks for working on this! Overall looks good, just a few gaps to close.
| export const REDACTED_SECRET = '***'; | ||
|
|
||
| const PASSWORD_FLAGS = new Set(['--ks-pass', '--key-pass', '-storepass', '-keypass']); | ||
| const PASSWORD_ARG_REGEX = |
There was a problem hiding this comment.
"(?:\\.|[^"])*" and '(?:\\.|[^'])*' have overlapping backslash branches (\\. vs [^"]/[^']), which causes exponential backtracking (ReDoS) on unterminated quoted strings with repeated backslashes; additionally, without a leading boundary, flags can match mid-token (e.g. foo-storepass bar). Exclude \\ from the negated classes ("(?:\\[\s\S]|[^"\\])*" and '(?:\\[\s\S]|[^'\\])*') and anchor flags to start-of-string or whitespace (e.g. (?<!\S) or a preserved (^|\s) group).
| */ | ||
| export function redactSensitiveCommand(command: string, args: string[] = []): string { | ||
| let redacted = command; | ||
| for (let i = 0; i < args.length - 1; i++) { |
There was a problem hiding this comment.
Single-element flag=value arguments (e.g. --ks-pass=pass:my secret or --ks-pass=pass:"a"b") bypass PASSWORD_FLAGS.has(...) in both redactSensitiveCommand and redactSensitiveArgs and fall back to PASSWORD_ARG_REGEX, leaking everything after the first space or quote. Handle arg.startsWith(${flag}=) explicitly in both functions via maskPasswordValue, and add i++ after matching PASSWORD_FLAGS.has(args[i]) in redactSensitiveCommand (matching redactSensitiveArgs) so a flag-like password value is not re-parsed as a flag.
| return redacted; | ||
| } | ||
|
|
||
| function sanitizeExecError(err: unknown, args: string[] = []): unknown { |
There was a problem hiding this comment.
util.promisify(exec) and util.promisify(execFile) also attach stdout and stderr as enumerable properties on the rejected error, so shell or wrapper output echoing the failing command can still leak passwords via err.stderr/err.stdout or console.error(err). Redact execErr.stdout and execErr.stderr when they are strings in sanitizeExecError as well.
Redacts sensitive keystore and key password flags (
--ks-pass,--key-pass,-storepass,-keypass) from shell execution errors and debug logs so secrets and their lengths are not printed to the terminal when a command fails.Changes
redactSensitiveCommand,redactSensitiveArgs, andsanitizeExecErrorinpackages/core/src/lib/util.tsand applied them inexecuteandexecuteFile(coveringerr.message,err.stack,err.cmd, andlog.debug).passwordandkeypasswordinKeyTool#createSigningKeydebug logging.utilSpec.tsandKeyToolSpec.ts.Verification
npm run buildpassed across all packages.npm testpassed (@bubblewrap/validator: 23 specs,@bubblewrap/core: 165 specs,@bubblewrap/cli: 36 specs + 1 existing pending spec, 0 failures).Fixes #1049