-
Notifications
You must be signed in to change notification settings - Fork 0
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
[PLAT-639] Add credentials obfuscation #33
Changes from all commits
d673f48
830f1db
c074cb1
0dccac8
507fb00
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,3 +79,32 @@ you can skip this (not recommanded) by setting the environment variable | |
In addition, you can update the pattern on which to make the match with the | ||
environment variable `LOGGER_SENSITIVE_DATA_PATTERN`. Its value must represent | ||
a valid [capturing regular expression](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/RegExp#group_back). | ||
|
||
You also can add custom filter : | ||
``` | ||
const sensitiveDataFragment = '(pass|password)'; // Will obfuscate 'pass' and 'password' data | ||
|
||
const newLogger = init({ | ||
logger: { | ||
sensitiveDataFragment, | ||
}, | ||
}); | ||
``` | ||
|
||
Moreover, you can add customize the way it replaces data : | ||
``` | ||
const sensitiveDataPattern = [ | ||
{ | ||
regex: YOUR_NEW_REGEX, | ||
substitute: SUBSTITUTION_CONTENT, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need to specify a substitute? the default one should be enough? Don't you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Substitute is indeed replacement pattern like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it is just to avoid double quote in the equal case, I keep thinking it is not necessary. |
||
} | ||
]; // Will replace data matching with new regex by substitute content | ||
|
||
const newLogger = init({ | ||
logger: { | ||
sensitiveDataPattern, | ||
}, | ||
}); | ||
``` | ||
|
||
🚨 Process is synchronous, it means that `sensitiveDataPattern` can produce performance issues on large sizes. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,27 @@ const DEFAULT_SENSITIVE_DATA_FRAGMENTS = | |
'(mdp|password|authorization|token|pwd|auth)'; | ||
|
||
module.exports = class SensitiveDataStream { | ||
constructor(fragments) { | ||
constructor(fragments, patterns = []) { | ||
this.fragments = fragments || DEFAULT_SENSITIVE_DATA_FRAGMENTS; | ||
this.pattern = new RegExp(`"${this.fragments}":"([^"]*)"`, 'ig'); | ||
this.replacer = '__SENSITIVE_DATA__'; | ||
|
||
this.patterns = [ | ||
...patterns, | ||
{ | ||
// Default pattern | ||
regex: new RegExp(`"${this.fragments}":"([^"]*)"`, 'ig'), // @Match "mdp":"My super password" | ||
substitute: `"$1":"${this.replacer}"`, | ||
}, | ||
]; | ||
} | ||
|
||
write(input) { | ||
const sanitized = input.replace(this.pattern, '"$1":"__SENSITIVE_DATA__"'); | ||
let sanitized = input; | ||
|
||
// Apply replace on input looping through patterns array | ||
for (let pattern of this.patterns) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All the logging process is done synchronously, we must ensure this array has not too many items because it could lead to performance issues. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just updated README because for the moment there is no usage of this functionality. But if you prefer I can update code. |
||
sanitized = sanitized.replace(pattern.regex, pattern.substitute); | ||
} | ||
|
||
return process.stdout.write(sanitized); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we need to change the substitute I think we can forced to be SENSITIVE_DATA
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, it isn't realy about SENISITIVE_DATA but more about the whole pattern replacement such as :
"password":"WHATEVER"
->"$1":"WHATEVERE"
which needs dots and quotes.Althought
password=whatever
- >$1=WHATEVER
doesn't need.