Skip to content
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

Merged
merged 5 commits into from
Aug 8, 2019

Conversation

Antoninbln
Copy link
Contributor

@Antoninbln Antoninbln commented Aug 7, 2019

Purpose of this PR

To be clean with sentry implementation, we need to obfuscate some critical information in logs such as TOKEN=MY_TOKEN or "token": "My token".

Changes

  • New obfuscation mode has been added : for example password=My-super-password in log.msg is now obfuscated by default ;
  • Parameters of SensitiveDataStream has changed :
    • fragments -> Example : (password|mdp);
    • patterns -> Example : [{ regex: YOUR_REGEX, substitute: SUBSTITUTION_CONTENT }];
  • Add the possibility to provide an "obfuscation config" to obfuscate whatever you want. To do this you need to use :
const newLogger = init({
   logger: { sensitiveDataFragment, sensitiveDataPattern },
});
  • Update documentation

@Antoninbln Antoninbln requested a review from a team August 7, 2019 13:55
@codecov
Copy link

codecov bot commented Aug 7, 2019

Codecov Report

Merging #33 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #33   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           4      4           
  Lines          39     44    +5     
=====================================
+ Hits           39     44    +5
Impacted Files Coverage Δ
index.js 100% <ø> (ø) ⬆️
streams/sensitive-data.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9648ed5...d673f48. Read the comment docs.

@codecov
Copy link

codecov bot commented Aug 7, 2019

Codecov Report

Merging #33 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #33   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           4      4           
  Lines          39     42    +3     
=====================================
+ Hits           39     42    +3
Impacted Files Coverage Δ
index.js 100% <ø> (ø) ⬆️
streams/sensitive-data.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9648ed5...507fb00. Read the comment docs.

@Antoninbln Antoninbln changed the title [PLAT-639] Add credentials offuscation [PLAT-639] Add credentials obfuscation Aug 7, 2019
Copy link
Contributor

@ygrandmaitre ygrandmaitre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM some comment about default regexp

{
regex: new RegExp(`${this.fragments}=([\\w-]*)`, 'ig'), // @Match mdp=My-super-password
substitute: `$1=${this.replacer}`,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should only have the first regexp by default to be iso with the actual version of the logger.
And the second regex should only be used in nestor-api

const sensitiveDataPattern = [
{
regex: YOUR_NEW_REGEX,
substitute: SUBSTITUTION_CONTENT,
Copy link
Contributor

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

Copy link
Contributor Author

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.

regex: new RegExp(`"${this.fragments}":"([^"]*)"`, 'ig'), // @Match "mdp":"My super password"
substitute: `"$1":"${this.replacer}"`,
},
{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove this case from the default regexp to keep the same behaviour as before.

const sensitiveDataPattern = [
{
regex: YOUR_NEW_REGEX,
substitute: SUBSTITUTION_CONTENT,

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

@Antoninbln Antoninbln Aug 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Substitute is indeed replacement pattern like "$1":"__SENSITIVE_DATA__", and it is not the same depending on cases, sometimes we need quotes, for other ones we don't necessarily need.

Choose a reason for hiding this comment

The 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.

let sanitized = input;

// Apply replace on input looping through patterns array
for (let pattern of this.patterns) {

Choose a reason for hiding this comment

The 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.
If we don't do anything in code we must at least warn the users in the documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

@ygrandmaitre ygrandmaitre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Antoninbln Antoninbln merged commit 608c4a3 into master Aug 8, 2019
Antoninbln pushed a commit that referenced this pull request Aug 9, 2019
…entials"

This reverts commit 608c4a3, reversing
changes made to 9648ed5.
@JulienJourdain JulienJourdain deleted the PLAT-639-offuscate-credentials branch December 16, 2019 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants