fix: sanitize API error responses to prevent credential leakage#34
Open
prabhakarpujeri wants to merge 1 commit intohuggingface:mainfrom
Open
fix: sanitize API error responses to prevent credential leakage#34prabhakarpujeri wants to merge 1 commit intohuggingface:mainfrom
prabhakarpujeri wants to merge 1 commit intohuggingface:mainfrom
Conversation
Added _sanitize_response() function that: - Truncates long responses to 500 characters max - Redacts sensitive patterns (bearer tokens, API keys, secrets, passwords) - Applied to all error handling paths in _make_request() This prevents potential credential exposure in logs, CLI output, and monitoring tools when API error responses contain sensitive data. Fixes huggingface#30
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.
Summary
_sanitize_response()function to prevent credential leakage in error messagesProblem
API error responses were included directly in exception messages without sanitization. If the API returned tokens, credentials, or user data in error responses, this information could be logged or displayed to users.
Solution
Added a sanitization function in
client.pythat:Applied to all three locations where
response.textwas used:Changes
dell_ai/client.py- Added_sanitize_response()function and applied it to error handlingtests/unit/test_client.py- Added 14 new tests for sanitization logicTest plan
Fixes #30