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

Use safe stringify for redaction #1587

Merged
merged 1 commit into from Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
})