fix(api): 修复 API Token 过期校验与更新校验
- 将数据库中的 expires_at 设为必填,并在认证时仅允许未过期的令牌通过 - 增加空过期时间的更新校验,避免写入非法时间值 - 补充过期令牌与空过期时间更新的测试覆盖 - 调整前端日期输入与提交逻辑,避免创建 API Token 时表单异常中断
This commit is contained in:
@@ -124,6 +124,10 @@ func (a *App) handleUpdateAPIToken(w http.ResponseWriter, r *http.Request) {
|
||||
expiresValue = current.ExpiresAt.UTC().Format(time.RFC3339Nano)
|
||||
}
|
||||
if req.ExpiresAt != nil {
|
||||
if strings.TrimSpace(*req.ExpiresAt) == "" {
|
||||
badRequest(w, errors.New("expiresAt must be an RFC3339 timestamp"))
|
||||
return
|
||||
}
|
||||
expiresAt, err := parseOptionalFutureTime(*req.ExpiresAt, a.now().UTC())
|
||||
if err != nil {
|
||||
badRequest(w, err)
|
||||
|
||||
Reference in New Issue
Block a user