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 589 from issue
id
589
repo_id
21
index
265
poster_id
1
original_author
original_author_id
0
name
🔍 代码审查报告:pay-260616 - 卡券续费可用时间为0的bug
content
## 自动代码审查报告 **分支**: pay-260616 **提交**: `e7d1ca4a8
## 自动代码审查报告 **分支**: pay-260616 **提交**: `e7d1ca4a8958a09bd6437965fbb58da98fdab24f` **提交人**: LITTLEMAIDI (11833999+littlemaidi@user.noreply.gitee.com) **时间**: 2026-06-08 14:39:09 --- ## 1. 审查摘要 - **代码质量评分**:6.5 / 10 分 - **总体评价**:业务逻辑覆盖较全面,数据关联与分页处理基本合理。但存在**高危 SQL 注入漏洞**、**引用遍历删除元素失效**等严重逻辑缺陷,且多处价格计算逻辑高度重复,未遵循 DRY 原则。代码风格偏向传统 CI3 写法,缺乏类型约束与异常保护机制。 - **风险等级**:🔴 高 > 📌 **框架说明**:代码结构(`get_instance()`、`$this->load->model()`、`system/` 目录等)高度符合 **CodeIgniter 3** 规范。若实际运行环境确为 `phpci`,请确认底层是否完全兼容 CI3 的 Loader 与 DB 组件。以下审查基于 CI3/PHP 通用最佳实践。 ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `get_book_package_list` / `get_hot_sale_top5` | **SQL 注入漏洞**:直接拼接 `$shop_name`、`$param['special_merchant_id']` 等外部参数到原生 SQL 中,未做转义或参数绑定。 | 使用 CI Query Builder 或 `$this->db->escape()` / `$this->db->escape_like_str()` 处理动态参数。 | `$shop_name = $this->db->escape_like_str($shop_name);`<br>`$sql .= " AND shop._name LIKE '%{$shop_name}%'";` | | 🔴 严重 | `get_package_price_list` / `get_screen_list` | **引用遍历删除失效**:`foreach ($list as &$row) { unset($row); continue; }` 仅断开引用,**不会从原数组中移除元素**,导致脏数据返回。 | 改用键值遍历并直接操作原数组,或使用 `array_filter`。 | `foreach ($list as $key => &$row) {`<br>` if ($book_arrival_time < $order_end_time) {`<br>` unset($list[$key]);`<br>` continue;`<br>` }`<br>`}` | | 🔴 严重 | `get_package_price_list` / `get_screen_list` | **原始 SQL 条件拼接**:`$where['where'] = ["((info._start_time <= $time ..."]` 直接插值,若 `$businessDay` 等来源不可控,易引发注入或语法错误。 | 使用框架提供的 `where()` 方法配合转义,或至少使用 `$this->db->escape()`。 | `$escaped_day = $this->db->escape($businessDay);`<br>`$where['where'] = ["FIND_IN_SET({$escaped_day}, _disabled_date) = ''"];` | | 🟠 警告 | `get_package_by_fields` / `get_book_package_detail` | **模型状态未安全恢复**:`$this->set_table_name()` 修改了内部表名,若中间抛出异常,后续查询将使用错误的表名。 | 使用 `try-finally` 确保状态回滚,或避免在方法内修改全局状态。 | `try {`<br>` $this->set_table_name($table_name . ' info');`<br>` $result = $this->select(...);`<br>`} finally {`<br>` $this->set_table_name($table_name);`<br>`}` | | 🟠 警告 | 全局多处 | **重复的价格/折扣计算逻辑**:`get_package_price_list`、`get_price_set_detail` 中会员折扣、VIP 价格计算代码几乎完全一致,维护成本高。 | 抽取为私有方法 `calculate_vip_price($row, $vip_level, $discount_rate)` 统一调用。 | `private function apply_discount($price, $rate, $status) {`<br>` return $status == 1 && $rate < 10 ? $price * ($rate / 100) : $price;`<br>`}` | | 🟠 警告 | `get_package_price_list` / `get_screen_list` | **直接修改 CI 实例属性**:`$CI->operational_scene = ...` 破坏了框架封装性,易引发全局状态污染或并发冲突。 | 改用 `$this->config->set_item()`、Session 或通过方法参数显式传递上下文。 | `$this->config->set_item('operational_scene', $book_order['_operational_scene']);` | | 🟡 建议 | `get_package_price_list` | **浮点数直接比较**:`$row['vip_level1_price']<0.01` 在货币计算中可能因精度丢失导致误判。 | 使用 `bccomp()` 或先 `round($val, 2)` 再比较。 | `if (bccomp((string)$row['vip_level1_price'], '0.01', 2) < 0) { ... }` | | 🟡 建议 | `get_screen_list` | **数组越界风险**:`$res[($v['package_type'] - 1)]['data'][] = $v;` 假设 `package_type` 仅为 1/2/3,若数据异常将触发 Warning 或覆盖数据。 | 增加边界校验或使用 `switch` 映射,避免硬编码索引。 | `$idx = $v['package_type'] - 1;`<br>`if (isset($res[$idx])) $res[$idx]['data'][] = $v;` | ## 3. 总结与行动建议 ### 🚨 优先修复的关键问题 1. **彻底修复 SQL 注入**:所有原生 SQL 拼接处必须替换为 Query Builder 或严格转义。特别是 `get_book_package_list` 和 `get_hot_sale_top5` 中的 `$shop_name` 和 `$param['special_merchant_id']`。 2. **修正 `unset` 逻辑缺陷**:立即将 `foreach ($list as &$row) { unset($row); }` 改为基于键的删除 `unset($list[$key])`,否则过滤逻辑完全失效。 3. **安全恢复模型状态**:为所有调用 `set_table_name()` 或 `set_select_db()` 的方法包裹 `try-finally`,防止异常导致后续请求串表或串库。 ### 🛠 后续重构与优化方向 - **逻辑抽象与 DRY 原则**:将会员折扣计算、价格格式化、节假日价格重置等重复代码提取为 `private` 辅助方法或 Trait,降低维护成本。 - **统一数据访问层**:逐步淘汰原生 `$this->db->query($sql)`,全面转向 CI Query Builder。不仅提升安全性,还能自动处理表前缀、字段转义与驱动兼容。 - **类型声明与 PSR-12 规范**:为方法参数与返回值添加 PHP 7+ 类型提示(如 `array $ids`, `int $type`),统一缩进、空格与命名规范,提升 IDE 静态分析能力。 - **上下文传递规范化**:停止通过 `$CI->xxx` 动态挂载属性传递业务状态。建议采用依赖注入、配置项或显式参数传递,确保代码可测试、可追踪。 > ⚠️ **局限性说明**:提供的代码在 `get_book_package_list_group_by_shop` 方法末尾被截断(`$special_city_id = [2, 3, 4, 5, 34,`)。若后续逻辑包含更多原生 SQL 或状态切换,请同步补充审查。建议结合单元测试覆盖核心价格计算与过滤分支,确保重构后业务一致性。 --- *此 Issue 由代码审查服务自动创建*
...
milestone_id
0
priority
0
is_closed
0
is_pull
0
num_comments
0
ref
deadline_unix
0
created_unix
1780900749
updated_unix
1780900749
closed_unix
0
is_locked
0
content_version
0
time_estimate
0
Delete
Cancel