Gate response body debug log behind log_requests - #371
Open
adityaanikam wants to merge 1 commit into
Open
Conversation
_check_status_code logged the full response body at DEBUG on every non-200 response unconditionally, unlike the sibling debug log sites in the same class (_log_request and the "Response headers" line in _handle_response), which are both gated behind log_requests. A consumer that never sets log_requests, or sets it False, still got the response body dumped to the pybit logger on any non-200, and could only silence it by raising the logger level rather than through log_requests. The body can contain sensitive account data on some endpoints. Wrapped the one log call in the same if self.log_requests check used everywhere else in this class. Added two tests exercising _check_status_code directly: one confirms the log is absent when log_requests is not set, the other confirms it still fires when log_requests=True. Verified the first test actually catches the regression by reverting the fix locally and confirming it fails. Closes bybit-exchange#368
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
_check_status_code logged the full response body at DEBUG on every non 200 response unconditionally, unlike the sibling debug log sites in the same class (_log_request and the "Response headers" line in _handle_response), which are both gated behind log_requests. A consumer that never sets log_requests, or sets it False, still got the response body dumped to the pybit logger on any non-200, and could only silence it by raising the logger level rather than through log_requests. The body can contain sensitive account data on some endpoints.
Wrapped the one log call in the same if self.log_requests check used everywhere else in this class.
Added two tests exercising _check_status_code directly: one confirms the log is absent when log_requests is not set, the other confirms it still fires when log_requests=True. Verified the first test actually catches the regression by reverting the fix locally and confirming it fails.
Closes #368