-
Notifications
You must be signed in to change notification settings - Fork 704
security: add HTTP security headers to MindServer and bind browser viewer to localhost #717
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: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -48,7 +48,31 @@ export function logoutAgent(agentName) { | |||||||||||||||||||||||||||||||||||||||
| export function createMindServer(host_public = false, port = 8080) { | ||||||||||||||||||||||||||||||||||||||||
| const app = express(); | ||||||||||||||||||||||||||||||||||||||||
| server = http.createServer(app); | ||||||||||||||||||||||||||||||||||||||||
| io = new Server(server); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| // Determine allowed origins for CORS / Socket.IO | ||||||||||||||||||||||||||||||||||||||||
| const allowedOrigins = host_public | ||||||||||||||||||||||||||||||||||||||||
| ? undefined // allow any when explicitly public (Docker/EC2) | ||||||||||||||||||||||||||||||||||||||||
| : [`http://localhost:${port}`, `http://127.0.0.1:${port}`]; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| io = new Server(server, { | ||||||||||||||||||||||||||||||||||||||||
| cors: { | ||||||||||||||||||||||||||||||||||||||||
| origin: allowedOrigins, | ||||||||||||||||||||||||||||||||||||||||
| methods: ['GET', 'POST'], | ||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+54
to
+61
|
||||||||||||||||||||||||||||||||||||||||
| ? undefined // allow any when explicitly public (Docker/EC2) | |
| : [`http://localhost:${port}`, `http://127.0.0.1:${port}`]; | |
| io = new Server(server, { | |
| cors: { | |
| origin: allowedOrigins, | |
| methods: ['GET', 'POST'], | |
| }, | |
| ? undefined // legacy behavior: previously relied on origin: undefined | |
| : [`http://localhost:${port}`, `http://127.0.0.1:${port}`]; | |
| const corsOptions = host_public | |
| // Explicitly allow any origin when running in public mode | |
| ? { origin: true, methods: ['GET', 'POST'] } | |
| // Restrict origins to local development URLs when not public | |
| : { origin: allowedOrigins, methods: ['GET', 'POST'] }; | |
| io = new Server(server, { | |
| cors: corsOptions, |
Copilot
AI
Mar 3, 2026
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.
The CSP connect-src 'self' ws: wss: allows WebSocket connections to any host over ws/wss (scheme-only sources), which largely defeats the intent of restricting connections to same-origin. If the UI only needs same-origin Socket.IO/WebSockets, remove ws:/wss: and rely on 'self'; otherwise, specify explicit websocket endpoints/hosts instead of allowing all.
| "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self' ws: wss:; font-src 'self';" | |
| "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self'; font-src 'self';" |
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.
Binding prismarine-viewer to 127.0.0.1 will make the viewer unreachable from outside the process namespace (e.g., typical Docker
-p/docker-compose port publishing won’t reach a service that only listens on loopback inside the container). Consider making the bind host configurable (e.g., default to localhost for non-container local dev, but allow 0.0.0.0 when explicitly requested) so existing container/remote viewing setups keep working while still enabling a secure default.