补齐邮件协议隔离回归并优化客户端设置
Security Checks / security (push) Waiting to run

This commit is contained in:
xuans committed 2026-09-06 22:28:20 +08:00
1 parent 110a5f86cc
commit 20a6eea3b3
15 files changed
+360 -21

No files matched your search

+15 -2
View File
@@ -204,8 +204,21 @@ func (s *Service) VerifyProtocolCode(userID int, protocol string, plain string)
return false
}
now := s.now()
_, _ = s.engine.ID(item.ID).Cols("last_used_at", "updated_at").Update(&models.ProtocolCredential{LastUsedAt: &now})
return true
// 哈希计算期间可能发生关闭、撤销或换码,返回成功前必须再次原子确认凭据状态。
affected, err := s.engine.ID(item.ID).
Where("enabled = ? AND revoked_at IS NULL AND code_version = ? AND code_hash = ?", true, item.CodeVersion, item.CodeHash).
Cols("last_used_at", "updated_at").Update(&models.ProtocolCredential{LastUsedAt: &now})
if err != nil {
return false
}
if affected == 1 {
return true
}
// MySQL 在时间字段未变化时可能报告零影响行,必须再次查询有效状态而不是误拒绝或直接放行。
valid, err := s.engine.ID(item.ID).
Where("enabled = ? AND revoked_at IS NULL AND code_version = ? AND code_hash = ?", true, item.CodeVersion, item.CodeHash).
Exist(&models.ProtocolCredential{})
return err == nil && valid
}
func newProtocolCode() (string, error) {