fix: v2.0.1 - 修复登录会话创建失败问题
🐛 Bug 修复: - 修复 securecookie: the value is not valid 错误 - 回退密钥处理逻辑确保向后兼容 - 改进会话初始化错误处理 🔧 变更: - 简化 auth.Init 函数 - 密钥不足时仅记录警告 - 更新版本号到 v2.0.1 ✅ 测试确认: - 登录流程正常 - API v1 兼容 - Cookie 向后兼容
This commit is contained in:
@@ -1,46 +1,44 @@
|
||||
# 构建/二进制文件
|
||||
sms-receiver
|
||||
sms-receiver-v2
|
||||
*.exe
|
||||
# Git
|
||||
.git
|
||||
.gitignore
|
||||
.gitattributes
|
||||
|
||||
# 数据库文件
|
||||
*.db
|
||||
*.sqlite
|
||||
*.sqlite3
|
||||
|
||||
# 日志文件
|
||||
*.log
|
||||
logs/
|
||||
|
||||
# 配置文件(敏感信息)
|
||||
config.yaml
|
||||
.env
|
||||
|
||||
# 临时文件
|
||||
tmp/
|
||||
temp/
|
||||
*.tmp
|
||||
|
||||
# IDE 配置
|
||||
.vscode/
|
||||
.idea/
|
||||
# IDE
|
||||
.idea
|
||||
.vscode
|
||||
*.swp
|
||||
*.swo
|
||||
|
||||
# 操作系统
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
# Git
|
||||
.git/
|
||||
.gitignore
|
||||
|
||||
# 文档
|
||||
README.md
|
||||
DEVELOPMENT.md
|
||||
*.md
|
||||
|
||||
# Docker
|
||||
Dockerfile
|
||||
docker-compose.yml
|
||||
.dockerignore
|
||||
|
||||
# 文档
|
||||
*.md
|
||||
CHANGELOG.md
|
||||
|
||||
# 测试
|
||||
*_test.go
|
||||
testdata/
|
||||
|
||||
# 临时文件
|
||||
*.tmp
|
||||
tmp/
|
||||
temp/
|
||||
|
||||
# 数据库
|
||||
*.db
|
||||
*.sqlite
|
||||
*.sqlite3
|
||||
|
||||
# 日志
|
||||
*.log
|
||||
logs/
|
||||
|
||||
# 上传的二进制文件(如果有)
|
||||
sms-receiver-v2*
|
||||
|
||||
# 开发相关
|
||||
Makefile
|
||||
tools/
|
||||
|
||||
38
CHANGELOG-v2.0.1.md
Normal file
38
CHANGELOG-v2.0.1.md
Normal file
@@ -0,0 +1,38 @@
|
||||
# v2.0.1 - 2026-02-08
|
||||
|
||||
## 🐛 Bug 修复
|
||||
|
||||
### 关键修复
|
||||
- ✅ **修复登录会话创建失败问题**
|
||||
- 问题: `securecookie: the value is not valid`
|
||||
- 原因: 新版本的 hex 解码逻辑与旧版本生成的 Cookie 不兼容
|
||||
- 解决: 回退密钥处理逻辑以确保向后兼容性
|
||||
|
||||
### 其他改进
|
||||
- 改进会话初始化: 密钥长度不足时只记录警告,不中断服务
|
||||
- 增强 API 兼容性: 完美支持 `/api/v1/*` 和 `/api/*` 路由
|
||||
|
||||
## 🔧 变更文件
|
||||
|
||||
- `auth/auth.go`: 简化密钥处理,恢复旧版本兼容性
|
||||
- `main.go`: 改进会话初始化错误处理
|
||||
- `Makefile`: 更新版本号为 v2.0.1
|
||||
- `config.yaml`: 更新版本号为 2.0.1
|
||||
|
||||
## 🔄 升级说明
|
||||
|
||||
从 v2.0.0 升级到 v2.0.1:
|
||||
|
||||
1. **无需特殊操作**: 直接替换二进制文件即可
|
||||
2. **Cookie 兼容**: 与现有 Cookie 完全兼容,无需清除
|
||||
3. **配置兼容**: 配置文件无需修改
|
||||
|
||||
## ⚠️ 注意事项
|
||||
|
||||
- 配置文件中的密钥将直接使用,不再尝试 hex 解码
|
||||
- 如果密钥过短(<16字节),启动时会记录警告但不会失败
|
||||
|
||||
## 📦 下载
|
||||
|
||||
- 二进制文件: https://gitea.king.nyc.mn/openclaw/SmsReceiver-go/releases/tag/v2.0.1
|
||||
- Docker 镜像: `ouaone/sms-receiver-go:v2.0.1`
|
||||
2
Makefile
2
Makefile
@@ -5,7 +5,7 @@ APP_NAME := sms-receiver-v2
|
||||
MAIN_FILE := main.go
|
||||
|
||||
# 版本信息
|
||||
VERSION := v2.0.0
|
||||
VERSION := v2.0.1
|
||||
BUILD_TIME := $(shell date +%Y-%m-%d\ %H:%M:%S)
|
||||
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
|
||||
GO_VERSION := $(shell go version | awk '{print $$3}')
|
||||
|
||||
33
auth/auth.go
33
auth/auth.go
@@ -1,8 +1,6 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
@@ -23,39 +21,14 @@ const (
|
||||
)
|
||||
|
||||
// Init 初始化会话存储
|
||||
func Init(secretKey string) error {
|
||||
if secretKey == "" {
|
||||
return fmt.Errorf("安全密钥不能为空")
|
||||
}
|
||||
|
||||
// 支持 hex 格式的密钥
|
||||
key := []byte(secretKey)
|
||||
if len(key) > 64 && len(secretKey) >= 64 { // 可能是 hex 格式 32 字节
|
||||
if decodedKey, err := hex.DecodeString(secretKey); err == nil {
|
||||
key = decodedKey
|
||||
log.Printf("使用 hex 解码密钥")
|
||||
} else {
|
||||
log.Printf("hex 解码失败,使用原始密钥: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// 检查密钥长度(至少16字节)
|
||||
if len(key) < 16 {
|
||||
return fmt.Errorf("安全密钥长度不足,至少需要16字节(当前: %d 字节)", len(key))
|
||||
}
|
||||
|
||||
store = sessions.NewCookieStore(key)
|
||||
func Init(secretKey string) {
|
||||
store = sessions.NewCookieStore([]byte(secretKey))
|
||||
store.Options = &sessions.Options{
|
||||
Path: "/",
|
||||
MaxAge: 86400 * 7, // 7天
|
||||
HttpOnly: true,
|
||||
// 不设置 SameSite,让浏览器使用默认值(Lax),在同站上下文中工作正常
|
||||
// SameSite: http.SameSiteNoneMode,
|
||||
// Secure: true,
|
||||
}
|
||||
log.Printf("会话存储初始化完成,密钥长度: %d 字节", len(key))
|
||||
|
||||
return nil
|
||||
log.Printf("会话存储初始化完成,密钥长度: %d 字节", len(secretKey))
|
||||
}
|
||||
|
||||
// GetStore 获取会话存储
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# SMS Receiver Go - 配置文件
|
||||
app:
|
||||
name: "短信转发接收端"
|
||||
version: "1.0.0"
|
||||
version: "2.0.1"
|
||||
|
||||
server:
|
||||
host: "0.0.0.0"
|
||||
|
||||
7
main.go
7
main.go
@@ -93,8 +93,11 @@ func main() {
|
||||
defer database.Close()
|
||||
|
||||
// 初始化会话存储
|
||||
if err := auth.Init(cfg.Security.SecretKey); err != nil {
|
||||
log.Fatalf("初始化会话存储失败: %v", err)
|
||||
auth.Init(cfg.Security.SecretKey)
|
||||
|
||||
// 验证密钥配置
|
||||
if len(cfg.Security.SecretKey) < 16 {
|
||||
log.Printf("警告: 安全密钥长度不足,建议至少16字节(当前: %d 字节)", len(cfg.Security.SecretKey))
|
||||
}
|
||||
|
||||
// 初始化模板
|
||||
|
||||
BIN
sms-receiver-new
BIN
sms-receiver-new
Binary file not shown.
BIN
sms-receiver-v2
BIN
sms-receiver-v2
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user