feat: add backend proxy layer to keep auth tokens server-side#1
Merged
feat: add backend proxy layer to keep auth tokens server-side#1
Conversation
Introduces a WebSocket proxy server (server/) that sits between the webchat widget and GoClaw Gateway, preventing auth token exposure in client-side JavaScript. - Proxy intercepts WS connect frame and injects gateway token - Widget updated with proxyUrl config option for proxy mode - Origin validation, per-IP rate limiting, TRUST_PROXY support - 512KB max frame size, message buffering, graceful shutdown - Example page and documentation updated
…ken leakage - Reject missing Origin header when allowedOrigins is configured - Cap pending message buffer to 10 messages (prevents memory DoS) - Add per-session message rate limiting (60 msgs/min sliding window) - Sanitize upstream responses to strip token fields (defense in depth)
…nt-side auth Removes direct mode entirely — the webchat widget now connects exclusively through the backend proxy, which keeps the gateway auth token server-side. Client never receives or sends the token. Changes: - Config: removed `token` and `proxyUrl` fields; renamed `proxyUrl` → `url` (required), `proxyApiKey` → `apiKey` (optional). - Client: removed token sending logic; proxy injects token at connection time. - Server: added optional API key validation for proxy endpoints. - Docs: rewrote README for proxy-only setup, removed direct mode examples. This hardens security by eliminating token exposure in client-side code and browser storage.
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.
Overview
Adds an optional backend proxy server that allows keeping GoClaw authentication tokens server-side, improving security for production deployments.
Changes
New Proxy Server (
server/)connectframes to inject auth tokens server-sidewsas sole production dependencyWidget Updates
src/types.tsto support newproxyUrlconfiguration optionsrc/websocket-client.tsto connect via proxy when configuredDocumentation & Examples
Security Benefits
Deployment
Architecture