Skip to content

Commit d895ac1

Browse files
authored
Merge pull request #337 from gosuda/fix/loopback-http-portal-url
fix(utils): accept loopback http relay URLs
2 parents 39ede6c + 1ebdbd2 commit d895ac1

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

utils/relayurl_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package utils
2+
3+
import "testing"
4+
5+
func TestNormalizeRelayURLRewritesLoopbackHTTP(t *testing.T) {
6+
t.Parallel()
7+
8+
got, err := NormalizeRelayURL("http://127.0.0.1:14017")
9+
if err != nil {
10+
t.Fatalf("NormalizeRelayURL(loopback http) error = %v", err)
11+
}
12+
if got != "https://127.0.0.1:14017" {
13+
t.Fatalf("NormalizeRelayURL(loopback http) = %q, want https://127.0.0.1:14017", got)
14+
}
15+
}
16+
17+
func TestNormalizeRelayURLRejectsNonLoopbackHTTP(t *testing.T) {
18+
t.Parallel()
19+
20+
_, err := NormalizeRelayURL("http://relay.example")
21+
if err == nil {
22+
t.Fatal("NormalizeRelayURL(non-loopback http) error = nil, want https required")
23+
}
24+
}

utils/utils.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ func NormalizeRelayURL(raw string) (string, error) {
158158
if parsed.Host == "" {
159159
return "", fmt.Errorf("relay url host is empty: %q", raw)
160160
}
161+
if strings.EqualFold(parsed.Scheme, "http") && IsLocalRelayHost(parsed.Hostname()) {
162+
parsed.Scheme = "https"
163+
}
161164
if !strings.EqualFold(parsed.Scheme, "https") {
162165
return "", fmt.Errorf("relay url must use https: %q", raw)
163166
}

0 commit comments

Comments
 (0)