fix: validate maintenance profiles and canonical local auth origins
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -713,7 +714,7 @@ func parseConfigure(args []string) (configureRequest, error) {
|
||||
*target, args = args[0], args[1:]
|
||||
seen[option] = true
|
||||
}
|
||||
if request.mode != "local" && request.mode != "oidc" || !validPublicURL(request.publicURL) {
|
||||
if request.mode != "local" && request.mode != "oidc" || !ValidPublicURL(request.publicURL) {
|
||||
return configureRequest{}, errCommandRefused
|
||||
}
|
||||
if request.mode == "local" {
|
||||
@@ -1173,9 +1174,19 @@ func rolesToStrings(roles []Role) []string {
|
||||
return values
|
||||
}
|
||||
|
||||
func validPublicURL(value string) bool {
|
||||
// ValidPublicURL follows the backend policy: HTTP requires canonical literal loopback.
|
||||
func ValidPublicURL(value string) bool {
|
||||
parsed, err := url.Parse(value)
|
||||
return err == nil && (parsed.Scheme == "http" || parsed.Scheme == "https") && parsed.Host != "" && parsed.User == nil && parsed.Path == "" && parsed.RawQuery == "" && parsed.Fragment == ""
|
||||
if err != nil || parsed.Host == "" || parsed.User != nil || (parsed.Path != "" && parsed.Path != "/") || parsed.RawQuery != "" || parsed.Fragment != "" {
|
||||
return false
|
||||
}
|
||||
if port := parsed.Port(); port != "" {
|
||||
n, err := strconv.Atoi(port)
|
||||
if err != nil || n < 0 || n > 65535 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return parsed.Scheme == "https" || parsed.Scheme == "http" && isLoopbackURL(value)
|
||||
}
|
||||
|
||||
func validOIDCURL(value string) bool {
|
||||
@@ -1191,10 +1202,28 @@ func isHTTPS(value string) bool {
|
||||
return err == nil && parsed.Scheme == "https"
|
||||
}
|
||||
func isLoopbackURL(value string) bool {
|
||||
if !strings.HasPrefix(value, "http://") {
|
||||
return false
|
||||
}
|
||||
parsed, err := url.Parse(value)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
host := parsed.Hostname()
|
||||
return host == "localhost" || net.ParseIP(host) != nil && net.ParseIP(host).IsLoopback()
|
||||
ip := net.ParseIP(host)
|
||||
if ip == nil || !ip.IsLoopback() || ip.String() != host {
|
||||
return false
|
||||
}
|
||||
authority := host
|
||||
if strings.Contains(host, ":") {
|
||||
authority = "[" + host + "]"
|
||||
}
|
||||
if port := parsed.Port(); port != "" {
|
||||
n, err := strconv.Atoi(port)
|
||||
if err != nil || n < 0 || n > 65535 || strconv.Itoa(n) != port {
|
||||
return false
|
||||
}
|
||||
authority += ":" + port
|
||||
}
|
||||
return parsed.Host == authority
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user