Repository navigation
Conversation
sgzrov
force-pushed
the
fix/separate-logging-extras
branch
2 times, most recently
from
October 31, 2026 06:58
88a865e to
d22b42b
Compare
The WebSocket connection extras do two jobs: they are passed to handshake validation (so an app can authenticate from the upgrade headers, see replit#406) and they are attached to every log line for the connection (since replit#246). The default extras contain the upgrade headers, so a client's session cookie or bearer token was written to the server logs. Give WebSocketConnection a separate loggingExtras value that is the only thing attached to log metadata: a copy of the extras with the cookie, authorization, and proxy-authorization headers replaced by [redacted], computed once in the constructor. The extras themselves are untouched, so validation still sees the real headers. No signature changes. Adds a test in ws.test.ts for both halves and a README note.
sgzrov
force-pushed
the
fix/separate-logging-extras
branch
from
October 31, 2026 07:07
d22b42b to
4cdd9c2
Compare
2 tasks
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Session cookies and bearer tokens end up in server logs.
WebSocketServerTransportstores each connection's upgrade headers inconnection.extras, andWebSocketConnection.loggingMetadataattaches those extras to every log line for the connection (added in #246 so headers are visible in logs). The headers are only filtered forsec-*, socookieandauthorizationare logged as-is. This has been the case since #246.The obvious fix, dropping those headers from the extras, breaks something else: #406 passes the same extras to handshake validation so an app can authenticate from the upgrade headers, and it promised the default extras stay unchanged.
So the extras have to keep the real values, and only what gets logged can change. This PR does exactly that: the connection keeps
extrasas-is for validation and gets a separateloggingExtras, a copy with thecookie,authorization, andproxy-authorizationvalues replaced by[redacted], and onlyloggingExtrasis attached to log lines.What changed
WebSocketConnectiongets a privateloggingExtrasvalue, andloggingMetadataattaches only that. The connection extras are never logged directly and are untouched for validation (transport/server.tsstill passessession.conn.extrasat both validation sites).loggingExtrasis computed once in theWebSocketConnectionconstructor: a copy of the extras with thecookie,authorization, andproxy-authorizationheader values (the credential request headers per the Fetch spec) replaced by[redacted], every other key unchanged. Aheadersvalue that is not a plain object is passed through as-is. Every caller constructing aWebSocketConnectiongets this; no signature changes.WebSocketServerTransportis unchanged.ws.test.ts, next to the Expose WebSocket upgrade context to handshake validation #406 test (details under Tests).Caddy takes the same approach: its log marshaler redacts these headers while the request headers stay intact.
Versioning
No protocol or API change. The one behavior change is in the default log output:
cookie,authorization, andproxy-authorizationvalues now show[redacted]. Anyone correlating logs by those values loses that; all other headers are still logged, as in #246.Tests
Ran locally on Node 22.16.0, on top of
main(b154136):npm run test:single): 816 passed, 1 skipped, across 37 files. Cleanmainis 815 passed.npm run checkpasses: TypeScript, Prettier, and ESLint.transport/impls/ws/ws.test.ts: a client connects withcookie,authorization, anduser-agentupgrade headers. The handshake validator receives the real values throughconnectionExtras, the connection's log metadata shows[redacted]for the two credential headers and keepsuser-agent, andconn.extrasis untouched.connection.tsreverted tomain, the new test fails with the real cookie in log metadata; the existing Expose WebSocket upgrade context to handshake validation #406 test keeps passing both ways.Scope
cookie,authorization, andproxy-authorizationare redacted. Any other header, and any other key in custom extras, is logged as before.