Skip to content

Support for deep-wildcard object redaction #65

Description

@byrne-greg

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions