davidmarkclements / fast-redact

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

Support for deep-wildcard object redaction #65

Open byrne-greg opened 9 months ago

byrne-greg commented 9 months ago

Tried to set-up using fast-redact for redacting PII from logs. However the logs are unstructured and it's non-obvious the package doesn't support wildcarding depths in object paths rather than widths at specific depths. e.g.

import fastRedact from 'fast-redact';

describe('fastRedact', () => {
  test('deep wildcard redaction', () => {
    const redact = fastRedact({ paths: ['*.firstName'] });
    const obj = {
      x: { firstName: 'redactme' },
      y: { a: { firstName: 'redactme' } },
      z: { c: { h: { firstName: 'redactme' } } },
    };

    expect(redact(obj)).toStrictEqual(
      JSON.stringify({
        x: { firstName: '[REDACTED]' },
        y: { a: { firstName: '[REDACTED]' } }, // is 'redactme
        z: { c: { h: { firstName: '[REDACTED]' } } }, // 'redactme'
      }),
    );
  });
});

I can get the above to work if I add paths: ['*.firstName', '*.*.firstName', '*.*.*.firstName'] but as these are unstructured logs, I'll never know the depth of the object beforehand

Have I missed something in the documentation to enable the depth wildcard traversal?

sawyerh commented 9 months ago

Potentially related: https://github.com/davidmarkclements/fast-redact/issues/5 (was just searching for the same behavior)

tushar32 commented 1 month ago

Do we have any update on this?