Skip to content

Redact credentials in urllib3's DEBUG request logs - #209

Merged
jinskeep-morpc merged 1 commit into
mainfrom
fix/redact-urllib3-debug
Sep 24, 2026
Merged

jinskeep-morpc merged 1 commit into
mainfrom
fix/redact-urllib3-debug

Conversation

@jinskeep-morpc

Copy link
Copy Markdown
Collaborator

Follow-up to #207 (#206).

Problem

After #207, morpc's own logs no longer contain the Census API key. With logging at DEBUG, though, urllib3 (used by requests) logs every request line, query string included, e.g. "GET /data/2024/acs/acs5?get=...&key=<key> HTTP/1.1" 200, so the key still reached the logs.

Change

morpc.req attaches a logging.Filter to the urllib3.connectionpool logger. The filter runs redact() over each record's message and string arguments. It's installed when morpc.req is imported, so it applies whether or not morpc.logs.config_logs is used. The request details stay in DEBUG output with credentials replaced by REDACTED, so they're still useful for debugging; urllib3 isn't silenced.

Testing

  • New test test_urllib3_debug_request_log_is_redacted: it logs a request line the way urllib3 does and asserts the host is kept and the key is redacted. It failed before the change.
  • test_req (12), test_frictionless, test_gpkg, test_morpc, test_release, and test_geocode all pass. test_utils: the same 4 datetime tests fail on main.
  • Live, logging at DEBUG, two region15 CensusAPI fetches (ACS 5-year 2024 places, 2017 070): 281 urllib3 request lines logged, and the key doesn't appear anywhere in the log.

🤖 Generated with Claude Code

urllib3 logs every request line, query string included, at DEBUG, so
running with DEBUG logging still wrote the Census API key into logs
after #207. morpc.req now attaches a filter to the urllib3.connectionpool
logger that redacts key, token, and api_key in its records. The request
details stay in the log.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jinskeep-morpc
jinskeep-morpc merged commit 2f48be5 into main Sep 24, 2026
1 check passed
@jinskeep-morpc jinskeep-morpc mentioned this pull request Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant