From 7bed5d45ce4850a9a096ed54ce8a25dff21ac9e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bianca=20Bosse=CC=81?= <> Date: Wed, 9 Nov 2022 15:53:57 -0500 Subject: [PATCH] Use safe stringify for redaction --- pino.js | 2 +- test/redact.test.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/pino.js b/pino.js index 934eb7476..c16a7456c 100644 --- a/pino.js +++ b/pino.js @@ -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 } diff --git a/test/redact.test.js b/test/redact.test.js index d5c01660c..8e9eff36e 100644 --- a/test/redact.test.js +++ b/test/redact.test.js @@ -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) +})