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 393 from issue
id
393
repo_id
22
index
41
poster_id
1
original_author
original_author_id
0
name
🔍 代码审查报告:app-260519 - 预买包段转房增加房态判断。
content
## 自动代码审查报告 **分支**: app-260519 **提交**: `cf3bb0779
## 自动代码审查报告 **分支**: app-260519 **提交**: `cf3bb07792eb4726b58d4c3e0e7b058dec020c48` **提交人**: zhangjunnan (121158035@qq.com) **时间**: 2026-05-28 10:57:03 --- ## 1. 审查摘要 - **代码质量评分**:4/10 分 - **总体评价**:该文件为典型的遗留 CodeIgniter(注:根据目录结构推断 `phpci` 实为 `CodeIgniter`)模型代码。业务逻辑覆盖全面,但存在严重的 SQL 注入隐患、硬编码安全密钥、SQL 语法错误及性能瓶颈。代码风格陈旧,未充分利用框架的 Query Builder 特性,且 MVC 分层边界模糊(如在模型层直接 `json_encode`)。 - **风险等级**:🔴 高 ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `get_new_add_people_trend_data` (~L238) | **SQL 语法/逻辑错误**:子查询 `NOT IN (select DISTINCT(_ahead_user_id))` 缺失表名,执行将直接报错或返回全量数据,导致统计完全失真。 | 补全子查询表名与关联条件,确保逻辑闭环。 | `NOT IN (SELECT _ahead_user_id FROM ahead_yc_order WHERE _merchant_id = ? AND _status = 1)` | | 🔴 严重 | `refund` 方法 (~L380) | **硬编码安全密钥**:`md5(... . '1441600902')` 等签名盐值硬编码在代码中,且使用已淘汰的 MD5。一旦泄露将导致支付接口被伪造调用。 | 将盐值移至 `config` 或环境变量,升级至 `hash_hmac('sha256', ...)`。 | `$salt = config_item('refund_salt'); $data['refund_key'] = hash_hmac('sha256', $order_info['_id'] . $order_info['_trade_no'], $salt);` | | 🔴 严重 | 多处方法 (如 `get_order_manage`, `get_amount_info` 等) | **SQL 注入高危**:`$addsql` 变量通过字符串直接拼接进 SQL 语句。若该参数来自用户输入或未经严格白名单过滤,将导致严重注入漏洞。 | **彻底废弃 `$addsql` 拼接模式**,全面改用 CI Query Builder 的安全方法链。 | `$this->db->where('_status !=', 0)->where_in('_shop_id', $shop_ids)->get('ahead_yc_order');` | | 🟠 警告 | `get_consumption_trend_data` 等多处 | **模型层越权处理 JSON**:在模型中直接 `json_encode($this->db->query(...)->result_array())` 返回,违反 MVC 分层原则,增加内存开销且不利于后续数据二次处理。 | 移除 `json_encode()`,直接返回数组。JSON 序列化应在 Controller 或 API 响应层统一处理。 | `return $result['data'] ? $result : false; // 移除 json_encode` | | 🟠 警告 | `get_business` 方法 (~L445) | **类型转换与精度隐患**:`number_format()` 返回字符串,直接 `* 100` 会触发隐式类型转换;且 `$sum` 为 0 时的边界处理不够严谨。 | 使用原生浮点运算配合 `round()`,提升精度与可读性。 | `$tmp['percent'] = $sum > 0 ? round(($tmp['actual_pay'] / $sum) * 100, 2) : 0;` | | 🟠 警告 | `cjy_get_other_order_info` (~L310) | **输入过滤过时**:使用 `addslashes()` 防注入已不符合现代 PHP 安全标准;正则校验逻辑复杂且易被绕过。 | 使用 CI 内置的 `$this->db->escape()` 或参数绑定;统一使用 Query Builder 处理 `LIKE`。 | `$this->db->like('_id', $_order_id, 'after');` | | 🟡 建议 | 全局 | **违反 PSR-12 规范**:大量使用 `array()`、变量命名风格混乱(`$_merchant_id` vs `$merchant_id`)、存在大量注释代码块、缺乏类型声明。 | 升级至 PHP 7.4+/8.x 语法,使用 `[]`、添加参数类型提示、清理废弃注释、统一驼峰/下划线命名规范。 | `public function get_order_info(int $merchantId, string $orderId = '', ...): array` | | 🟡 建议 | `__construct` 及多处 `load->model()` | **框架适配不佳**:在业务方法中频繁动态 `$this->load->model()` 和 `$this->config->load()`,增加不必要的 I/O 开销。 | 依赖模型应在 `__construct()` 中预加载,或通过 CI 的 `autoload.php` 配置。 | `public function __construct() { parent::__construct(); $this->load->model('ahead_yc_merchant_user_model'); }` | ## 3. 总结与行动建议 ### 🚨 优先修复的关键问题 1. **修复 SQL 语法错误**:立即修正 `get_new_add_people_trend_data` 中的子查询缺失表名问题,否则该接口将直接崩溃。 2. **消除 SQL 注入风险**:全面重构 `$addsql` 拼接逻辑。建议封装一个统一的查询构建器方法,或使用 CI 的 `where()`、`where_in()`、`group_by()` 链式调用替代字符串拼接。 3. **移除硬编码密钥**:将 `refund` 方法中的 MD5 盐值及加密串 `$encrypt` 迁移至 `application/config/config.php` 或 `.env` 文件中,并升级哈希算法。 ### 🛠 后续重构与优化方向 1. **架构分层优化**: - **Model 层**:仅负责数据查询与基础组装,禁止 `json_encode`、禁止直接输出/跳转、禁止硬编码业务规则。 - **Controller/Service 层**:负责参数校验、权限控制、JSON 序列化及复杂业务编排。 2. **性能调优**: - 将 `IN ($shop_ids)` 字符串拼接改为 `$this->db->where_in()`,便于框架底层进行参数绑定与查询缓存。 - 针对高频统计接口(如数据魔方系列),建议引入 **物化视图** 或 **定时任务预计算**,避免每次请求都执行 `SUM()`、`COUNT(DISTINCT)` 等重型聚合查询。 - 移除 `force index` 硬编码,交由 MySQL 优化器根据实际数据分布自动选择索引,或通过 `EXPLAIN` 验证后在数据库层维护。 3. **代码规范升级**: - 启用 `phpcs` 配合 `PSR-12` 规则进行静态扫描。 - 逐步引入 PHP 类型声明(`declare(strict_types=1);`、参数类型、返回类型),提升代码健壮性与 IDE 提示体验。 - 清理所有 `// echo $this->db->last_query();` 等调试注释,改用日志系统(如 Monolog 或 CI 内置 Log)记录慢查询。 > ⚠️ **局限性说明**:您提供的代码在末尾 `get_goods_sales` 方法处被截断(`$this->ahead_yc_merchant_user_model->get_one(['_id' => $para`),未能完整审查该方法的权限校验与分页逻辑。若需对该部分进行深度评估,请补充完整代码。同时,本审查基于 `CodeIgniter 3` 架构假设,若实际框架版本不同,部分 Query Builder 用法需相应调整。 --- *此 Issue 由代码审查服务自动创建*
...
milestone_id
0
priority
0
is_closed
0
is_pull
0
num_comments
0
ref
deadline_unix
0
created_unix
1779937023
updated_unix
1779937023
closed_unix
0
is_locked
0
content_version
0
time_estimate
0
Delete
Cancel