Skip to content

fix(core): redact keystore passwords from command errors and logs - #1085

Open
kiranp97 wants to merge 1 commit into
GoogleChromeLabs:mainfrom
kiranp97:fix/redact-keystore-passwords
Open

kiranp97 wants to merge 1 commit into
GoogleChromeLabs:mainfrom
kiranp97:fix/redact-keystore-passwords

Conversation

@kiranp97

@kiranp97 kiranp97 commented Dec 2, 2026

Copy link
Copy Markdown

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

  • Added redactSensitiveCommand, redactSensitiveArgs, and sanitizeExecError in packages/core/src/lib/util.ts and applied them in execute and executeFile (covering err.message, err.stack, err.cmd, and log.debug).
  • Masked password and keypassword in KeyTool#createSigningKey debug logging.
  • Added regression tests in utilSpec.ts and KeyToolSpec.ts.

Verification

  • npm run build passed across all packages.
  • Targeted ESLint check passed on all modified files.
  • npm test passed (@bubblewrap/validator: 23 specs, @bubblewrap/core: 165 specs, @bubblewrap/cli: 36 specs + 1 existing pending spec, 0 failures).

Fixes #1049

@gstepniewski-google gstepniewski-google left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 =

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"(?:\\.|[^"])*" 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++) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Security: CLI error prints key store password to terminal

2 participants