File size: 469 Bytes
befd7da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
'use strict';

const DEFAULT_SENSITIVE_DATA_FRAGMENTS =
  '(mdp|password|authorization|token|pwd|auth)';

module.exports = class SensitiveDataStream {
  constructor(fragments) {
    this.fragments = fragments || DEFAULT_SENSITIVE_DATA_FRAGMENTS;
    this.pattern = new RegExp(`"${this.fragments}":"([^"]*)"`, 'ig');
  }
  write(input) {
    const sanitized = input.replace(this.pattern, '"$1":"__SENSITIVE_DATA__"');

    return process.stdout.write(sanitized);
  }
};