diff --git a/modules/api_rest.go b/modules/api_rest.go index 8b932f67..71845023 100644 --- a/modules/api_rest.go +++ b/modules/api_rest.go @@ -50,12 +50,12 @@ func NewRestAPI(s *session.Session) *RestAPI { api.AddParam(session.NewStringParameter("api.rest.username", "", - ".+", + "", "API authentication username.")) api.AddParam(session.NewStringParameter("api.rest.password", "", - ".+", + "", "API authentication password.")) api.AddParam(session.NewStringParameter("api.rest.certificate", diff --git a/modules/api_rest_controller.go b/modules/api_rest_controller.go index 8d0dd511..7c99e18f 100644 --- a/modules/api_rest_controller.go +++ b/modules/api_rest_controller.go @@ -43,12 +43,14 @@ func toJSON(w http.ResponseWriter, o interface{}) { } func (api *RestAPI) checkAuth(r *http.Request) bool { - user, pass, _ := r.BasicAuth() - // timing attack my ass - if subtle.ConstantTimeCompare([]byte(user), []byte(api.username)) != 1 { - return false - } else if subtle.ConstantTimeCompare([]byte(pass), []byte(api.password)) != 1 { - return false + if api.username != "" && api.password != "" { + user, pass, _ := r.BasicAuth() + // timing attack my ass + if subtle.ConstantTimeCompare([]byte(user), []byte(api.username)) != 1 { + return false + } else if subtle.ConstantTimeCompare([]byte(pass), []byte(api.password)) != 1 { + return false + } } return true }