mirror of
https://github.com/J3vb/OwnCord.git
synced 2026-09-03 03:50:00 +03:00
nhooyr.io/websocket now resolves to github.com/nhooyr/websocket-old and its README is a one-line deprecation pointing at coder/websocket. Its last three releases (v1.8.15-17) all shipped on 2024-08-10 as the redirect; the fork has shipped through 2026-06-15. The version number decreases (v1.8.17 -> v1.8.15) because both paths tagged in the same space, but the coder release is ~2 years newer. Import path only; the 9 API symbols used are unchanged. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
37 lines
1.3 KiB
Go
37 lines
1.3 KiB
Go
package ws
|
|
|
|
import (
|
|
"log/slog"
|
|
|
|
"github.com/coder/websocket"
|
|
)
|
|
|
|
// OriginAcceptOptions builds a *websocket.AcceptOptions that enforces origin
|
|
// checking according to the provided allowed-origins list.
|
|
//
|
|
// Rules:
|
|
// - nil or empty list → InsecureSkipVerify = false (deny all cross-origin; safe default)
|
|
// - list contains "*" → InsecureSkipVerify = true (explicit opt-in for any origin)
|
|
// - any other list → OriginPatterns set to the list; origin checking active
|
|
//
|
|
// The Tauri desktop client uses a Rust WS proxy that does not send an Origin
|
|
// header, so the default deny-all does not block desktop connections.
|
|
// Set allowed_origins: ["*"] in config to explicitly allow any origin.
|
|
func OriginAcceptOptions(allowedOrigins []string) *websocket.AcceptOptions {
|
|
if len(allowedOrigins) == 0 {
|
|
slog.Info("ws: no allowed_origins configured — denying cross-origin connections (safe default)")
|
|
return &websocket.AcceptOptions{InsecureSkipVerify: false}
|
|
}
|
|
|
|
for _, o := range allowedOrigins {
|
|
if o == "*" {
|
|
slog.Warn("ws: allowed_origins contains wildcard '*' — accepting connections from ANY origin (insecure)")
|
|
return &websocket.AcceptOptions{InsecureSkipVerify: true}
|
|
}
|
|
}
|
|
|
|
return &websocket.AcceptOptions{
|
|
OriginPatterns: allowedOrigins,
|
|
}
|
|
}
|