-
Notifications
You must be signed in to change notification settings - Fork 358
Added Cap'n Web Sample #154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| console.log('Initializing Cap\'n Web connection...'); | ||
|
|
||
| // Create WebSocket connection | ||
| const wsUrl = `ws://${window.location.host}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we using ws:// unconditionally? Could it be replaced with the following approach?
Choose protocol based on window.location.protocol, e.g.:
const wsProtocol = window.location.protocol === 'https:' ? 'wss' : 'ws';
const wsUrl = ${wsProtocol}://${window.location.host};
As browsers might block the connection on secure origins and the RPC client might fail.
| const config = { | ||
| auth0: { | ||
| domain: AUTH0_DOMAIN, | ||
| clientId: process.env.AUTH0_CLIENT_ID, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Problem:
/api/config may return a 500 when AUTH0_CLIENT_ID is missing because startup only validates AUTH0_DOMAIN/AUDIENCE.
Possible Fix:
By Failing fast on startup (or return a clear JSON error).
Add AUTH0_CLIENT_ID validation at boot so the server never runs with an incomplete public config.
| server, | ||
| verifyClient: (info) => { | ||
| console.log('WebSocket connection request from:', info.origin); | ||
| return true; // Allow all connections for development |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Problem: verifyClient returns true for all origins/connections. Accepting all WS connections without initial authentication could be insecure.
This should be okay for demo, but for production, tighter handshake should be implemented (validate Origin and or require an Authorization token during the WebSocket upgrade or as the first RPC "authenticate" call), rejecting unauthorized upgrade attempts. As leaving the upgrade open is a security risk.
| id: message.id, | ||
| result: result | ||
| })); | ||
| } catch (error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not send raw internal error messages back to clients over WebSocket. As the server forwards error.message directly to the client. This can leak internal details (stack traces, validation internals).
We should sanitize error responses sent to clients. Send a safe, minimal message (e.g., "Invalid request" or "Invalid access token") and log full error details server-side for debugging. This should prevent leaking sensitive server internals and improve security posture.
Added a Cap'n Web Sample to feature on an upcoming blog post.
More info: