diff options
author | Jakob Borg <jakob@kastelo.net> | 2023-10-02 08:40:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-02 08:40:03 +0200 |
commit | 296db314f5c89057b92e617dd1b5459aa4effb3f (patch) | |
tree | e8182367028eda7855a5778f86f038fce36a8768 | |
parent | a8486b0468395adf1ba718009812cf735b91c083 (diff) |
lib/config: Improve parsing of gui-address overrides (#9144)
improve parsing of gui-address overrides
make checks for whether the gui-address is overridden consistent by
checking whether the environment variable is set and not an empty
string. the `Network()` function however checked for the inclusion of
a slash instead of the presence of any characters. If the config file's
gui address was set to a unix socket and the gui override to a tcp
address, then the function would have wrongly returned "unix".
the `URL()` function always returned the config file's gui address if a
unix socket was configured, even if an override was specified.
the `URL()` function wrongly formatted unix addresses. the http(s)
protocol was used as the sheme and the path was percent escaped. because
of the previous bug, this could only be triggered if the config file's
gui address was tcp and an unix socket override was given.
simplify the `useTLS()` function's codepath for overrides.
Co-authored-by: digital <didev@dinid.net>
-rw-r--r-- | lib/config/guiconfiguration.go | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/lib/config/guiconfiguration.go b/lib/config/guiconfiguration.go index 9f5df227ff..77832a3498 100644 --- a/lib/config/guiconfiguration.go +++ b/lib/config/guiconfiguration.go @@ -60,14 +60,12 @@ func (c GUIConfiguration) UnixSocketPermissions() os.FileMode { } func (c GUIConfiguration) Network() string { - if override := os.Getenv("STGUIADDRESS"); strings.Contains(override, "/") { + if override := os.Getenv("STGUIADDRESS"); override != "" { url, err := url.Parse(override) - if err != nil { - return "tcp" - } - if strings.HasPrefix(url.Scheme, "unix") { + if err == nil && strings.HasPrefix(url.Scheme, "unix") { return "unix" } + return "tcp" } if strings.HasPrefix(c.RawAddress, "/") { return "unix" @@ -77,19 +75,17 @@ func (c GUIConfiguration) Network() string { func (c GUIConfiguration) UseTLS() bool { if override := os.Getenv("STGUIADDRESS"); override != "" { - if strings.HasPrefix(override, "http") { - return strings.HasPrefix(override, "https:") - } - if strings.HasPrefix(override, "unix") { - return strings.HasPrefix(override, "unixs:") - } + return strings.HasPrefix(override, "https:") || strings.HasPrefix(override, "unixs:") } return c.RawUseTLS } func (c GUIConfiguration) URL() string { - if strings.HasPrefix(c.RawAddress, "/") { - return "unix://" + c.RawAddress + if c.Network() == "unix" { + if c.UseTLS() { + return "unixs://" + c.Address() + } + return "unix://" + c.Address() } u := url.URL{ |