Compare commits

...
3 Commits
Author SHA1 Message Date
github-actions[bot] 3840720620 chore: release v2.5.3 2023-04-06 13:08:21 +00:00
qwqcode 7dd8668b6e perf(ip_region): add db file existence check and error message (#482)
Signed-off-by: qwqcode <qwqcode@gmail.com>
2023-04-06 21:05:37 +08:00
qwqcode ac4b8b0b80 fix(api/comment_add): SIGSEGV crash in comment_add (#478) (#481)
Signed-off-by: qwqcode <qwqcode@gmail.com>
2023-04-06 20:46:27 +08:00
6 changed files with 45 additions and 12 deletions

No files matched your search

+11
View File
@@ -1,4 +1,15 @@
## [v2.5.3](https://github.com/ArtalkJS/Artalk/compare/v2.5.2...v2.5.3) (2023-04-06)
### Bug Fixes
* **api/comment_add:** SIGSEGV crash in comment_add ([#478](https://github.com/ArtalkJS/Artalk/issues/478)) ([#481](https://github.com/ArtalkJS/Artalk/issues/481))
### Performance Improvements
* **ip_region:** add db file existence check and error message ([#482](https://github.com/ArtalkJS/Artalk/issues/482))
## [v2.5.2](https://github.com/ArtalkJS/Artalk/compare/v2.5.1...v2.5.2) (2023-03-19)
### Bug Fixes
+1 -1
View File
@@ -1,3 +1,3 @@
{
"latest": "2.5.2"
"latest": "2.5.3"
}
+10 -5
View File
@@ -11,7 +11,6 @@ import (
"github.com/ArtalkJS/Artalk/internal/entity"
"github.com/ArtalkJS/Artalk/internal/query"
"github.com/ArtalkJS/Artalk/internal/utils"
"github.com/gofiber/fiber/v2"
"github.com/sirupsen/logrus"
)
@@ -19,7 +18,13 @@ var AntiSpamReplaceKeywords *[]string
const LOG_TAG = "[Spam Interception] "
func SyncSpamCheck(comment *entity.Comment, fiberCtx *fiber.Ctx) {
type SpanCheckConf struct {
ReqReferer string
ReqIP string
ReqUserAgent string
}
func SyncSpamCheck(comment *entity.Comment, conf SpanCheckConf) {
// 拦截评论
BlockCommentBy := func(blocker string) {
logrus.Info(fmt.Sprintf(LOG_TAG+"%s Successful blocking of comments ID=%d CONT=%s", blocker, comment.ID, strconv.Quote(comment.Content)))
@@ -60,7 +65,7 @@ func SyncSpamCheck(comment *entity.Comment, fiberCtx *fiber.Ctx) {
siteURL = query.CookSite(&site).FirstUrl
}
if siteURL == "" { // 从 referer 中提取网站
if pr, err := url.Parse(string(fiberCtx.Request().Header.Referer())); err == nil && pr.Scheme != "" && pr.Host != "" {
if pr, err := url.Parse(conf.ReqReferer); err == nil && pr.Scheme != "" && pr.Host != "" {
siteURL = fmt.Sprintf("%s://%s", pr.Scheme, pr.Host)
}
}
@@ -71,8 +76,8 @@ func SyncSpamCheck(comment *entity.Comment, fiberCtx *fiber.Ctx) {
isPass, err := Akismet(&AkismetParams{
Blog: siteURL,
UserIP: fiberCtx.IP(),
UserAgent: string(fiberCtx.Request().Header.UserAgent()),
UserIP: conf.ReqIP,
UserAgent: string(conf.ReqUserAgent),
CommentType: "comment",
CommentAuthor: user.Name,
+9
View File
@@ -1,6 +1,7 @@
package core
import (
"errors"
"io"
"os"
"strconv"
@@ -185,6 +186,14 @@ func initIPRegion() {
if irConf.DBPath == "" {
irConf.DBPath = "./data/ip2region.xdb"
}
// 检测配置文件是否存在
if _, err := os.Stat(irConf.DBPath); errors.Is(err, os.ErrNotExist) {
logrus.Error("未找到 IP 数据库文件:" + strconv.Quote(irConf.DBPath) + ",IP 归属地功能已禁用," +
"参考链接:https://artalk.js.org/guide/frontend/ip-region.html")
return
}
if irConf.Precision == "" {
// 默认精确到省
irConf.Precision = string(ip_region.Province)
+13 -5
View File
@@ -71,8 +71,12 @@ func CommentAdd(router fiber.Router) {
return common.RespError(c, i18n.T("Invalid {{name}}", Map{"name": i18n.T("Link")}))
}
ip := c.IP()
ua := string(c.Request().Header.UserAgent())
var (
ip = c.IP()
ua = string(c.Request().Header.UserAgent())
referer = string(c.Request().Header.Referer())
isAdmin = common.CheckIsAdminReq(c)
)
// 允许传入修正后的 UA
if p.UA != "" {
@@ -140,7 +144,7 @@ func CommentAdd(router fiber.Router) {
}
// default comment type
if !common.CheckIsAdminReq(c) && config.Instance.Moderator.PendingDefault {
if !isAdmin && config.Instance.Moderator.PendingDefault {
// 不是管理员评论 && 配置开启评论默认待审
comment.IsPending = true
}
@@ -160,8 +164,12 @@ func CommentAdd(router fiber.Router) {
}
// 垃圾检测
if !common.CheckIsAdminReq(c) { // 忽略检查管理员
anti_spam.SyncSpamCheck(&comment, c) // 同步执行
if !isAdmin { // 忽略检查管理员
anti_spam.SyncSpamCheck(&comment, anti_spam.SpanCheckConf{
ReqReferer: referer,
ReqIP: ip,
ReqUserAgent: ua,
}) // 同步执行
}
// 通知发送
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "artalk",
"version": "2.5.2",
"version": "2.5.3",
"license": "LGPL-3.0",
"description": "A Selfhosted Comment System",
"keywords": [