new: disabling api.rest authentication if username or password are empty

This commit is contained in:
evilsocket 2018-08-29 16:00:17 +03:00
parent 3b6ea499dd
commit f9656e1d1d
No known key found for this signature in database
GPG key ID: 1564D7F30393A456
2 changed files with 10 additions and 8 deletions

View file

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