Skip to content

Commit

Permalink
fix: 解决请求信息通过伪造绕过校验的问题 (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
eryajf authored Apr 3, 2023
1 parent b4ff4d2 commit 5d648a8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
12 changes: 4 additions & 8 deletions pkg/db/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ type Chat struct {
Content string `gorm:"type:varchar(128);comment:'内容'" json:"content"` // 问题或回答的内容
}

// 需要考虑下如何处理一个完整对话的问题
// 如果是单聊,那么就记录上下两句就好了
// 如果是串聊,则需要知道哪条是第一条,并依次往下记录
type ChatListReq struct {
Username string `json:"username" form:"username"`
Source string `json:"source" form:"source"`
}

// Add 添加资源
func (c Chat) Add() (uint, error) {
Expand All @@ -36,11 +37,6 @@ func (c Chat) Find(filter map[string]interface{}, data *Chat) error {
return DB.Where(filter).First(&data).Error
}

type ChatListReq struct {
Username string `json:"username" form:"username"`
Source string `json:"source" form:"source"`
}

// List 获取数据列表
func (c Chat) List(req ChatListReq) ([]*Chat, error) {
var list []*Chat
Expand Down
6 changes: 3 additions & 3 deletions pkg/process/process_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func ProcessRequest(rmsg *dingbot.ReceiveMsg) error {
logger.Warning(fmt.Errorf("send message error: %v", err))
}
case "查对话":
msg := "使用如下指令进行查询:\n\n---\n\n**#查对话 username:张三**\n\n---\n\n需要注意格式必须严格与上边一致,否则会查询失败\n\n只有钉钉管理员,程序系统管理员,与查自己的情况下,才会被允许"
msg := "使用如下指令进行查询:\n\n---\n\n**#查对话 username:张三**\n\n---\n\n需要注意格式必须严格与上边一致,否则将会查询失败\n\n只有程序系统管理员有权限查询,即config.yml中的admin_users指定的人员。"
_, err := rmsg.ReplyToDingtalk(string(dingbot.MARKDOWN), msg)
if err != nil {
logger.Warning(fmt.Errorf("send message error: %v", err))
Expand Down Expand Up @@ -264,8 +264,8 @@ func ImageGenerate(rmsg *dingbot.ReceiveMsg) error {
}
func SelectHistory(rmsg *dingbot.ReceiveMsg) error {
name := strings.TrimSpace(strings.Split(rmsg.Text.Content, ":")[1])
if !rmsg.IsAdmin && name != rmsg.SenderNick && !public.JudgeAdminUsers(rmsg.SenderNick) {
_, err := rmsg.ReplyToDingtalk(string(dingbot.MARKDOWN), "**🤷 抱歉,您没有权限查询其他人的对话记录!**")
if !public.JudgeAdminUsers(rmsg.SenderNick) {

This comment has been minimized.

Copy link
@tuvvut

tuvvut Apr 3, 2023

看起来还是使用 SenderNick,请问这样不会有伪造为管理员的可能性存在吗?

This comment has been minimized.

Copy link
@eryajf

eryajf Apr 3, 2023

Author Owner

这么说来,也不是不能😂
有点难,得再思考一下

_, err := rmsg.ReplyToDingtalk(string(dingbot.MARKDOWN), "**🤷 抱歉,您没有查询对话记录的权限,只有程序管理员可以查询!**")
if err != nil {
logger.Error(fmt.Errorf("send message error: %v", err))
return err
Expand Down

0 comments on commit 5d648a8

Please sign in to comment.