harden websocket CheckOrigin
This commit is contained in:
parent
e2a9bb97c7
commit
16d717884d
2 changed files with 14 additions and 3 deletions
|
|
@ -5,6 +5,7 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
|
@ -73,10 +74,19 @@ func NewPicoChannel(cfg config.PicoConfig, messageBus *bus.MessageBus) (*PicoCha
|
|||
|
||||
allowOrigins := cfg.AllowOrigins
|
||||
checkOrigin := func(r *http.Request) bool {
|
||||
if len(allowOrigins) == 0 {
|
||||
return true // allow all if not configured
|
||||
}
|
||||
origin := r.Header.Get("Origin")
|
||||
// If no origins are configured, allow same-origin only (default Gorilla behavior).
|
||||
if len(allowOrigins) == 0 {
|
||||
if origin == "" {
|
||||
return true
|
||||
}
|
||||
u, err := url.Parse(origin)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return u.Host == r.Host
|
||||
}
|
||||
// If origins are configured, check for '*' or exact match.
|
||||
for _, allowed := range allowOrigins {
|
||||
if allowed == "*" || allowed == origin {
|
||||
return true
|
||||
|
|
|
|||
1
semgrep-results-owasp.json
Normal file
1
semgrep-results-owasp.json
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Reference in a new issue