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 555 from issue
id
555
repo_id
21
index
241
poster_id
1
original_author
original_author_id
0
name
🔍 代码审查报告:pay-260616 - 1
content
## 自动代码审查报告 **分支**: pay-260616 **提交**: `cbaafe309
## 自动代码审查报告 **分支**: pay-260616 **提交**: `cbaafe30977d49fb302e42774ef10cbb7da9424a` **提交人**: LITTLEMAIDI (11833999+littlemaidi@user.noreply.gitee.com) **时间**: 2026-06-05 13:31:39 --- ## 1. 审查摘要 - **代码质量评分**:6.5 / 10 分 - **总体评价**:代码实现了较为完整的订单与套餐业务逻辑,但存在明显的架构与规范问题。整体偏向传统 CI3 风格(非 phpci),存在多处 SQL 拼接风险、全局状态污染、逻辑冗余及超长方法。部分核心业务(如支付路由、优惠券计算)耦合度过高,缺乏防御性编程与精度控制。 - **风险等级**:🔴 高(存在 SQL 注入隐患、并发状态串扰风险、越权操作依赖隐式实现) - **⚠️ 框架说明**:提交代码的架构特征(`BASEPATH`、`$this->load->model()`、`get_instance()`、`$this->db`)明确属于 **CodeIgniter 3 (CI3)**,而非 `phpci`。以下审查将基于 CI3 最佳实践与通用 PHP 规范进行。若实际项目确为 `phpci`,请核对框架加载机制与生命周期差异。 ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `Ahead_room_package_infos_model.php` ~L108, L285 | **SQL 注入漏洞**:`$shop_name`、`$time`、`$businessDay` 等外部/动态变量直接拼接进 `where` 原始 SQL 字符串。CI 查询构建器不会自动转义 `where` 数组中的原始字符串。 | 严格使用 CI Query Builder 的 `like()`、`where()` 方法,或手动调用 `$this->db->escape()` 进行转义。 | `$this->db->like('shop._name', $shop_name);`<br>`$where['where'] = ["FIND_IN_SET('{$this->db->escape($businessDay)}', _disabled_date) = ''"];` | | 🔴 严重 | `Order.php` ~L115, L185 | **全局状态污染/并发串扰**:通过 `$CI =& get_instance(); $CI->room_id = ...` 直接修改 CI 超全局对象属性。在 PHP-FPM/CGI 多请求并发下,极易导致不同用户请求间数据覆盖。 | 禁止修改 `$CI` 属性。上下文数据应通过方法参数传递,或封装至独立的 `Context/Request` 对象中。 | `// 移除 $CI->room_id = ...`<br>`$param['room_id'] = $this->room_id;`<br>`$order_add_res = $this->neworderservice->createOrderWeb($param);` | | 🟠 警告 | `Ahead_room_package_infos_model.php` ~L145 | **逻辑缺陷**:`foreach ($list as &$row) { ... unset($row); }` 仅销毁引用变量 `$row`,**无法从原数组中移除元素**,导致无效数据继续参与后续计算。 | 使用键值遍历并 `unset($list[$key])`,或改用 `array_filter`。 | `foreach ($list as $key => &$row) {`<br>` if ($book_arrival_time < $order_end_time) { unset($list[$key]); continue; }`<br>`}` | | 🟠 警告 | `Ahead_yc_order_model.php` ~L138 | **潜在致命错误**:在 `get_detail()` 中调用 `$this->ahead_yc_order_model->get_one()`。类内部不应通过完整类名调用自身,且该属性未定义,将触发 `Undefined property` 错误。 | 改为 `$this->get_one()` 或 `self::get_one()`(若为静态)。 | `$before_order_info_data = $this->get_one(['_id' => $order_info['before_order_id']]);` | | 🟠 警告 | `Order.php` ~L225 | **越权风险 (IDOR)**:`deleteOrder` 仅校验 `order_id` 非空,未显式校验订单归属权。若 Model 层未强制绑定 `uid` 过滤,攻击者可遍历删除他人订单。 | Controller 层增加显式归属权校验,或要求 Model 返回操作结果状态。 | `$res = $this->ahead_yc_order_model->delete_one($order_id, $this->uid);`<br>`if ($res === false) $this->error_response('无权删除该订单');` | | 🟡 建议 | 全局多处 | **重复加载模型**:在方法内部多次调用 `$this->load->model()`。CI 虽会缓存实例,但影响可读性且增加 I/O 开销。 | 统一移至 `__construct()` 中加载,或采用按需懒加载(仅首次调用时加载)。 | `public function __construct() { parent::__construct(); $this->load->model(['ahead_yc_order_model', 'ahead_room_package_infos_model']); }` | | 🟡 建议 | `Ahead_user_reward_model.php` ~L250 | **浮点数精度丢失**:金额计算直接使用 `-`、`/` 运算符(如 `$goods_discount_rate / 10`),在 PHP 中可能产生 `0.09999999999999998` 等精度问题。 | 涉及金额计算统一使用 `bcsub()`、`bcmul()` 或 `round()`,并保留两位小数。 | `$actual_pay = round(bcsub($price_info['actual_pay'], $price_info['preferential_price'], 2), 2);` | | 🟡 建议 | `Order.php` ~L45 | **代码规范与可维护性**:存在大量 `//edit by nan 24.9.25` 等历史注释、魔法数字(如 `1, 2, 3, 4`)、单方法超 200 行,违反 PSR-12 与单一职责原则。 | 清理提交历史注释,提取私有方法(如 `validateRenewal()`, `processWxPay()`),使用常量/枚举替代魔法数字。 | `const PAY_PLATFORM_WX = 1;`<br>`if ($param['pay_platform'] == self::PAY_PLATFORM_WX) { ... }` | ## 3. 总结与行动建议 ### 🔑 优先修复的关键问题 1. **修复 SQL 注入风险**:立即替换所有直接拼接变量的 `where` 字符串,全面启用 CI Query Builder 或 `$this->db->escape()`。 2. **消除全局状态污染**:彻底移除 `$CI->xxx = ...` 的赋值操作,改用参数传递或独立上下文对象,防止高并发下的数据串扰。 3. **修正数组过滤逻辑**:将 `unset($row)` 替换为 `unset($list[$key])`,确保业务过滤逻辑按预期执行。 4. **修复类内自调用错误**:将 `$this->ahead_yc_order_model->get_one()` 修正为 `$this->get_one()`,避免运行时致命错误。 ### 🛠 后续重构与优化方向 - **架构解耦**:当前 Controller 承担了过多业务逻辑(参数校验、价格计算、支付路由、订单创建)。建议引入 `Service` 层(如 `OrderService`、`PaymentService`),Controller 仅负责请求接收与响应格式化。 - **防御性编程**:所有外部输入(`$param`、`$shop_name`、`$order_id`)应在入口处进行类型强转与白名单校验。支付回调与金额计算必须使用 `bcmath` 扩展。 - **规范与工程化**: - 严格遵循 PSR-12 规范,统一命名风格(推荐 `camelCase` 或 `snake_case` 二选一)。 - 使用 Git Commit Message 管理修改记录,移除代码中的 `//edit by xxx` 注释。 - 对超长方法(>100行)进行拆分,提升单元测试覆盖率。 - **框架适配说明**:若项目确需迁移至 `phpci` 或其他现代框架,建议将 `$this->load->model()` 替换为依赖注入(DI)容器管理,并采用 PSR-4 自动加载规范。当前代码结构较难直接平滑迁移,需逐步重构。 > 📌 **局限性提示**:`Ahead_user_reward_model.php` 与 `Ahead_yc_order_model.php` 末尾代码被截断,部分逻辑(如 `continue` 后的流程、`confirm_receipt` 完整实现)无法全面评估。建议补充完整代码以便进行更精准的边界条件与事务一致性审查。 --- *此 Issue 由代码审查服务自动创建*
...
milestone_id
0
priority
0
is_closed
0
is_pull
0
num_comments
0
ref
deadline_unix
0
created_unix
1780637499
updated_unix
1780637499
closed_unix
0
is_locked
0
content_version
0
time_estimate
0
Delete
Cancel