-
Notifications
You must be signed in to change notification settings - Fork 186
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
bodyBlacklist doesn't work for responses #253
Comments
+1 it would be very nice to have this feature. |
This can be achieved by using a import * as expressWinston from 'express-winston';
function bodySanitizer(
body: Record<string, unknown> | undefined,
bodyBlacklist: string[] | undefined,
): Record<string, unknown> | undefined {
if (body && bodyBlacklist) {
for (const key of bodyBlacklist) {
if (body[key]) {
body[key] = 'REDACTED';
}
}
}
return body;
}
const bodyBlacklist = ['secret'];
expressWinston.logger({
bodyBlacklist,
responseFilter: (res: expressWinston.FilterResponse, propName: string) => {
if (propName === 'body') {
res['body'] = bodySanitizer({ ...res['body'] }, bodyBlacklist);
}
return (res as any)[propName];
},
}); |
+1 to this. The bodyBlacklist feature doesn't indicate that its only for requests so you would assume both req/res are covered. Having to use one list for req and a more in-depth approach for res sucks for consistency 😢 |
+1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When using this library, I noticed that the
bodyBlacklist
feature doesn't work as I thought it should.bodyBlacklist
I expected the following code to include the request/response bodies in the logs but strip top-level key/value pairs where the key is "secret".
However, when performing a request such as
I can see that "secret" is stripped from the request logs, but not from the response logs.
responseWhitelist
I also tried to only allow certain keys by using the
responseWhitelist
like that:but even though my route is returning a key/value pair with the key "foo", no response body gets logged.
I prepared a reproduction example for you to try it out quickly.
The text was updated successfully, but these errors were encountered: