✏️ sql 防注入

This commit is contained in:
fumiama 2021-12-08 17:35:22 +08:00
parent c824b2e0b4
commit 5645fa0168
2 changed files with 3 additions and 2 deletions

View File

@ -13,7 +13,8 @@ func init() {
Help: "哀伤雪刃推书记录\n- 书评[xxx]\n- 随机书评", Help: "哀伤雪刃推书记录\n- 书评[xxx]\n- 随机书评",
}) })
engine.OnRegex("^书评(.{1,25})$").SetBlock(true). // 中文、英文、数字但不包括下划线等符号
engine.OnRegex("^书评([\u4E00-\u9FA5A-Za-z0-9]{1,25})$").SetBlock(true).
Handle(func(ctx *zero.Ctx) { Handle(func(ctx *zero.Ctx) {
b := getBookReviewByKeyword(ctx.State["regex_matched"].([]string)[1]) b := getBookReviewByKeyword(ctx.State["regex_matched"].([]string)[1])
ctx.SendChain(message.Text(b.BookReview)) ctx.SendChain(message.Text(b.BookReview))

View File

@ -7,7 +7,7 @@ type book struct {
// 暂时随机选择一个书评 // 暂时随机选择一个书评
func getBookReviewByKeyword(keyword string) (b book) { func getBookReviewByKeyword(keyword string) (b book) {
db.Find("bookreview", &b, "where bookreview LIKE %"+keyword+"%") db.Find("bookreview", &b, "where bookreview LIKE '%"+keyword+"%'")
return return
} }