bug fixed

This commit is contained in:
lik
2026-10-07 15:51:23 +08:00
parent 1974975882
commit f0edd6d548
3 changed files with 10 additions and 11 deletions
+4 -11
View File
@@ -241,17 +241,10 @@ class HandlerUser {
return ResponseUtil.success(ctx, { user: sanitizeUser(ctx.state.user) }, "获取用户信息成功");
}
// 兼容:通过 userId 查询(脱敏响应,不含任何安全凭证)
const { userId } = ctx.request.body || {};
if (userId) {
const user = await DBModel.User.findOne({ _id: userId });
if (!user) {
return ResponseUtil.notFound(ctx, "用户不存在");
}
return ResponseUtil.success(ctx, { user: sanitizeUser(user) }, "获取用户信息成功");
}
return ResponseUtil.badRequest(ctx, "缺少 token 或 userId");
// 不再支持「凭 userId 明文查询」:用户ID不是凭证,
// 任何人都可能通过日志/链接拿到他人 userId,若可据此读取资料即构成越权。
// 一律要求携带有效 token,身份以 token 为准。
return ResponseUtil.badRequest(ctx, "缺少 token");
}
// 更新用户信息