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.
Этот коммит содержится в:
Martin Kraft
2018-07-30 14:59:08 -04:00
коммит произвёл GitHub
родитель d23ca07133
Коммит 65cd447a61
3 изменённых файлов: 108 добавлений и 1 удалений

Просмотреть файл

@@ -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)
}