Skip to content

fix(realtime): redact API keys and access tokens from debug logs - #1992

Merged
spydon merged 3 commits into
mainfrom
lukasklingsbo/sdk-2814-realtime-access-tokens-are-written-to-debug-logs
Nov 5, 2026
Merged

spydon merged 3 commits into
mainfrom
lukasklingsbo/sdk-2814-realtime-access-tokens-are-written-to-debug-logs

Conversation

@spydon

@spydon spydon commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

What

With debug logging on, realtime wrote the user's JWT and API key to the logs in two places:

  • RealtimeClient._send and _send_no_wait logged every outgoing frame in full, including the access_token in join payloads and in the access_token events that set_auth sends on every heartbeat.
  • The websockets library logs the handshake request line (> GET /realtime/v1/websocket?vsn=2.0.0&apikey=... HTTP/1.1) and every frame it sends, so the token leaked through the websockets.client logger as well.

The v2 fix (#1750) never reached v3. This is the small security fix that lands before the logging rework in SDK-2721.

How

  • New private module realtime/_redact.py. Its redact function replaces apikey= query values (case insensitive) and access_token values (JSON, dict repr and keyword repr forms) with <redacted>.
  • RedactingLoggerAdapter redacts the message, string arguments and websockets frames before they are formatted, so the token is removed even when WEBSOCKETS_MAX_LOG_SIZE is raised and frames are logged in full. Frames that contain no secret are passed through untouched. It bumps stacklevel so records still point at the code that logged them, not at the adapter.
  • The realtime.client logger is wrapped in the adapter, which covers the sending: frame logs and every other log line in the module.
  • connect_once passes an adapter around the websockets.client logger to websockets.connect. The logger names are unchanged, so existing logging configuration keeps working.
  • .sdk-parse-ignore excludes _redact.py from the capability matrix check, since it is internal and not public API.

Tests

tests/test_log_redaction.py connects to a local WebSocket server with debug logging on, with both the default and full length frame logging, subscribes a channel, calls set_auth, subscribes a second channel, and asserts that neither the URL token nor the refreshed token appears in any client log line. It also asserts that no record is attributed to the adapter. It fails without this change. A parametrized test covers redact directly.

Linear: SDK-2814

@coderabbitai

coderabbitai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 13 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 8 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3183ee49-7b4f-40ff-a81d-8f3382340a6f
Commits

Reviewing files that changed from the base of the PR and between c2056b5 and a9d6107.

Files selected for processing: 4

  • .sdk-parse-ignore
  • src/realtime/src/realtime/_redact.py
  • src/realtime/src/realtime/client.py
  • src/realtime/tests/test_log_redaction.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@spydon
spydon merged commit 2b20207 into main Nov 5, 2026
59 checks passed
@spydon
spydon deleted the lukasklingsbo/sdk-2814-realtime-access-tokens-are-written-to-debug-logs branch November 5, 2026 12:24
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