fix: inject gateway token into WebSocket requests for CF Access users#176
Merged
sidharthachatterjee merged 1 commit intocloudflare:mainfrom Feb 6, 2026
Merged
Conversation
When Cloudflare Access is enabled, the authentication redirect strips query parameters from the URL. This causes authenticated users to lose the ?token= parameter, resulting in "disconnected (1008): Invalid or missing token" errors on the gateway dashboard. Since the user has already passed CF Access authentication at this point, the worker now injects MOLTBOT_GATEWAY_TOKEN into the WebSocket request server-side when the token parameter is missing. Fixes cloudflare#58
Collaborator
|
Thanks for this! |
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.
Summary
?token=parameterMOLTBOT_GATEWAY_TOKENinto WebSocket requests server-side when the token parameter is missingFixes #58
Details
The root cause: CF Access redirects (for login) strip query params from the original URL. So even if a user visits
https://example.com/?token=xxx, after CF Access authentication they land onhttps://example.com/without the token. The gateway dashboard's JavaScript then opens WebSocket connections without?token=, and the container gateway rejects them with1008: Invalid or missing token.The fix injects the gateway token at the Worker level before proxying the WebSocket to the container, only when:
MOLTBOT_GATEWAY_TOKENis configuredtokenquery paramTest plan
MOLTBOT_GATEWAY_TOKENset?token=in URL)