Skip to content

Commit

Permalink
Use safe stringify for redaction (#1587)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbi22 committed Nov 10, 2022
1 parent 121c71d commit 1ff0976
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pino.js
Expand Up @@ -117,10 +117,10 @@ function pino (...args) {
formatters.log
)

const stringifiers = redact ? redaction(redact, stringify) : {}
const stringifyFn = stringify.bind({
[stringifySafeSym]: stringifySafe
})
const stringifiers = redact ? redaction(redact, stringifyFn) : {}
const formatOpts = redact
? { stringify: stringifiers[redactFmtSym] }
: { stringify: stringifyFn }
Expand Down
19 changes: 19 additions & 0 deletions test/redact.test.js
Expand Up @@ -826,3 +826,22 @@ test('child can remove parent redact by array', async ({ equal }) => {
equal(req.headers.cookie, 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;')
equal(req.method, 'GET')
})

test('redact safe stringify', async ({ equal }) => {
const stream = sink()
const instance = pino({ redact: { paths: ['that.secret'] } }, stream)

instance.info({
that: {
secret: 'please hide me',
myBigInt: 123n
},
other: {
mySecondBigInt: 222n
}
})
const { that, other } = await once(stream, 'data')
equal(that.secret, '[Redacted]')
equal(that.myBigInt, 123)
equal(other.mySecondBigInt, 222)
})

0 comments on commit 1ff0976

Please sign in to comment.