davidmarkclements / fast-redact

very fast object redaction
MIT License
278 stars 30 forks source link

Should restore properties matching multiple paths #33

Closed th3hunt closed 3 years ago

th3hunt commented 3 years ago

The issue

Each path type (static, group, nested) uses an isolated way of storing and restoring values on the original object.

In case of a property that matches multiple redaction paths, this isolation leads to loss of information as it fails to restore the original value on the original mutated object.

The issue can be reproduced with the following:

const redact = fastRedact({
  paths: ['a', '*.b', 'x.b'],
  serialize: false
})
const o = {
  x: {
    a: 'a',
    b: 'b'
  }
}
redact(o)

In this example x.b would match both the static x.b path and the wildcard *.b path leading in the original object being restored as:

{
  x: {
    a: 'a',
    b: '[REDACTED]'
  }
}

I prepared #34 that resolves this issue. Haven't checked the performance impact yet but will do asap.