From ed0c0db6a3954416101affc1539b87983c230cc8 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Sun, 10 Jan 2016 20:51:50 -0700 Subject: [PATCH] If scheme and port defy convention, it is an error This prevents serving HTTPS over port 80 or HTTP over 443. It's confusing and we don't allow it. --- caddy/parse/parsing.go | 7 ++++++- caddy/parse/parsing_test.go | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/caddy/parse/parsing.go b/caddy/parse/parsing.go index 482d8428..b5294de5 100644 --- a/caddy/parse/parsing.go +++ b/caddy/parse/parsing.go @@ -338,7 +338,12 @@ func standardAddress(str string) (address, error) { // repeated or conflicting scheme is confusing, so error if scheme != "" && (port == "http" || port == "https") { - return address{}, fmt.Errorf("[%s] scheme specified twice in address", str) + return address{}, fmt.Errorf("[%s] scheme specified twice in address", input) + } + + // error if scheme and port combination violate convention + if (scheme == "http" && port == "443") || (scheme == "https" && port == "80") { + return address{}, fmt.Errorf("[%s] scheme and port violate convention", input) } // standardize http and https ports to their respective port numbers diff --git a/caddy/parse/parsing_test.go b/caddy/parse/parsing_test.go index 8533b2a3..462cd40f 100644 --- a/caddy/parse/parsing_test.go +++ b/caddy/parse/parsing_test.go @@ -27,6 +27,8 @@ func TestStandardAddress(t *testing.T) { {`:https`, "https", "", "443", false}, {`http://localhost:https`, "", "", "", true}, // conflict {`http://localhost:http`, "", "", "", true}, // repeated scheme + {`http://localhost:443`, "", "", "", true}, // not conventional + {`https://localhost:80`, "", "", "", true}, // not conventional {`http://localhost`, "http", "localhost", "80", false}, {`https://localhost`, "https", "localhost", "443", false}, {`http://127.0.0.1`, "http", "127.0.0.1", "80", false},