From 65cd447a61efa852da2c0e7db25f385c2436e236 Mon Sep 17 00:00:00 2001 From: Martin Kraft Date: Mon, 30 Jul 2018 14:59:08 -0400 Subject: MM-11301: Validates listen address config value. (#9138) * MM-11301: Validates listen address config value. * MM-11301: Adds some invalid port test cases. * MM-11301: Accept domain names. * MM-11301: Fix for max port. --- model/config.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'model/config.go') diff --git a/model/config.go b/model/config.go index 1d0f40901..aa7900279 100644 --- a/model/config.go +++ b/model/config.go @@ -6,9 +6,12 @@ package model import ( "encoding/json" "io" + "math" + "net" "net/http" "net/url" "regexp" + "strconv" "strings" "time" ) @@ -2352,7 +2355,15 @@ func (ss *ServiceSettings) isValid() *AppError { } } - if len(*ss.ListenAddress) == 0 { + host, port, err := net.SplitHostPort(*ss.ListenAddress) + var isValidHost bool + if host == "" { + isValidHost = true + } else { + isValidHost = (net.ParseIP(host) != nil) || IsDomainName(host) + } + portInt, err := strconv.Atoi(port) + if err != nil || !isValidHost || portInt < 0 || portInt > math.MaxUint16 { return NewAppError("Config.IsValid", "model.config.is_valid.listen_address.app_error", nil, "", http.StatusBadRequest) } -- cgit v1.2.3-1-g7c22