Describe the bug
During the value masking process, objects passed to the logger are run through this function:
|
obj[key] = this.settings.maskPlaceholder; |
As you can see, it directly modifies the source object, meaning the original value is replaced with the placeholder.
After an object containing masked keys is passed to the logger the original secret is destroyed, which throws errors when using the secret elsewhere in code.
To Reproduce
Steps to reproduce the behavior:
- Add
maskValuesOfKeys: ["foo"] rule to options.
{
// ...
maskValuesOfKeys: ["foo"]
}
- Instantiate a logger.
- Run
const test = { foo: "bar" }
logger.info(test)
if(test.foo !== "bar") {
throw Error(`Test value was modified by logger.`)
}
- See error
Expected behavior
A deep clone of any objects should be performed prior to masking.
Node.js Version
e.g. 18.x
Describe the bug
During the value masking process, objects passed to the logger are run through this function:
tslog/src/BaseLogger.ts
Line 208 in 91c0378
As you can see, it directly modifies the source object, meaning the original value is replaced with the placeholder.
After an object containing masked keys is passed to the logger the original secret is destroyed, which throws errors when using the secret elsewhere in code.
To Reproduce
Steps to reproduce the behavior:
maskValuesOfKeys: ["foo"]rule to options.Expected behavior
A deep clone of any objects should be performed prior to masking.
Node.js Version
e.g. 18.x