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
@@ -51,11 +51,58 @@ class BlogArticle extends BaseModel
|
||||
'update_at' => 'int',
|
||||
];
|
||||
|
||||
// 内容修改器(过滤危险标签)
|
||||
// 内容修改器:还原实体后做白名单净化
|
||||
//
|
||||
// 正文在前台是 {$article.content|raw} 直出(富文本必须原样输出),
|
||||
// 因此必须在入库前净化,否则会员投稿即可形成存储型 XSS。
|
||||
|
||||
public function setContentAttr($value)
|
||||
{
|
||||
return htmlspecialchars_decode($value);
|
||||
return \addon\blog\library\HtmlSanitizer::clean(htmlspecialchars_decode((string) $value));
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入后清理首页缓存
|
||||
*
|
||||
* 首页数据缓存 homepage_data_v2 原先没有失效机制,新文章最长 1 小时才可见。
|
||||
* 放在模型事件里,后台审核/编辑、会员发文等所有入口都能自动失效。
|
||||
*/
|
||||
protected static function onAfterWrite($model)
|
||||
{
|
||||
\think\facade\Cache::delete('homepage_data_v2');
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表场景的字段列表(动态生成,排除 longtext content)
|
||||
*
|
||||
* 为什么不写死列名、也不用 field('content', true):
|
||||
* 1. 排除式 field() 与 bind 关联(user()/category())组合时,
|
||||
* 会生成只剩 `content` 的 SQL,列表字段全部变空(实测踩过);
|
||||
* 2. 写死列名在老库缺列时直接 Unknown column 报错。
|
||||
* 因此改为按 SHOW COLUMNS 动态取列并排除 content,结果缓存 1 小时。
|
||||
*/
|
||||
public static function listFields(): string
|
||||
{
|
||||
$cacheKey = 'blog:list_fields';
|
||||
$fields = \think\facade\Cache::get($cacheKey);
|
||||
|
||||
if (!is_array($fields) || empty($fields)) {
|
||||
$table = \think\facade\Db::name('blog_article')->getTable();
|
||||
$cols = \think\facade\Db::query('SHOW COLUMNS FROM `' . $table . '`');
|
||||
|
||||
$fields = [];
|
||||
foreach ($cols as $col) {
|
||||
$name = $col['Field'] ?? '';
|
||||
if ($name === '' || strtolower($name) === 'content') {
|
||||
continue;
|
||||
}
|
||||
$fields[] = '`' . $name . '`';
|
||||
}
|
||||
|
||||
\think\facade\Cache::set($cacheKey, $fields, 3600);
|
||||
}
|
||||
|
||||
return implode(',', $fields);
|
||||
}
|
||||
|
||||
// 摘要写入修改器:提交时若留空,自动从正文截取并持久化
|
||||
|
||||
@@ -17,6 +17,10 @@ class BlogVisit extends BaseModel
|
||||
{
|
||||
// 设置数据表名
|
||||
protected $name = 'blog_visit';
|
||||
|
||||
// 注:本模型已有 record()(写入)/ getStats()(读取),
|
||||
// 但此前没有任何地方调用 record(),导致访客统计恒空。
|
||||
// 写入入口已在 BlogFrontend::recordVisit() 中接入(带 30 分钟去重)。
|
||||
|
||||
// 设置主键
|
||||
protected $pk = 'id';
|
||||
|
||||
Reference in new issue
Block a user