oapi-sdk-python
oapi-sdk-python copied to clipboard
fix(ws): redact credentials from connection logs
Summary
- redact
access_keyandticketvalues in WebSocket connection and disconnection INFO logs - preserve every other URL byte, including query ordering, percent-encoding, empty/value-less parameters, repeats, and fragments
- keep the original URL for
websockets.connect()andClient._conn_url
Closes #141.
Root cause
Client._connect() and _disconnect() formatted the complete server-provided WebSocket URL directly into lifecycle logs. That URL carries sensitive authentication query values.
The fix uses a small log-only scanner. It replaces only the value bytes of ASCII case-insensitive access_key and ticket keys, without parsing or normalizing the URL.
Tests
pytest -q lark_oapi/ws/tests/test_client_log_redaction.py
2 passed, 2 warnings
pytest -q lark_oapi/ws/tests/
15 passed, 2 warnings
git diff --check origin/v2_main..HEAD
clean
The regression test proves that:
- connect and disconnect each emit a redacted lifecycle message;
- the original sensitive values are absent from both messages;
- non-sensitive URL bytes remain unchanged;
websockets.connect()receives the exact original URL; andClient._conn_urlretains the exact original URL until disconnect.
Environment and limits
- WSL2 Ubuntu on Windows 11
- Python 3.12 test virtual environment
- no real Lark credentials or live WebSocket endpoint were used
- the WS suite still reports pre-existing event-loop/cache cleanup and deprecation warnings; all tests exit successfully