Skip to content

Commit

Permalink
Fix for password leak in logs (#100)
Browse files Browse the repository at this point in the history
* Fix for password leak in logs

Fixes: #99

Signed-off-by: Vinay Potluri <[email protected]>

* lint fixes

---------

Signed-off-by: Vinay Potluri <[email protected]>
Co-authored-by: Alejandro Alvarez <[email protected]>
  • Loading branch information
vinaypotluri and jandroav authored Jun 20, 2024
1 parent bdae640 commit 8ca991c
Showing 1 changed file with 44 additions and 3 deletions.
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=******');
}
}

0 comments on commit 8ca991c

Please sign in to comment.