From cbe9a0bffd591e7e8a0f7ec2849e3a437b0d03c1 Mon Sep 17 00:00:00 2001 From: Flow Mind Date: Tue, 5 May 2026 11:03:06 +0300 Subject: [PATCH] sec: constant-time admin token compare Direct == on admin token leaks length-bytes via timing channel. Replace with subtle.ConstantTimeCompare. Pre-prod hardening for multi-tenant deploy where admin token grants user-creation rights. --- handlers.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/handlers.go b/handlers.go index 338e7fcd..a7771986 100644 --- a/handlers.go +++ b/handlers.go @@ -3,6 +3,7 @@ package main import ( "bytes" "context" + "crypto/subtle" "database/sql" "encoding/base64" "encoding/json" @@ -124,7 +125,8 @@ func (s *server) GetHealth() http.HandlerFunc { func (s *server) authadmin(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { token := r.Header.Get("Authorization") - if token != *adminToken { + // Constant-time compare to avoid timing-attack leak of admin token bytes. + if subtle.ConstantTimeCompare([]byte(token), []byte(*adminToken)) != 1 { s.Respond(w, r, http.StatusUnauthorized, errors.New("unauthorized")) return }