Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redact fails when both the parent and child nodes are redacted #66

Open
jonathansamines opened this issue Jan 8, 2024 · 0 comments
Open

Comments

@jonathansamines
Copy link

The following redaction pattern works on v3.1.2 and v3.2.0 but not on v3.3.0:

'use strict';

const fastRedact = require('fast-redact');

const thing = {
  prop: {
    top: {
      secret: 'top secret',
    },
  },
};

const redact = fastRedact({
  paths: ['*.*.secret', '*.top'],
  censor: '**SECRET**',
});

console.log(redact(thing));

On v3.3.0 it fails with the following error:

/Users/user/project/node_modules/fast-redact/lib/modifiers.js:54
    current[path[0]] = value
                     ^

TypeError: Cannot create property 'secret' on string '**SECRET**'
    at Object.nestedRestore (/Users/user/project/node_modules/fast-redact/lib/modifiers.js:54:22)
    at Object.eval (eval at compileRestore (/Users/user/project/node_modules/fast-redact/lib/restorer.js:15:20), <anonymous>:12:17)
    at Object.eval (eval at redactor (/Users/user/project/node_modules/fast-redact/lib/redactor.js:9:18), <anonymous>:24:10)
    at Object.<anonymous> (/Users/user/project/test.js:18:13)

The conditions to generate this failure seem to be:

  • You are redacting a node (e.g top), but also one of it's child (e.g top.secret)
  • In the redaction paths, you specify the child redaction pattern before the parent redaction pattern (e.g ['*.*.secret', '*.top'] fails but ['*.top', '*.*.secret'] works)

Would appreciate some help to understand whether this is working as designed, a bug or known limitation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant