Repository navigation
ws: carry auth token in Sec-WebSocket-Protocol instead of the URL - #281
Merged
Merged
Conversation
📝 WalkthroughWalkthroughWebSocket authentication is encoded into a negotiated ChangesWebSocket authentication
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant WsTransportClient
participant WsTransportServer
participant matchWsAuthSubprotocol
participant onConnect
WsTransportClient->>WsTransportServer: WebSocket upgrade with encoded auth subprotocol
WsTransportServer->>matchWsAuthSubprotocol: Match Sec-WebSocket-Protocol
matchWsAuthSubprotocol-->>WsTransportServer: Decoded auth and selected subprotocol
WsTransportServer->>onConnect: Request containing decoded auth
onConnect-->>WsTransportServer: Accept connection
WsTransportServer-->>WsTransportClient: Echo selected subprotocol
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/protocol/src/common/ws.ts`:
- Around line 45-54: Update the auth decoding in the subprotocol parsing flow to
construct TextDecoder with UTF-8 fatal mode, so invalid byte sequences throw and
remain treated as foreign subprotocols by the existing catch. Add a regression
test covering malformed UTF-8 payload rejection.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: e45829af-1a9f-45bd-9442-522ba3700033
📒 Files selected for processing (8)
packages/protocol/src/common/index.tspackages/protocol/src/common/ws.tspackages/protocol/tests/common/ws.spec.tspackages/ws-client/src/index.tspackages/ws-client/tests/client.spec.tspackages/ws-transport/src/server.tspackages/ws-transport/src/types.tspackages/ws-transport/tests/auth-upgrade.spec.ts
denny-il
force-pushed
the
dev/fix-214-ws-token-subprotocol
branch
from
July 17, 2026 09:55
738d455 to
867a135
Compare
denny-il
force-pushed
the
dev/fix-214-ws-token-subprotocol
branch
2 times, most recently
from
August 23, 2026 12:03
c3ade35 to
7f751c7
Compare
denny-il
force-pushed
the
dev/fix-214-ws-token-subprotocol
branch
from
August 23, 2026 12:22
7f751c7 to
52f5ba3
Compare
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.
Closes #214 — the CORS and request-body items landed separately; this PR addresses the remaining WebSocket token leak against the current consolidated transport architecture.
What changed
packages/client/src/transports/wssends auth only as a strictnmt.auth.<base64url>WebSocket subprotocol, so tokens never appear in connection URLs.packages/protocolprovides the shared encoder/matcher. Decoding is fatal UTF-8 and preserves a leading BOM, avoiding lossy credential normalization.packages/transports/src/neemata/wsextracts the auth offer, echoes the exact selected subprotocol, and keepsconnectionDataas the standardRequestcontract.connectionData.headers.get('authorization'), matching the existing HTTP Request convention without a custom request type or service.Verification
pnpm run fmtpnpm run check