mirror of
https://github.com/tailscale/tailscale.git
synced 2025-12-23 17:16:29 +00:00
ipn/localapi: use constant-time comparison for RequiredPassword (#17906)
Updates #cleanup Signed-off-by: Andrew Lytvynov <awly@tailscale.com>
This commit is contained in:
@@ -7,6 +7,7 @@ package localapi
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"cmp"
|
"cmp"
|
||||||
|
"crypto/subtle"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -257,7 +258,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
http.Error(w, "auth required", http.StatusUnauthorized)
|
http.Error(w, "auth required", http.StatusUnauthorized)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if pass != h.RequiredPassword {
|
if subtle.ConstantTimeCompare([]byte(pass), []byte(h.RequiredPassword)) == 0 {
|
||||||
metricInvalidRequests.Add(1)
|
metricInvalidRequests.Add(1)
|
||||||
http.Error(w, "bad password", http.StatusForbidden)
|
http.Error(w, "bad password", http.StatusForbidden)
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user