scrub headers when logging

This commit is contained in:
takumi
2020-08-17 14:14:33 +09:00
parent 9ba430c228
commit ca5696eed5

View File

@@ -98,9 +98,23 @@ function onError(err, req, res) {
console.log('Error in proxied request', err, req.method, req.url);
}
const SENSITIVE_HEADER_KEYS = ['authorization'];
function scrubHeaders(headers) {
const res = Object.assign({}, headers);
SENSITIVE_HEADER_KEYS.forEach(function(key) {
if (res.hasOwnProperty(key)) {
delete res[key];
}
});
return res;
}
function onProxyRes(proxyRes, req, res) {
console.log('VERBOSE REQUEST', req.method, req.protocol, req.hostname, req.url, req.headers);
console.log('VERBOSE RESPONSE', proxyRes.statusCode, proxyRes.headers);
const reqHeaders = scrubHeaders(req.headers);
console.log('VERBOSE REQUEST', req.method, req.protocol, req.hostname, req.url, reqHeaders);
const proxyResHeaders = scrubHeaders(proxyRes.headers);
console.log('VERBOSE RESPONSE', proxyRes.statusCode, proxyResHeaders);
}
function handleErrors(err, req, res, next) {