sqlite-web 0.7.2
gitea.db
issue
Create
Query
access
access_token
action
action_artifact
action_run
action_run_index
action_run_job
action_runner
action_runner_token
action_schedule
action_schedule_spec
action_task
action_task_output
action_task_step
action_tasks_version
action_variable
app_state
attachment
auth_token
badge
branch
collaboration
comment
commit_status
commit_status_index
commit_status_summary
commit_sync_log
commit_sync_status
dbfs_data
dbfs_meta
deploy_key
email_address
email_hash
external_login_user
follow
gpg_key
gpg_key_import
hook_task
issue
issue_assignees
issue_content_history
issue_dependency
issue_index
issue_label
issue_pin
issue_user
issue_watch
label
language_stat
lfs_lock
lfs_meta_object
login_source
milestone
mirror
notice
notification
oauth2_application
oauth2_authorization_code
oauth2_grant
org_user
package
package_blob
package_blob_upload
package_cleanup_rule
package_file
package_property
package_version
project
project_board
project_issue
protected_branch
protected_tag
public_key
pull_auto_merge
pull_request
push_mirror
reaction
release
renamed_branch
repo_archiver
repo_hidden_file
repo_indexer_status
repo_license
repo_redirect
repo_topic
repo_transfer
repo_unit
repository
review
review_state
secret
session
sqlite_sequence
star
stopwatch
system_setting
task
team
team_invite
team_repo
team_unit
team_user
topic
tracked_time
two_factor
upload
user
user_badge
user_blocking
user_open_id
user_redirect
user_setting
version
watch
webauthn_credential
webhook
Toggle helper tables
Structure
Content
Query
Insert
Drop
Import
Export
Delete row 643 from issue
id
643
repo_id
22
index
81
poster_id
1
original_author
original_author_id
0
name
🔍 代码审查报告:app-260616 - 预订列表
content
## 自动代码审查报告 **分支**: app-260616 **提交**: `422c54fb5
## 自动代码审查报告 **分支**: app-260616 **提交**: `422c54fb5bc9fc67619ac2b5c777d7be5b60df9e` **提交人**: LITTLEMAIDI (11833999+littlemaidi@user.noreply.gitee.com) **时间**: 2026-06-09 16:52:26 --- ## 1. 审查摘要 - **代码质量评分**:4.5 / 10 分 - **总体评价**:代码实现了较为复杂的商户端业务逻辑,但存在典型的“巨型控制器/模型”反模式。安全层面存在硬编码密钥与 SQL 注入风险;性能层面存在明显的 N+1 查询与重复资源加载;架构层面严重违反单一职责原则,且混用了 CodeIgniter 3 的底层特性(注:项目结构及语法特征高度吻合 CI3,非 `phpci` 框架,以下审查基于 CI3 最佳实践)。整体需进行系统性重构。 - **风险等级**:🔴 高 ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `MerchantAppServer.php` (约第350行) | **硬编码敏感凭证**:`xfyun_tts_config` 直接暴露了第三方 API 的 `APPID`、`APISecret` 和 `APIKey`,极易导致服务被盗刷或数据泄露。 | 将敏感配置移至 `application/config/` 下的独立配置文件或环境变量中,通过 `$this->config->item()` 读取。 | `// config/xfyun.php<br>return ['appid' => 'xxx', 'secret' => 'xxx'];<br><br>// Controller<br>$config = $this->config->item('xfyun');` | | 🔴 严重 | `Ahead_book_model.php` (第5行) | **框架生命周期违规**:在类外部直接调用 `$CI = &get_instance();`。CI 框架在文件加载阶段尚未完成初始化,会导致致命错误或不可预期的行为。 | 移除文件顶部的全局调用。在类方法内部按需使用 `$this->load->` 或 `$CI = &get_instance()`。 | `// 删除文件顶部的 $CI = &get_instance();<br>// 在方法内部使用:<br>$CI =& get_instance();` | | 🔴 严重 | `Ahead_book_model.php` (`get_book_list` 方法内) | **SQL 注入漏洞**:`$where_str[] = "(book._book_no LIKE '%" . $params['book_no'] . "%' ..."` 直接拼接用户输入,未进行转义或参数绑定。 | 使用 CI Query Builder 的 `like()` 方法或 `$this->db->escape_like_str()` 进行安全过滤。 | `$search = $this->db->escape_like_str($params['book_no']);<br>$this->db->group_start()<br> ->like('book._book_no', $search, 'both')<br> ->or_like('book._customer_contact', $search, 'after')<br>->group_end();` | | 🔴 严重 | `MerchantAppServer.php` (`__construct`) | **初始化逻辑断裂**:通过 `if ($this->router->fetch_method() !== "uploadPic")` 跳过核心初始化。若其他未白名单方法被调用,将因 `$this->request`、`$this->stream` 等属性未定义而抛出 `Undefined property` 或空指针异常。 | 移除方法级白名单拦截。改为在 `__construct` 中安全初始化基础属性,或在具体方法开头按需校验。 | `// 移除 if 判断<br>$this->stream = json_decode(file_get_contents('php://input'), true) ?? [];` | | 🟠 警告 | `Ahead_book_model.php` (`get_book_list` 循环内) | **N+1 查询性能瓶颈**:`foreach` 循环中逐行调用 `$this->ahead_vip_model->get_vip_info_by_recharge()`,数据量大时将导致数据库连接耗尽与响应延迟。 | 改为批量查询:先收集所有 `customer_contact`,使用 `WHERE IN` 一次性查出 VIP 信息,再在 PHP 中映射到对应行。 | `$contacts = array_column($list['rows'], 'customer_contact');<br>$vip_data = $this->ahead_vip_model->get_batch_by_mobiles($contacts);<br>// 循环中通过 $vip_data[$row['customer_contact']] 赋值` | | 🟠 警告 | `MerchantAppServer.php` (`index` 方法) | **重复加载模型与配置**:多个 `case` 分支中重复执行 `$this->load->model()` 和 `$this->config->load()`,增加 I/O 开销与内存占用。 | 将公共依赖的模型/配置提取至 `__construct` 或类属性中按需懒加载。 | `// __construct 中统一加载<br>$this->load->model(['ahead_merchant_role_priv_model', 'ahead_yc_shop_model']);` | | 🟠 警告 | `MerchantAppServer.php` (约第15行) | **CORS 策略过于宽松**:`header("Access-Control-Allow-Origin:*");` 允许任意域名跨域请求,易被恶意站点利用发起 CSRF 或数据窃取。 | 根据实际业务配置可信域名白名单,或限制为 App 端特定 `User-Agent`/`Origin`。 | `$allowed = ['https://app.yourdomain.com'];<br>if (in_array($_SERVER['HTTP_ORIGIN'] ?? '', $allowed)) {<br> header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");<br>}` | | 🟡 建议 | `MerchantAppServer.php` (`index` 方法) | **魔法数字与硬编码泛滥**:`case '0005'`、`$permission_id = 534`、`$unsetMenuIds = [694, 849...]` 等缺乏语义化定义,维护成本极高。 | 提取为类常量或独立配置文件(如 `config/permissions.php`),使用枚举或常量映射。 | `const FUNC_LOGIN = '0005';<br>const PERM_VIP_RECHARGE_INVALID = 534;` | | 🟡 建议 | `MerchantAppServer.php` (约第200行) | **数组过滤逻辑低效**:使用 `foreach` + `unset` + `array_values()` 过滤菜单,可读性差且性能不佳。 | 改用 `array_filter()` 结合闭包函数,代码更简洁且符合函数式编程规范。 | `$menus = array_values(array_filter($menus, function($v) use ($unsetMenuIds) {<br> return !in_array($v['id'], $unsetMenuIds) && !in_array($v['parentid'], $unsetMenuIds);<br>}));` | | 🟡 建议 | `MerchantAppServer.php` / `Ahead_book_model.php` | **命名规范与拼写错误**:`AplicationController` 拼写错误;变量命名混用驼峰与下划线;注释含大量历史标记(如 `add by nan 17.10.25`)。 | 遵循 PSR-12 规范:类名 PascalCase,方法/属性 camelCase,常量 UPPER_SNAKE_CASE。清理过期注释。 | `class MerchantAppServer extends ApplicationController` | ## 3. 总结与行动建议 ### 🔑 优先修复的关键问题 1. **立即移除硬编码密钥**:将 `xfyun_tts_config` 等敏感配置迁移至环境变量或加密配置文件中,避免凭证泄露。 2. **修复 SQL 注入风险**:全面审查 `Ahead_book_model.php` 中的 `$where_str` 拼接逻辑,统一替换为 CI Query Builder 的安全绑定方法。 3. **纠正框架生命周期调用**:删除 `Ahead_book_model.php` 文件顶部的 `$CI = &get_instance();`,防止框架初始化冲突。 ### 🛠 后续重构与优化方向 1. **架构拆分(Controller -> Service/Repository)**: - 当前 `MerchantAppServer` 承担了路由分发、鉴权、权限校验、数据组装、业务逻辑等所有职责,违反单一职责原则。 - **建议**:按业务域拆分为独立控制器(如 `AuthController`, `OrderController`, `PrinterController`),并将复杂业务逻辑下沉至 `Service` 层,模型仅负责数据持久化。 2. **性能优化策略**: - 解决 `get_book_list` 中的 N+1 查询问题,采用批量加载或 `JOIN` 预加载。 - 将重复的 `$this->load->model()` 移至构造函数或使用 CI 的自动加载配置。 - 对高频调用的权限校验(如 `check_priv`)引入 Redis 缓存,降低数据库压力。 3. **规范化与可维护性提升**: - 建立全局常量/配置中心管理魔法数字(接口号、权限ID、菜单ID等)。 - 统一输入校验层:在 `__construct` 或中间件中统一解析 JSON、校验 Token 格式、过滤非法字符,避免在每个 `case` 中重复处理。 - 补充异常处理与日志记录:当前 `try-catch` 仅返回失败提示,建议接入统一日志组件(如 Monolog)记录堆栈,便于线上排查。 > 📌 **注**:项目代码结构、加载方式(`$this->load->`、`get_instance()`、`BASEPATH`)与 **CodeIgniter 3** 高度一致。若实际使用的是内部封装的 `phpci` 框架,请核对上述 CI3 特性是否被框架兼容或重写。建议查阅框架官方文档确认路由分发、模型加载及安全过滤的最佳实践。 --- *此 Issue 由代码审查服务自动创建*
...
milestone_id
0
priority
0
is_closed
0
is_pull
0
num_comments
0
ref
deadline_unix
0
created_unix
1780995146
updated_unix
1780995146
closed_unix
0
is_locked
0
content_version
0
time_estimate
0
Delete
Cancel