Skip to content

fix(ws): redact access_key and ticket from WebSocket lifecycle logs - #155

Open
Xuxchloris wants to merge 1 commit into
larksuite:v2_mainfrom
Xuxchloris:fix/redact-ws-conn-url
Open

fix(ws): redact access_key and ticket from WebSocket lifecycle logs#155
Xuxchloris wants to merge 1 commit into
larksuite:v2_mainfrom
Xuxchloris:fix/redact-ws-conn-url

Conversation

@Xuxchloris

Copy link
Copy Markdown

Fixes #141.

Problem

Client._connect() and _disconnect() log the complete WebSocket connection URL at INFO level. The URL returned by the Lark WebSocket endpoint contains sensitive access_key and ticket query values, so lifecycle logs can disclose credentials to stdout, journals, or downstream log collectors.

Change

  • New _redact_conn_url(url) helper in lark_oapi/ws/client.py: parses the URL and masks the access_key and ticket query values (***) while preserving the rest of the URL. Returns the input untouched when there is no query.
  • Both log sites (connected to …, disconnected to …) now log the redacted URL. The URL passed to websockets.connect() is unchanged.

Tests

lark_oapi/ws/tests/test_redact_conn_url.py:

  • secrets are absent from the redacted URL, keys remain, non-sensitive query params (fpid, service_id) and host/path are preserved;
  • URLs without a query are returned unchanged;
  • None/empty input is handled.

Verification

  • python -m pytest lark_oapi/ws/tests/test_redact_conn_url.py — 3/3 pass.

Client._connect()/_disconnect() logged the full WS endpoint URL at INFO
level; the URL query carries access_key and ticket credentials, leaking
them to stdout/journals/log collectors. Adds _redact_conn_url() which
masks those two query values for logging while preserving the rest of the
URL, and uses it at both log sites. The URL passed to websockets.connect()
is unchanged. Fixes larksuite#141.
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.

Redact access_key and ticket from WebSocket lifecycle INFO logs

1 participant