feat: 添加安全中间件、优化限流器与API密钥验证
1. 新增安全响应头中间件强化请求安全性 2. 使用恒定时间比较修复API密钥验证时序漏洞 3. 新增限流器条目上限配置与自动清理逻辑 4. 优化CORS日志与客户端IP获取逻辑 5. 升级Go构建环境与基础镜像版本 6. 新增非root用户运行容器增强安全性
This commit is contained in:
+2
-1
@@ -1,6 +1,7 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"crypto/subtle"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
@@ -39,7 +40,7 @@ func ValidateAPIKey(r *http.Request) bool {
|
||||
|
||||
token := strings.TrimPrefix(authHeader, "Bearer ")
|
||||
for _, validKey := range validAPIKeys {
|
||||
if token == validKey {
|
||||
if subtle.ConstantTimeCompare([]byte(token), []byte(validKey)) == 1 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user