diff --git a/src/logging/LogItem.ts b/src/logging/LogItem.ts index da009b06..bb8815db 100644 --- a/src/logging/LogItem.ts +++ b/src/logging/LogItem.ts @@ -19,6 +19,11 @@ import {LogLevel, LogFilter} from "./LogFilter"; import type {BaseLogger} from "./BaseLogger"; import type {ISerializedItem, ILogItem, LogItemValues, LabelOrValues, FilterCreator, LogCallback} from "./types"; +// Make sure that loginToken does not end up in the logs +function filterLoginToken(trace?: string): string | undefined { + return trace?.replace(/(?<=\/\?loginToken=).+/, ""); +} + export class LogItem implements ILogItem { public readonly start: number; public logLevel: LogLevel; @@ -155,7 +160,7 @@ export class LogItem implements ILogItem { if (this.error) { // (e)rror item.e = { - stack: this.error.stack, + stack: filterLoginToken(this.error.stack), name: this.error.name, message: this.error.message.split("\n")[0] }; @@ -259,3 +264,14 @@ export class LogItem implements ILogItem { return this._children; } } + +export function tests() { + return { + "Login token removed from item": (assert) => { + const str = "main http://localhost:3000/src/main.js:55\n http://localhost:3000/?loginToken=secret:26"; + const result = filterLoginToken(str); + const index = result?.search("secret"); + assert.equal(index, -1); + } + } +}