Skip to content

Commit c407698

Browse files
redact specific re and res properties
1 parent 10350b5 commit c407698

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## [0.6.0] - 2024-11-27
4+
- Redact specific properties in req and res
5+
36
## [0.5.9] - 2024-10-30
47
- Upgrade to `dd-trace` and `express` to their latest minor version.
58

bufflog.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
import {
2+
REQ_KEYS_REDACTED,
3+
REQ_CONTEXT_KEYS_REDACTED,
4+
RES_KEYS_REDACTED,
5+
RES_CONTEXT_KEYS_REDACTED
6+
} from './constants'
17
const pinoLogger = require('pino')({
28
level: process.env.LOG_LEVEL ? String.prototype.toLowerCase.apply(process.env.LOG_LEVEL) : "notice",
39
// probably we want to call it `msg`. if so, let's change the PHP library instead
@@ -19,7 +25,12 @@ const pinoLogger = require('pino')({
1925
useOnlyCustomLevels: true,
2026

2127
redact: {
22-
paths: ['req', 'res', 'context.req', 'context.res'],
28+
paths: [
29+
...REQ_KEYS_REDACTED,
30+
...RES_KEYS_REDACTED,
31+
...REQ_CONTEXT_KEYS_REDACTED,
32+
...RES_CONTEXT_KEYS_REDACTED,
33+
],
2334
censor: '[ REDACTED ]',
2435
},
2536
});

constants.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const SERVER_KEYS_TO_REDACT = [
2+
'body.password',
3+
'query.password',
4+
'cookies',
5+
'fresh',
6+
'res',
7+
'secure',
8+
'signedCookies',
9+
'stale',
10+
'xhr',
11+
'headers'
12+
]
13+
14+
export const REQ_KEYS_REDACTED = SERVER_KEYS_TO_REDACT.map((el: string) => `req.${el}`)
15+
export const REQ_CONTEXT_KEYS_REDACTED = SERVER_KEYS_TO_REDACT.map((el: string) => `context.req.${el}`)
16+
export const RES_KEYS_REDACTED = SERVER_KEYS_TO_REDACT.map((el: string) => `res.${el}`)
17+
export const RES_CONTEXT_KEYS_REDACTED = SERVER_KEYS_TO_REDACT.map((el: string) => `context.res.${el}`)

0 commit comments

Comments
 (0)