mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-22 16:43:35 +00:00
Merge branch 'fix-authenticateUserOrAdmin-bypass'
This commit is contained in:
@@ -1434,7 +1434,6 @@ const authenticateAdmin = async (req, res, next) => {
|
|||||||
|
|
||||||
// 设置管理员信息(只包含必要信息)
|
// 设置管理员信息(只包含必要信息)
|
||||||
req.admin = {
|
req.admin = {
|
||||||
id: adminSession.adminId || 'admin',
|
|
||||||
username: adminSession.username,
|
username: adminSession.username,
|
||||||
sessionId: token,
|
sessionId: token,
|
||||||
loginTime: adminSession.loginTime
|
loginTime: adminSession.loginTime
|
||||||
@@ -1567,8 +1566,15 @@ const authenticateUserOrAdmin = async (req, res, next) => {
|
|||||||
try {
|
try {
|
||||||
const adminSession = await redis.getSession(adminToken)
|
const adminSession = await redis.getSession(adminToken)
|
||||||
if (adminSession && Object.keys(adminSession).length > 0) {
|
if (adminSession && Object.keys(adminSession).length > 0) {
|
||||||
|
// 🔒 安全修复:验证会话必须字段(与 authenticateAdmin 保持一致)
|
||||||
|
if (!adminSession.username || !adminSession.loginTime) {
|
||||||
|
logger.security(
|
||||||
|
`🔒 Corrupted admin session in authenticateUserOrAdmin from ${req.ip || 'unknown'} - missing required fields (username: ${!!adminSession.username}, loginTime: ${!!adminSession.loginTime})`
|
||||||
|
)
|
||||||
|
await redis.deleteSession(adminToken) // 清理无效/伪造的会话
|
||||||
|
// 不返回 401,继续尝试用户认证
|
||||||
|
} else {
|
||||||
req.admin = {
|
req.admin = {
|
||||||
id: adminSession.adminId || 'admin',
|
|
||||||
username: adminSession.username,
|
username: adminSession.username,
|
||||||
sessionId: adminToken,
|
sessionId: adminToken,
|
||||||
loginTime: adminSession.loginTime
|
loginTime: adminSession.loginTime
|
||||||
@@ -1579,6 +1585,7 @@ const authenticateUserOrAdmin = async (req, res, next) => {
|
|||||||
logger.security(`🔐 Admin authenticated: ${adminSession.username} in ${authDuration}ms`)
|
logger.security(`🔐 Admin authenticated: ${adminSession.username} in ${authDuration}ms`)
|
||||||
return next()
|
return next()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.debug('Admin authentication failed, trying user authentication:', error.message)
|
logger.debug('Admin authentication failed, trying user authentication:', error.message)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user