-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Logging mask credentials #12292
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
Logging mask credentials #12292
Conversation
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.
LGTM! Nice test, pretty neat 👌
I only have one comment regarding the dict
usage for storing the pattern + key, I wonder if we could save the replacement value already at init time. Very minor, not really blocking!
for key, pattern in self.patterns.items(): | ||
message = re.sub(pattern, to_bytes(f'"{key}": "******"'), message) |
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.
question/nit: should we actually save the pattern and the replacement value already in self.patterns
?
Maybe we do not need a dict, and could use a list of tuple?
So that we would need to convert the replacement value every time. It's quite a minor optimisation, but I'm not seeing the value of a dict directly here as we never access it by key.
Something like:
self.patterns = [(re.compile(to_bytes(rf'"{key}":\s*"[^"]+"')), to_bytes(f'"{key}": "******"')) for key in self.sensitive_keys]
...
for pattern, repl_value in self.patterns.items():
message = re.sub(pattern, repl_value, message)
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.
you are totally right 👀. I missed that simple fact! 🤣 I will update 😉
Motivation
This pr introduces a logging filter that can be used to mask sensitive values in our http logger. As we log every incoming HTTP request raw body, we can user this filter to find sensitive keys in a json string and mask their value.
Changes