feat: 上线前安全加固与发布工程化;appmall 由插件迁移为独立应用
安全(P0) - 发布包签名:新增 scripts/package_keygen.php、scripts/package_verify.php、 ywxapp\service\PackageVerifier;FrameworkService::apply() 解压前强制验签 (ywxapp.framework_package_verify,默认开启) - JWT 收紧:config/jwt.php 移除公开默认密钥,JwtService::assertStrongSecret() 校验非空 / 长度≥32 / 已知弱值;.env.production.example 键名由 JWT_SECRET_KEY 修正为 JWT_SECRET - /api/v1/Article:免登录白名单收窄为只读接口,写操作字段白名单 + assertOwner() 越权校验 - 开发者令牌:查找接口不再回显明文、统一失败文案 + 限流 - TemplateInstaller:文件名白名单 + realpath 归一化 + 目录内断言,修复 Zip Slip;补 use ZipArchive - 后台登录:接入验证码、失败锁定与登录限流(config/ratelimit.php) - 缓存 / Session 驱动可由 .env 覆盖(CACHE_DRIVER / SESSION_TYPE),集群部署改 redis - paycenter 支付日志开关改为 PAY_LOG,不再跟随 APP_DEBUG 工程化 / 交付 - 新增 CHANGELOG.md 与 .env.production.example;composer.lock 入库锁定依赖版本 - 插件离线安装 CLI 增加 --uid,后台上传安装透传 uid,付费插件授权校验可通过 - 授权拒绝文案区分「未携带 uid」与「未找到有效授权」,便于排障 - .gitignore 放行 .env.production.example / .env.addon.example / .gitattributes / public/.htaccess 结构 - appmall 由 addon/appmall 迁移为独立应用 app/appmall(市场 / 开发者中心 / 审核 / 分润)
This commit is contained in:
1 parent
1d49e6f5ee
commit
18101cf11a
636 files changed
+58517
-9519
No files matched your search
@@ -40,6 +40,12 @@ class Comment extends BlogFrontend
|
||||
}
|
||||
$uid = $this->auth->model->uid;
|
||||
|
||||
// 限流:同一用户 N 秒内只能发一条,防灌水/刷屏(0 = 不限)
|
||||
$interval = max(0, (int) config('blog.comment_interval', 10));
|
||||
if ($interval > 0 && \think\facade\Cache::get('blog_comment_lock:' . $uid)) {
|
||||
return json(['code' => 0, 'msg' => '评论太频繁,请稍后再试']);
|
||||
}
|
||||
|
||||
$data = Request::post();
|
||||
|
||||
$validate = new \think\Validate([
|
||||
@@ -52,9 +58,14 @@ class Comment extends BlogFrontend
|
||||
return json(['code' => 0, 'msg' => $validate->getError()]);
|
||||
}
|
||||
|
||||
$article = ArticleModel::find($data['article_id']);
|
||||
// 只能给「已发布 + 审核通过」的文章评论:
|
||||
// 否则草稿/待审/驳回文章会成为垃圾评论入口,也泄露未公开内容
|
||||
$article = ArticleModel::where('id', $data['article_id'])
|
||||
->where('status', 1)
|
||||
->where('audit_status', 2)
|
||||
->find();
|
||||
if (!$article) {
|
||||
return json(['code' => 0, 'msg' => '文章不存在']);
|
||||
return json(['code' => 0, 'msg' => '文章不存在或不可评论']);
|
||||
}
|
||||
|
||||
if ($data['parent_id'] > 0) {
|
||||
@@ -64,21 +75,32 @@ class Comment extends BlogFrontend
|
||||
}
|
||||
}
|
||||
|
||||
// 先做 HTML 白名单净化(防 XSS),再做敏感词替换
|
||||
$content = \addon\blog\library\HtmlSanitizer::clean((string) $data['content']);
|
||||
$sensitiveWords = ['垃圾', '广告', '违法', '政治'];
|
||||
$content = str_replace($sensitiveWords, '***', $data['content']);
|
||||
$content = str_replace($sensitiveWords, '***', $content);
|
||||
|
||||
$comment = new CommentModel();
|
||||
$comment->uid = $uid;
|
||||
$comment->aid = $data['article_id'];
|
||||
$comment->pid = $data['parent_id'] ?? 0;
|
||||
$comment->content = $content;
|
||||
$comment->status = 1;
|
||||
// 评论审核:need_audit 开启时先审后发(0=待审核,见 install.sql 注释),否则直接显示
|
||||
$needAudit = (int) config('blog.need_audit');
|
||||
$comment->status = $needAudit ? 0 : 1;
|
||||
$comment->ip = Request::ip();
|
||||
$comment->user_agent = Request::server('HTTP_USER_AGENT');
|
||||
$comment->save();
|
||||
|
||||
$article->comment_count = Db::raw('comment_count + 1');
|
||||
$article->save();
|
||||
// 只有直接显示的评论才计数;待审核的等后台审核通过后再累加
|
||||
if (!$needAudit) {
|
||||
$article->comment_count = Db::raw('comment_count + 1');
|
||||
$article->save();
|
||||
}
|
||||
|
||||
if ($interval > 0) {
|
||||
\think\facade\Cache::set('blog_comment_lock:' . $uid, 1, $interval);
|
||||
}
|
||||
|
||||
return json([
|
||||
'code' => 1,
|
||||
@@ -87,6 +109,13 @@ class Comment extends BlogFrontend
|
||||
'id' => $comment->id,
|
||||
'content' => $comment->content,
|
||||
'create_at' => $comment->create_text,
|
||||
// 前端渲染取 d.user.*,键名必须一致(原先返回 member,导致新评论显示 undefined)
|
||||
'user' => [
|
||||
'uid' => $uid,
|
||||
'nickname' => $this->auth->model->nickname,
|
||||
'avatar' => $this->auth->model->avatar ?? '/static/images/avatar.png'
|
||||
],
|
||||
// 保留 member 兼容旧前端
|
||||
'member' => [
|
||||
'uid' => $uid,
|
||||
'nickname' => $this->auth->model->nickname,
|
||||
@@ -116,17 +145,32 @@ class Comment extends BlogFrontend
|
||||
return json(['code' => 0, 'msg' => '无权限操作']);
|
||||
}
|
||||
|
||||
// 先统计将被删除的条数(含子评论),避免计数漂移(原先固定 -1)
|
||||
$deletedCount = $this->countWithChildren((int) $id);
|
||||
$this->deleteCommentWithChildren($id);
|
||||
|
||||
$article = ArticleModel::find($comment->aid);
|
||||
if ($article) {
|
||||
$article->comment_count = Db::raw('comment_count - 1');
|
||||
$article->comment_count = Db::raw('comment_count - ' . max(1, $deletedCount));
|
||||
$article->save();
|
||||
}
|
||||
|
||||
return json(['code' => 1, 'msg' => '评论已删除']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归统计评论及其子评论的条数
|
||||
*/
|
||||
private function countWithChildren(int $id): int
|
||||
{
|
||||
$count = 1;
|
||||
$childIds = CommentModel::where('pid', $id)->column('id');
|
||||
foreach ($childIds as $childId) {
|
||||
$count += $this->countWithChildren((int) $childId);
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归删除评论及其子评论
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user