Filter token out of stack trace

This commit is contained in:
RMidhunSuresh 2021-11-29 11:43:43 +05:30
parent bc8b3d71d5
commit d981a85239

View file

@ -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=).+/, "<snip>");
}
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<anonymous> http://localhost:3000/?loginToken=secret:26";
const result = filterLoginToken(str);
const index = result?.search("secret");
assert.equal(index, -1);
}
}
}