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 causes infinite recursion #1513

Closed
meirkeller opened this issue Aug 10, 2022 · 7 comments
Closed

Redact causes infinite recursion #1513

meirkeller opened this issue Aug 10, 2022 · 7 comments

Comments

@meirkeller
Copy link

Reproduction

const pino = require('pino');

const logger = pino({
  redact: { paths: ['*.d', '*.*.d', '*.*.*.d'] },
});

const obj = {
  x: { c: { d: 'hide me', e: 'leave me be' } },
  y: { c: { d: 'and me', f: 'I want to live' } },
  z: { c: { d: 'and also I', g: 'I want to run in a stream' } },
};

logger.info(obj);
console.log(obj);

Output

{"level":30,"time":1660124503113,"pid":28160,"hostname":"MAC-Meir Keller","x":{"c":{"d":"[Redacted]","e":"leave me be"}},"y":{"c":{"d":"[Redacted]","f":"I want to live"}},"z":{"c":{"d":"[Redacted]","g":"I want to run in a stream"}}}
{
  x: { c: <ref *1> { d: [Circular *1], e: 'leave me be' } },
  y: { c: <ref *2> { d: [Circular *2], f: 'I want to live' } },
  z: {
    c: <ref *3> {
      d: [Circular *3],
      g: 'I want to run in a stream'
    }
  }
}
@mcollina
Copy link
Member

Same as davidmarkclements/fast-redact#50.

@meirkeller
Copy link
Author

Same as davidmarkclements/fast-redact#50.
It's worse. There the issue is, that the object doesn't restore.

@mcollina
Copy link
Member

Seems the actual same. Pino doesn't do anything more that calling fast-redact.

@meirkeller
Copy link
Author

For some reason it behaves different.

@mcollina
Copy link
Member

We actually do some manipulation of the wildcards:

pino/lib/redaction.js

Lines 18 to 70 in 0a56154

const shape = paths.reduce((o, str) => {
rx.lastIndex = 0
const first = rx.exec(str)
const next = rx.exec(str)
// ns is the top-level path segment, brackets + quoting removed.
let ns = first[1] !== undefined
? first[1].replace(/^(?:"|'|`)(.*)(?:"|'|`)$/, '$1')
: first[0]
if (ns === '*') {
ns = wildcardFirstSym
}
// top level key:
if (next === null) {
o[ns] = null
return o
}
// path with at least two segments:
// if ns is already redacted at the top level, ignore lower level redactions
if (o[ns] === null) {
return o
}
const { index } = next
const nextPath = `${str.substr(index, str.length - 1)}`
o[ns] = o[ns] || []
// shape is a mix of paths beginning with literal values and wildcard
// paths [ "a.b.c", "*.b.z" ] should reduce to a shape of
// { "a": [ "b.c", "b.z" ], *: [ "b.z" ] }
// note: "b.z" is in both "a" and * arrays because "a" matches the wildcard.
// (* entry has wildcardFirstSym as key)
if (ns !== wildcardFirstSym && o[ns].length === 0) {
// first time ns's get all '*' redactions so far
o[ns].push(...(o[wildcardFirstSym] || []))
}
if (ns === wildcardFirstSym) {
// new * path gets added to all previously registered literal ns's.
Object.keys(o).forEach(function (k) {
if (o[k]) {
o[k].push(nextPath)
}
})
}
o[ns].push(nextPath)
return o
}, {})
. So maybe this is confusing it even more.

@meirkeller
Copy link
Author

Fixed in davidmarkclements/fast-redact#51

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants