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:
yangwx committed 2026-10-22 00:53:39 +08:00
1 parent 1d49e6f5ee
commit 18101cf11a
636 files changed
+58517 -9519

No files matched your search

+73
View File
@@ -37,6 +37,56 @@ class BaseModel extends Model
];
}
/* ---------------------------------------------------------------------
* 通用表存在性兜底
*
* 背景:运行时数据/配置表被误删时(历史上出现过角色表、菜单节点被清空,
* 以及 wxapp_common_addon 整表缺失),模型查询会直接抛 1146,进而导致
* 后台整页不可用。这里在基类层面统一兜底:任何继承 BaseModel 的模型
* 实例化时校验自己的表,缺失则按 install.sql 事实源尝试重建。
* 子类因此无需各自实现一遍;install.sql 未收录的表(如 common_addonconf)
* 由该模型自身的 ensureSchema() 提供 DDL。
* ------------------------------------------------------------------- */
/**
* 本请求内已校验过的表,避免重复 SHOW TABLES
* @var array<string,bool>
*/
protected static array $schemaChecked = [];
protected function initialize()
{
parent::initialize();
// 构造顺序上 applyOptions() 可能尚未执行(取决于子类是否在 __construct 中调用),
// 这里补一次,确保取到的是含前缀的完整表名。
$this->applyOptions();
self::autoEnsureTable((string) $this->getTable());
}
/**
* 表缺失时按 install.sql 自愈(幂等,每请求每表最多一次探测)
*/
public static function autoEnsureTable(string $table): void
{
if ($table === '' || isset(self::$schemaChecked[$table])) {
return;
}
try {
if (self::tableExists($table)) {
self::$schemaChecked[$table] = true;
return;
}
$prefix = self::currentPrefix();
$bare = ($prefix !== '' && strpos($table, $prefix) === 0)
? substr($table, strlen($prefix))
: $table;
self::ensureTableFromInstall($prefix, $bare);
self::$schemaChecked[$table] = true;
} catch (\Throwable $e) {
// 自愈失败不阻断实例化,交由实际查询报错暴露
}
}
/**
* 将扁平的父子结构数组转换为带层级缩进的树形下拉数据
* @param array $cate 数据集(含 id/pid 字段)
@@ -63,6 +113,29 @@ class BaseModel extends Model
public function __construct(array $data = [])
{
// 自愈必须早于 parent::__construct():think-orm 在构造过程中就会读取表结构
// (PDOConnection::getTableInfo),若此时表尚不存在会直接抛 1146,
// 根本等不到 initialize() 钩子执行。
// 注意:这里不能用 $this->getTable() —— 它本身会触发 schema 读取而先抛异常,
// 因此直接读 name/table 属性自行拼表名(与 think-orm 的取名规则一致)。
// 这里刻意不调用 applyOptions():Model 内部属性(readonly/hidden/append 等)
// 此时还是 null,赋值会走 __set()->getMappingName() 触发 TypeError。
// 因此只读 getOptions() 的返回值推算表名——它仅返回配置数组,无副作用。
try {
$opts = method_exists($this, 'getOptions') ? (array) $this->getOptions() : [];
$bare = isset($opts['name']) ? (string) $opts['name'] : '';
if ($bare === '') {
$bare = strtolower((string) preg_replace(
'/(?<!^)[A-Z]/',
'_$0',
(new \ReflectionClass($this))->getShortName()
));
}
$table = ! empty($opts['table']) ? (string) $opts['table'] : self::currentPrefix() . $bare;
self::autoEnsureTable($table);
} catch (\Throwable $e) {
// 取表名失败等情况下不阻断实例化
}
parent::__construct($data);
$this->applyOptions();
}