Fix WebSocket 403 in dev mode by allowing localhost origins
Some checks failed
Deploy with Docker Compose / deploy (push) Has been cancelled
Some checks failed
Deploy with Docker Compose / deploy (push) Has been cancelled
The CheckOrigin function only accepted the production domain, rejecting localhost connections in dev. Also removed redundant error response after a failed upgrade since the upgrader already writes its own HTTP response. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
||||
func (store *Store) ConnectWebSocket(ctx *gin.Context) {
|
||||
conn, err := services.Upgrader.Upgrade(ctx.Writer, ctx.Request, nil)
|
||||
if err != nil {
|
||||
ctx.JSON(500, gin.H{"error": err.Error()})
|
||||
// Upgrader already wrote the HTTP error response, so just return
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,9 @@ var Upgrader = websocket.Upgrader{
|
||||
}
|
||||
origin = strings.TrimPrefix(origin, "https://")
|
||||
origin = strings.TrimPrefix(origin, "http://")
|
||||
return origin == allowedDomain || origin == "www."+allowedDomain
|
||||
// Strip port for localhost comparisons (e.g. "localhost:80")
|
||||
host := strings.Split(origin, ":")[0]
|
||||
return origin == allowedDomain || origin == "www."+allowedDomain || host == "localhost"
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user