Skip to content

Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.

fix: use constant-time comparison for API key validation

Mao Menge3b493e3166c
diff --git a/internal/middleware/auth.go b/internal/middleware/auth.go
index e318b637b..15c7fcecc 100644
--- a/internal/middleware/auth.go
+++ b/internal/middleware/auth.go
@@ -2,6 +2,7 @@ package middleware
import (
"context"
+ "crypto/subtle"
"errors"
"fmt"
"log"
@@ -178,7 +179,7 @@ func Auth(
return
}
- if t == nil || t.APIKey != apiKey {
+ if t == nil || subtle.ConstantTimeCompare([]byte(t.APIKey), []byte(apiKey)) != 1 {
c.JSON(http.StatusUnauthorized, gin.H{
"error": "Unauthorized: invalid API key",
})