Skip to content

Conversation

@brth31
Copy link

@brth31 brth31 commented Oct 28, 2025

Added a Cap'n Web Sample to feature on an upcoming blog post.

More info:

console.log('Initializing Cap\'n Web connection...');

// Create WebSocket connection
const wsUrl = `ws://${window.location.host}`;
Copy link
Contributor

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,
Copy link
Contributor

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
Copy link
Contributor

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) {
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants