ipn/localapi: use constant-time comparison for RequiredPassword (#17906)

Updates #cleanup

Signed-off-by: Andrew Lytvynov <awly@tailscale.com>
pull/17869/head
Andrew Lytvynov 3 weeks ago committed by GitHub
parent 9134440008
commit 888a5d4812
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -7,6 +7,7 @@ package localapi
import (
"bytes"
"cmp"
"crypto/subtle"
"encoding/json"
"errors"
"fmt"
@ -257,7 +258,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
http.Error(w, "auth required", http.StatusUnauthorized)
return
}
if pass != h.RequiredPassword {
if subtle.ConstantTimeCompare([]byte(pass), []byte(h.RequiredPassword)) == 0 {
metricInvalidRequests.Add(1)
http.Error(w, "bad password", http.StatusForbidden)
return

Loading…
Cancel
Save