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
Update row 260 in issue
id
Primary key.
INTEGER NOT NULL
repo_id
INTEGER
index
INTEGER
poster_id
INTEGER
original_author
TEXT
original_author_id
INTEGER
name
🔍 代码审查报告:pc-260519 - 1
TEXT
content
## 自动代码审查报告 **分支**: pc-260519 **提交**: `2422c1f8324a2fa9d1d96f124491b13c767cc3e1` **提交人**: LITTLEMAIDI (11833999+littlemaidi@user.noreply.gitee.com) **时间**: 2026-05-21 10:33:22 --- ## 1. 审查摘要 - **代码质量评分**:6.5 / 10 分 - **总体评价**:业务逻辑完整,报表查询与数据映射流程清晰,符合传统 MVC 架构习惯。但存在明显的 **SQL 拼接安全隐患** 与 **N+1 查询性能瓶颈**,且部分参数校验、异常处理及框架资源管理不够严谨。代码整体可维护性中等,需进行安全加固与性能重构。 - **风险等级**:🔴 高(存在潜在 SQL 注入与大数据量下的性能雪崩风险) > 📌 **框架说明**:根据提供的目录结构(`system/helpers/`, `application/models/`, `$this->load->model()` 等),判断该项目实际基于 **CodeIgniter 3.x** 架构(提示中的 `phpci` 可能为笔误)。以下审查建议将基于 CI3 最佳实践与现代 PHP 规范给出。若底层 `select/count` 为自定义 ORM 封装,请确保其内部已实现参数绑定与转义。 --- ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `get_community_revenues_list` ~L138-148 | **SQL 注入风险**:`$pay_platform_where` 通过字符串拼接直接构建 SQL 条件。若 `$params['pay_platform_arr']` 包含未过滤的恶意字符,将导致注入。 | 强制类型转换或使用框架查询构建器的参数绑定。避免手动拼接 SQL 片段。 | `$pay_platform_where[] = ['a._pay_platform' => (int)$pay_platform, 'a._second_pay_platform' => (int)$pay_platform_arr[1]];`<br>*(需适配底层 `where` 解析逻辑)* | | 🔴 严重 | `get_community_revenues_list` ~L178-195 | **N+1 查询性能瓶颈**:在 `foreach` 循环中逐条调用 `$this->ahead_book_order_model->get_one()`。数据量 >100 时将引发严重 DB 延迟。 | 提取所有 `book_order_id`,使用 `WHERE IN` 批量查询,再通过数组映射回填数据。 | *(见下方行动建议中的重构示例)* | | 🟠 警告 | `get_community_revenues_list` ~L98-100 | **时间参数未校验**:`strtotime($params['start_time'])` 直接处理用户输入,非法格式返回 `false`,可能导致 SQL 语法错误或全表扫描。 | 增加时间格式校验,失败时拦截请求或返回明确错误。 | `if (!strtotime($params['start_time'])) { return ['error' => '时间格式无效']; }` | | 🟠 警告 | `get_community_revenues_list` ~L115-125 | **重复模型加载与冗余计算**:`get_incomes_pay_platform_list` 在搜索参数与报表查询中重复调用,且内部频繁 `load->model`,增加 I/O 与内存开销。 | 将支付方式列表缓存至类属性,或作为参数传入;模型加载移至构造函数。 | `protected $pay_platform_cache = [];`<br>`if (empty($this->pay_platform_cache)) { $this->pay_platform_cache = $this->get_incomes_pay_platform_list(...); }` | | 🟠 警告 | `get_community_revenues_list` ~L108-112, L126-132 | **JSON 解析容错性不足**:`json_decode` 未指定 `assoc` 参数,默认返回对象。后续 `!is_array` 判断虽能兜底,但逻辑冗余且 PHP 7.3+ 推荐使用异常模式。 | 使用 `json_decode($str, true)` 并配合严格校验。 | `$arr = json_decode($str, true);`<br>`if (!is_array($arr)) $arr = [];` | | 🟠 警告 | `get_community_revenues_list` ~L160, L174 | **数据库连接切换未做异常保护**:`enforce_con_db()` 与 `enforce_con_db(2)` 之间若发生异常,可能导致连接状态未恢复,影响后续请求。 | 使用 `try...finally` 确保连接状态必定还原。 | `try { $this->enforce_con_db(); /* 业务 */ } finally { $this->enforce_con_db(2); }` | | 🟡 建议 | 文件顶部 L1-3 | **冗余的 CI 实例获取**:模型类内部已继承自 CI 核心,无需在文件顶部使用 `$CI = &get_instance();`。 | 删除顶部 `$CI = &get_instance();` 及 `$CI->load->model()`,统一使用 `$this->load->model()`。 | 直接删除前两行代码 | | 🟡 建议 | 全局/多处 | **魔法数字与硬编码**:`'1'`, `'2'`, `'8'`, `'9'` 等状态值散落在逻辑中,降低可读性与维护性。 | 提取为类常量或枚举(PHP 8.1+)。 | `const TYPE_INCOME = '1'; const TYPE_REFUND = '2';` | --- ## 3. 总结与行动建议 ### 🚨 优先修复的关键问题 1. **修复 SQL 注入漏洞**:立即将 `$pay_platform_where` 的字符串拼接改为参数绑定或强制 `(int)` 类型转换。若底层自定义模型不支持绑定,请改用 CI 原生 `$this->db->where()` 或 `$this->db->where_in()`。 2. **消除 N+1 查询**:将循环内的单条查询改为批量查询,这是提升报表性能最直接有效的手段。 3. **完善参数校验**:对 `start_time`、`end_time`、`json_decode` 输入进行严格校验,避免脏数据穿透至数据库层。 ### 🛠 后续重构与优化方向 #### ① N+1 查询优化示例(替换原 `foreach` 中的预订查询逻辑) ```php // 1. 收集所有需要查询的预订单号 $book_order_ids = []; foreach ($data as $v) { if ($v['order_type'] == '1') { $oid = $v['order_id']; if ($v['type'] == '2') { $oid = preg_replace('/\(退款单号:.*\)$/', '', $oid); } $book_order_ids[] = $oid; } } // 2. 批量查询并建立映射 $book_orders_map = []; if (!empty($book_order_ids)) { $book_orders = $this->ahead_book_order_model->get_data_by_ids( array_unique($book_order_ids), '_id,_shop_name,_arrival_time,_end_time', '_id' ); $book_orders_map = $book_orders ?: []; } // 3. 循环内直接映射,零额外查询 foreach ($data as &$v) { // ... 其他逻辑 ... if ($v['order_type'] == '1') { $book_order_id = $v['order_id']; if ($v['type'] == '2') { $book_order_id = preg_replace('/\(退款单号:.*\)$/', '', $book_order_id); } if (isset($book_orders_map[$book_order_id])) { $b = $book_orders_map[$book_order_id]; $v['book_info'] = [ 'book_order_id' => $book_order_id, 'shop_name' => $b['_shop_name'], 'room_name' => $v['room_name'], 'start_time' => date('Y-m-d H:i', $b['_arrival_time']), 'end_time' => date('Y-m-d H:i', $b['_end_time']), 'time_str' => minToStr(0, $b['_arrival_time'], $b['_end_time']), 'user_name' => filter_emoji(filterExcelSpecialChars($v['user_name'])) ]; } } // ... } unset($v); ``` #### ② 架构与规范建议 - **依赖注入/懒加载**:频繁调用的模型(如 `ahead_yc_shop_model`, `ahead_user_model`)建议在 `__construct()` 中统一加载,或封装为私有方法实现单例缓存。 - **数据库连接管理**:`enforce_con_db()` 属于自定义连接池/分组切换逻辑,务必配合 `try-finally` 使用,防止未捕获异常导致连接泄漏。 - **现代 PHP 特性**:若环境支持 PHP 7.4+,建议为方法添加返回类型声明(如 `: array`),并启用 `declare(strict_types=1);` 提升类型安全。 - **全局函数依赖**:代码中大量使用 `filter_emoji`, `filterExcelSpecialChars`, `change_number_format` 等全局函数。建议将其封装至独立的 `Helper` 类或 `Service` 层,便于单元测试与依赖管理。 > 💡 **局限性说明**:由于未提供底层 `Report_model` 中 `select()`, `count()`, `enforce_con_db()` 的具体实现,部分 SQL 生成逻辑与连接切换行为需结合源码二次验证。建议审查时同步确认自定义查询构建器是否默认启用 `escape()` 或 PDO 预处理。 --- *此 Issue 由代码审查服务自动创建*
TEXT
milestone_id
INTEGER
priority
INTEGER
is_closed
INTEGER
is_pull
INTEGER
num_comments
INTEGER
ref
TEXT
deadline_unix
INTEGER
created_unix
INTEGER
updated_unix
INTEGER
closed_unix
INTEGER
is_locked
INTEGER NOT NULL (default 0
content_version
INTEGER NOT NULL (default 0
time_estimate
INTEGER NOT NULL (default 0
Update
Cancel