Skip to content

Fix Electron CSP blocking websocket connections#410

Merged
ravjotbrar merged 1 commit into
mainfrom
fix/csp-self
Jul 23, 2026
Merged

Fix Electron CSP blocking websocket connections#410
ravjotbrar merged 1 commit into
mainfrom
fix/csp-self

Conversation

@ravjotbrar

Copy link
Copy Markdown
Collaborator

Description

The onHeadersReceived CSP in electron.main.js had connect-src 'self' which overrides the permissive meta tag in index.html. When both are present, the browser enforces the intersection (most restrictive). Add ws://localhost:* and http://localhost:* to match the meta tag.

Change Visualization

Include a screenshot/video of before and after the change.

Signed-off-by: ravjotb <ravjot.brar@improving.com>
"default-src 'self'; script-src 'self'; " +
"style-src 'self' 'unsafe-inline'; " +
"connect-src 'self'; " +
"connect-src 'self' ws://localhost:* http://localhost:*; " +

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there the ability to scope to specific ports, not all?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately not, due to the user having the ability to override the main server's default port, which is 8080.

"default-src 'self'; script-src 'self'; " +
"style-src 'self' 'unsafe-inline'; " +
"connect-src 'self'; " +
"connect-src 'self' ws://localhost:* http://localhost:*; " +

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we need to keep it consistent. - https://github.com/valkey-io/valkey-admin/blob/main/apps/frontend/index.html . Would it be better to add a small comment cross-referencing them?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably actually remove this one and keep the meta tag in index.html. Will do in a future PR to avoid any big changes before the release.

@alexey-temnikov alexey-temnikov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with few questions.

@ravjotbrar
ravjotbrar merged commit 2a8b7cd into main Jul 23, 2026
8 checks passed
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.

2 participants