Repository navigation
fix(logutils): redact Basic/Token/ApiKey auth headers and URL userinfo - #399
Merged
msoedov merged 1 commit intoNov 26, 2026
Merged
Conversation
Owner
|
@brixtonpham thx for the patch man, appreciate it! |
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.
Problem
agentic_security.logutils.redact()currently masksAuthorization: Bearer ...and query-string secrets, but leaks two common credential formats in logs andhttpxerrors:Authorization/Proxy-Authorizationschemes (Basic,Token,ApiKey,Api-Key): the header pattern stops at the space after the scheme name, and short scheme names (< 8 chars) don't match, so credentials likeAuthorization: Basic dXNlcjpzZWNyZXQ=,{"Authorization": "Token tok_..."}, andAuthorization: ApiKey key_...pass through in plaintext.https://user:secretpass@api.example.com/v1/chat,http://token@proxy.example.com:8080/v1, andpostgresql://dbuser:dbsecret@db.example.com:5432/apppass through unredacted.Solution
agentic_security/logutils.pywith an optional horizontal-whitespace-delimited scheme prefix(?:(?:Basic|Token|ApiKey|Api-Key)[ \t]+)?inside the preserved capture group (keepingBearerhandling, short placeholders likeAuthorization: Basic XXXXX, and ordinary log prose untouched).scheme://userinfo@hostwhile preserving scheme,@, host, port, path, and query parameters, and leaving email addresses (standalone, in URL paths/queries, or comma-separated after URLs) unchanged.tests/unit/test_log_redaction.pycovering both redaction cases, structure preservation, and non-secret false-positive guards.Testing
OPENAI_API_KEY="sk-fake" python3 -m pytest tests/unit/test_log_redaction.py -v: 41 passedOPENAI_API_KEY="sk-fake" python3 -m pytest . -q: 618 passed, 4 skippedblack --check,flake8,codespell,pycln,pyupgrade,poetry check --lock: clean