Potential fix for code scanning alert no. 7: Clear-text logging of sensitive information #1644
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Potential fix for https://github.com/stripe/stripe-python/security/code-scanning/7
To fix this, we must ensure that any data passed to logging functions cannot inadvertently include sensitive fields like "api_key" or "Authorization". The best way to accomplish this is by filtering out or redacting such sensitive values from dictionaries before formatting and logging them. Specifically, just before logging request details, defensive code should be inserted to remove (
pop) or replace values of sensitive keys (such as "api_key", "Authorization", and even "headers" fields that may contain such keys) with a placeholder (e.g., "REDACTED"). This should be done at the start of the logging functions, or in a helper that is called on all logging parameters.To implement:
stripe/_util.py(in the provided code region) that takes a dictionary and returns a copy with sensitive keys redacted ("api_key", "Authorization", "password", etc.).log_infoandlog_debugfunctions before loggingparams.Suggested fixes powered by Copilot Autofix. Review carefully before merging.