Skip to content

在RestCommentController的edit接口疑似存在水平越权,导致跨用户修改 #41

@goldthree-shit

Description

@goldthree-shit

问题描述

在RestCommentController的edit接口中,直接把前端传入的comment参数用于更新数据库。而没有校验comment的所属用户信息。此时,如果其他用户通过直接调用接口的方式传入comment参数,则可能造成跨用户修改。

相关代码

    @RequiresPermissions("comments")
    @PostMapping("/edit")
    @BussinessLog("编辑评论")
    public ResponseVO edit(Comment comment) {
        try {
            commentService.updateSelective(comment); // 缺少用户身份校验
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error("评论修改失败!");
        }
        return ResultUtil.success(ResponseStatus.SUCCESS);
    }

原理

漏洞复现场景
假设系统中有两个用户:

  • 用户 A(ID=1)发布了评论,评论 ID=1001,内容是 “好评”;
  • 用户 B(ID=2)拥有 comments 权限,但只能修改自己的评论。
    攻击者(用户 B)可通过以下方式篡改用户 A 的评论:
  1. 构造 POST 请求调用 /edit 接口;
  2. 请求参数传入:{id:1001, content:"差评", userId:1};
  3. 后端仅校验 comments 权限(用户 B 有),直接执行 updateSelective(comment);
  4. 最终用户 A 的评论 ID=1001 被篡改为 “差评”,完全跨用户修改。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions