Skip to content

Commit 1ff0976

Browse files
authored
Use safe stringify for redaction (#1587)
1 parent 121c71d commit 1ff0976

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

pino.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ function pino (...args) {
117117
formatters.log
118118
)
119119

120-
const stringifiers = redact ? redaction(redact, stringify) : {}
121120
const stringifyFn = stringify.bind({
122121
[stringifySafeSym]: stringifySafe
123122
})
123+
const stringifiers = redact ? redaction(redact, stringifyFn) : {}
124124
const formatOpts = redact
125125
? { stringify: stringifiers[redactFmtSym] }
126126
: { stringify: stringifyFn }

test/redact.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,3 +826,22 @@ test('child can remove parent redact by array', async ({ equal }) => {
826826
equal(req.headers.cookie, 'SESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43; _gat=1;')
827827
equal(req.method, 'GET')
828828
})
829+
830+
test('redact safe stringify', async ({ equal }) => {
831+
const stream = sink()
832+
const instance = pino({ redact: { paths: ['that.secret'] } }, stream)
833+
834+
instance.info({
835+
that: {
836+
secret: 'please hide me',
837+
myBigInt: 123n
838+
},
839+
other: {
840+
mySecondBigInt: 222n
841+
}
842+
})
843+
const { that, other } = await once(stream, 'data')
844+
equal(that.secret, '[Redacted]')
845+
equal(that.myBigInt, 123)
846+
equal(other.mySecondBigInt, 222)
847+
})

0 commit comments

Comments
 (0)