oapi-sdk-python icon indicating copy to clipboard operation
oapi-sdk-python copied to clipboard

fix(ws): redact credentials from connection logs

Open Bruce-anle opened this issue 4 months ago • 1 comments

Summary

  • redact access_key and ticket values 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() and Client._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; and
  • Client._conn_url retains 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

Bruce-anle avatar Jul 11 '26 18:07 Bruce-anle

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Jul 11 '26 18:07 CLAassistant