Skip to content

Commit

Permalink
fix: redact req.body.body (#2279)
Browse files Browse the repository at this point in the history
* fix: redact req.body.body

* fix: redact res.body
  • Loading branch information
jia1 authored Sep 25, 2024
1 parent 6e942c2 commit 2cc4ccb
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion backend/src/core/loaders/express.loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ const expressApp = ({ app }: { app: express.Application }): void => {
winstonInstance: logger,
ignoredRoutes: ['/'],
requestWhitelist: ['method', 'url', 'body', 'headers'],
responseWhitelist: ['body', 'statusCode'],
responseWhitelist: ['statusCode'],
requestFilter: (req: Request, propName: string) => {
if (propName === 'headers' && req.headers.authorization) {
// we do this instead of adding it to `headerBlacklist`
Expand All @@ -218,6 +218,11 @@ const expressApp = ({ app }: { app: express.Application }): void => {
})
)
}
if (propName === 'body' && req.body.body) {
// An example of req.body.body is the email body of an email that a user wishes to send
// We should redact such content as it may contain sensitive information
req.body.body = '[REDACTED]'
}
return (req as any)[propName]
},
metaField: null, // flatten this log to root instead of nesting under `meta`
Expand Down

0 comments on commit 2cc4ccb

Please sign in to comment.