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
@@ -18,6 +18,7 @@ use think\exception\ValidateException;
|
||||
use think\facade\View;
|
||||
use app\common\library\Token;
|
||||
use ywxapp\library\AdminAuth;
|
||||
use ywxapp\library\AdminLogger;
|
||||
use ywxapp\library\SkinOverlay;
|
||||
use ywxapp\library\SkinVariables;
|
||||
use ywxapp\AddonBase;
|
||||
@@ -188,6 +189,11 @@ abstract class BackendBase extends BaseController
|
||||
$this->view->assign('member', $this->auth->info);
|
||||
}
|
||||
}
|
||||
|
||||
// 注入当前登录者的权限集:前端 auth 模块据此显隐 [data-perm] 按钮。
|
||||
// 取自登录时已解析好的 Auth::$powers,不额外查库;未登录时给空数组,
|
||||
// 保证模板变量始终存在(前端空权限集会隐藏全部受限按钮,符合预期)。
|
||||
$this->view->assign('powers', ($this->auth && $this->auth->isLogin) ? $this->auth->getPowers() : []);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -307,8 +313,11 @@ abstract class BackendBase extends BaseController
|
||||
$password = $this->request->post('password/s', '');
|
||||
$captcha = $this->request->post('captcha/s', '');
|
||||
if (! $this->auth->login($account, $password, $captcha)) {
|
||||
// 登录失败也要留痕(安全审计),此时还拿不到管理员 ID → aid=0
|
||||
AdminLogger::login($account, false, (string) $this->auth->getError());
|
||||
$this->result->error($this->auth->getError());
|
||||
}
|
||||
AdminLogger::login($account, true, '', (int) ($this->auth->info['id'] ?? 0));
|
||||
$this->result->success('登录成功', ['url' => url('backend/index/index')->build()]);
|
||||
}
|
||||
View::layout(false);
|
||||
@@ -320,10 +329,34 @@ abstract class BackendBase extends BaseController
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
// 先记日志再退出:logout 之后 auth->info 会被清空
|
||||
AdminLogger::write(
|
||||
'退出登录',
|
||||
'账号:' . ($this->auth->info['account'] ?? ''),
|
||||
(int) ($this->auth->info['id'] ?? 0)
|
||||
);
|
||||
$this->auth->logout();
|
||||
$this->result->success('退出成功', ['url' => url('backend/login/login')->build()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录后台操作日志(写操作留痕,见 ywxapp\library\AdminLogger).
|
||||
*
|
||||
* 只在操作成功(已 commit)后调用,失败操作不留痕,避免日志被失败重试刷屏。
|
||||
*
|
||||
* @param string $action 动作名,如 create / del
|
||||
* @param string $remark 摘要
|
||||
* @return void
|
||||
*/
|
||||
protected function logAction(string $action, string $remark = ''): void
|
||||
{
|
||||
AdminLogger::write(
|
||||
$this->request->controller() . '/' . $action,
|
||||
$remark,
|
||||
(int) ($this->auth->info['id'] ?? 0)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置页面标题(核心 layout 通过 {$title} 显示).
|
||||
* @param string $title
|
||||
@@ -435,8 +468,10 @@ abstract class BackendBase extends BaseController
|
||||
Db::rollback();
|
||||
$this->result->error($e->getMessage());
|
||||
}
|
||||
if ($result !== false)
|
||||
if ($result !== false) {
|
||||
$this->logAction('create', 'ID:' . $this->model->getKey());
|
||||
$this->result->success();
|
||||
}
|
||||
$this->result->error(lang('No rows were inserted'));
|
||||
}
|
||||
$this->result->error(lang('Parameter %s can not be empty', ''));
|
||||
@@ -486,8 +521,10 @@ abstract class BackendBase extends BaseController
|
||||
Db::rollback();
|
||||
$this->result->error($e->getMessage());
|
||||
}
|
||||
if ($result !== false)
|
||||
if ($result !== false) {
|
||||
$this->logAction('edit', 'ID:' . $row->{$row->getPk()});
|
||||
$this->result->success();
|
||||
}
|
||||
$this->result->error(lang('No rows were updated'));
|
||||
}
|
||||
$this->result->error(lang('Parameter %s can not be empty', ''));
|
||||
@@ -521,8 +558,10 @@ abstract class BackendBase extends BaseController
|
||||
Db::rollback();
|
||||
$this->result->error($e->getMessage());
|
||||
}
|
||||
if ($count)
|
||||
if ($count) {
|
||||
$this->logAction('del', 'ID:' . $ids);
|
||||
$this->result->success();
|
||||
}
|
||||
$this->result->error(lang('No rows were deleted'));
|
||||
}
|
||||
$this->result->error(lang('Parameter %s can not be empty'));
|
||||
@@ -558,8 +597,10 @@ abstract class BackendBase extends BaseController
|
||||
Db::rollback();
|
||||
$this->result->error($e->getMessage());
|
||||
}
|
||||
if ($count)
|
||||
if ($count) {
|
||||
$this->logAction('destroy', 'ID:' . $ids);
|
||||
$this->result->success();
|
||||
}
|
||||
$this->result->error(lang('Parameter %s can not be empty', 'ids'));
|
||||
}
|
||||
|
||||
@@ -590,8 +631,10 @@ abstract class BackendBase extends BaseController
|
||||
Db::rollback();
|
||||
$this->result->error($e->getMessage());
|
||||
}
|
||||
if ($count)
|
||||
if ($count) {
|
||||
$this->logAction('restore', 'ID:' . $ids);
|
||||
$this->result->success();
|
||||
}
|
||||
$this->result->error(lang('No rows were updated'));
|
||||
}
|
||||
|
||||
@@ -630,6 +673,7 @@ abstract class BackendBase extends BaseController
|
||||
$this->result->error($e->getMessage());
|
||||
}
|
||||
if ($count) {
|
||||
$this->logAction('multi', 'ID:' . $ids . ',字段:' . implode(',', array_keys($values)));
|
||||
$this->result->success();
|
||||
} else {
|
||||
$this->result->error(lang('No rows were updated'));
|
||||
@@ -823,10 +867,15 @@ abstract class BackendBase extends BaseController
|
||||
$sym = '=';
|
||||
}
|
||||
if (strtoupper($sym) === 'FIND_IN_SET') {
|
||||
// FIND_IN_SET(col, val) —— 列名同样需校验
|
||||
if (preg_match('/^[A-Za-z_][A-Za-z0-9_.]*$/', $k)) {
|
||||
$where[] = ['', 'EXP', Db::raw("FIND_IN_SET(`{$k}`, '" . addslashes($v) . "')")];
|
||||
}
|
||||
// 列名已由上方正则白名单校验(大小写字母/数字/下划线/点)。
|
||||
// 值改为标准 where 数组形式交给查询构造器做**参数绑定**:
|
||||
// 原写法 addslashes() 拼进 Db::raw,在 GBK 等宽字节字符集下
|
||||
// 可被 %bf%27 之类绕过引号转义(经典宽字节注入)。
|
||||
$v = is_array($v) ? implode(',', $v) : $v;
|
||||
$field = (stripos((string) $k, '.') === false && $alias !== '')
|
||||
? ($alias . '.' . $k)
|
||||
: $k;
|
||||
$where[] = [$field, 'find in set', $v];
|
||||
continue;
|
||||
}
|
||||
if (stripos($k, '.') === false) {
|
||||
|
||||
Reference in new issue
Block a user