Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
phoneNumber: user.phoneNumber,
gender: user.gender
};
}
function redactAuthHeaders(payload) {
if (payload.context && payload.context.request && payload.context.request.headers) {
const headers = payload.context.request.headers;
if (headers['x-authenticated-userid']) {
headers['x-authenticated-userid'] = '[REDACTED]';
}
}
return payload;
}
apm.addFilter(redactAuthHeaders);
/**
* Return middleware that enhance the transaction data which will be sent
* to APM Server.
*
* @param {Object} options={} - Optional configuration.
* @return {function} Koa middleware.
*/
module.exports = () => {
debug('Create a middleware');
return async function apmMiddleware(ctx, next) {
// Skip if apm is disabled
if (!apm.isStarted()) {
debug('Skipped because APM is disabled');
return await next();
private setupApmFilter() {
const apm = require('elastic-apm-node');
apm.addFilter((payload: any) => {
if (!payload.context) {
return payload;
}
if (payload.context.response && payload.context.response.headers) {
if (payload.context.response.headers['x-token-refresh']) {
payload.context.response.headers['x-token-refresh'] = '[REDACTED]';
}
}
if (payload.context.request && payload.context.request.body) {
if (payload.context.request.body.password) {
payload.context.request.body.password = '[REDACTED]';
}
if (payload.context.request.body.current_password) {
payload.context.request.body.current_password = '[REDACTED]';