forked from mystiq/hydrogen-web
Filter token out of stack trace
This commit is contained in:
parent
bc8b3d71d5
commit
d981a85239
|
@ -19,6 +19,11 @@ import {LogLevel, LogFilter} from "./LogFilter";
|
||||||
import type {BaseLogger} from "./BaseLogger";
|
import type {BaseLogger} from "./BaseLogger";
|
||||||
import type {ISerializedItem, ILogItem, LogItemValues, LabelOrValues, FilterCreator, LogCallback} from "./types";
|
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 {
|
export class LogItem implements ILogItem {
|
||||||
public readonly start: number;
|
public readonly start: number;
|
||||||
public logLevel: LogLevel;
|
public logLevel: LogLevel;
|
||||||
|
@ -155,7 +160,7 @@ export class LogItem implements ILogItem {
|
||||||
if (this.error) {
|
if (this.error) {
|
||||||
// (e)rror
|
// (e)rror
|
||||||
item.e = {
|
item.e = {
|
||||||
stack: this.error.stack,
|
stack: filterLoginToken(this.error.stack),
|
||||||
name: this.error.name,
|
name: this.error.name,
|
||||||
message: this.error.message.split("\n")[0]
|
message: this.error.message.split("\n")[0]
|
||||||
};
|
};
|
||||||
|
@ -259,3 +264,14 @@ export class LogItem implements ILogItem {
|
||||||
return this._children;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue