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 for password leak in logs #100

Merged
merged 3 commits into from
Jun 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 44 additions & 3 deletions src/util/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ export class Logger {
return this._log(message);
}

public debug(message: string): void {
return this._debug(message);
}

public info(message: string): void {
return this._info(message);
}

public warn(message: string): void {
return this._warn(message);
}
Expand All @@ -29,7 +37,36 @@ export class Logger {
return;
}

return console.log(`${LIQUIBASE_LABEL} ${message}`);
if (this.logLevel === LiquibaseLogLevels.Debug) {
return this._debug(message);
}

return console.log(`${LIQUIBASE_LABEL} ${this.sanitizeOutput(message)}`);
}

private _debug(message: string) {
const levels = [
LiquibaseLogLevels.Debug,
LiquibaseLogLevels.Info,
LiquibaseLogLevels.Severe,
LiquibaseLogLevels.Warning,
];

if (!this.shouldOperate(levels)) {
return;
}

return console.debug('\x1b[34m%s\x1b[0m', `${LIQUIBASE_LABEL} ${message}`);
}

private _info(message: string) {
const levels = [LiquibaseLogLevels.Info, LiquibaseLogLevels.Severe, LiquibaseLogLevels.Warning];

if (!this.shouldOperate(levels)) {
return;
}

return console.info('\x1b[32m%s\x1b[0m', `${LIQUIBASE_LABEL} ${this.sanitizeOutput(message)}`);
}

private _warn(message: string) {
Expand All @@ -39,7 +76,7 @@ export class Logger {
return;
}

return console.warn('\x1b[33m%s\x1b[0m', `${LIQUIBASE_LABEL} ${message}`);
return console.warn('\x1b[33m%s\x1b[0m', `${LIQUIBASE_LABEL} ${this.sanitizeOutput(message)}`);
}

private _error(message: string) {
Expand All @@ -49,7 +86,7 @@ export class Logger {
return;
}

return console.error('\x1b[31m%s\x1b[0m', `${LIQUIBASE_LABEL} ${message}`);
return console.error('\x1b[31m%s\x1b[0m', `${LIQUIBASE_LABEL} ${this.sanitizeOutput(message)}`);
}

private shouldOperate(acceptableLogLevels: Array<LiquibaseLogLevels>) {
Expand All @@ -63,4 +100,8 @@ export class Logger {

return this.config?.logLevel || LiquibaseLogLevels.Severe;
}

private sanitizeOutput(output: string): string {
return output.replace(/password=("?\S+"?)/gi, 'password=******');
}
}
Loading