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 176 in issue
id
Primary key.
INTEGER NOT NULL
repo_id
INTEGER
index
INTEGER
poster_id
INTEGER
original_author
TEXT
original_author_id
INTEGER
name
🔍 代码审查报告:pay-260519 - 1
TEXT
content
## 自动代码审查报告 **分支**: pay-260519 **提交**: `aa880e50672277db9650328ede3b2b261906d202` **提交人**: LITTLEMAIDI (11833999+littlemaidi@user.noreply.gitee.com) **时间**: 2026-05-19 13:20:10 --- ## 1. 审查摘要 - **代码质量评分**:5.5 / 10 分 - **总体评价**:代码实现了较为复杂的门店业务逻辑,但存在多处严重的安全隐患(SQL注入)、状态管理缺陷(类属性污染)、MVC 职责越界以及性能瓶颈(N+1查询、PHP层距离计算)。部分代码未遵循 CI 框架生命周期规范,且命名与硬编码缺乏一致性。需进行系统性重构。 - **风险等级**:🔴 高 > 📌 **框架说明**:根据目录结构(`system/`, `application/`)及语法特征(`get_instance()`, `$this->load->model()`, `$this->db->`),判定该代码基于 **CodeIgniter 3.x** 架构。以下审查与建议均基于 CI3 最佳实践。若 `phpci` 为内部定制框架,请对照其官方文档调整组件调用方式。 ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `get_community_shop_list` 约第 280 行 | **变量名拼写错误**:使用未定义的 `$param['bookFrom']`,实际参数名为 `$params`。将导致 PHP Notice 且业务逻辑失效。 | 修正为 `$params['bookFrom']`,并增加类型校验。 | `if (!empty($params['bookFrom'])) { ... }` | | 🔴 严重 | `get_date_shop_no_business_time` 约第 560 行 | **类属性状态污染**:使用 `$this->shop_no_business_time` 累加数据。同一请求多次调用该方法会导致数据无限叠加,引发内存泄漏与逻辑错乱。 | 改为局部变量,方法结束后自动销毁。 | `$shop_no_business_time = [];`<br>`// 后续逻辑中替换 $this->shop_no_business_time` | | 🔴 严重 | 多处 (`get_community_shop_list`, `get_shop_list_order_by_distance` 等) | **SQL 注入漏洞**:`FIND_IN_SET({$operational_scene}, ...)` 与 `LIKE '%{$shop_name}%'` 直接拼接用户输入,未做转义或参数化。 | 使用 CI 查询构建器绑定参数,或严格过滤输入类型。 | `$this->db->where("FIND_IN_SET(?, shop._operational_scene)", (int)$operational_scene);`<br>`$shop_name = $this->db->escape_like_str($shop_name);` | | 🟠 警告 | 文件顶部 第 8-9 行 | **违反框架生命周期**:在文件作用域直接调用 `get_instance()` 加载模型。CI 尚未完全初始化时会引发 Fatal Error。 | 移除文件顶部代码,统一在 `__construct()` 中加载依赖。 | `public function __construct() { parent::__construct(); $this->load->model('Simple_model'); }` | | 🟠 警告 | `getAliAuthInfo` 约第 180 行 | **变量拼写错误**:`$this->db->select($filed)` 中 `$filed` 未定义,应为 `$fields`。 | 修正变量名,避免查询字段为空。 | `$this->db->select($fields)` | | 🟠 警告 | `get_shop_list_order_by_distance` 约第 350 行 | **原始 SQL 拼接风险**:`_id in (...)` 与 `FIELD()` 循环拼接未校验数据类型,若传入非数字将破坏 SQL 语法或引发注入。 | 使用 `array_map('intval', $arr)` 过滤,并改用 CI Query Builder 或严格转义。 | `$safe_ids = implode(',', array_map('intval', $shop_id_arr_order_distance));`<br>`$sql .= " AND _id IN ({$safe_ids})";` | | 🟠 警告 | 多个列表方法 (`get_info`, `get_community_shop_list` 等) | **N+1 查询性能瓶颈**:在 `foreach` 循环中逐条调用 `get_miniprogram_consumption_methods` 等模型方法,数据量大时数据库压力剧增。 | 提取 ID 列表批量查询,或引入 Redis/内存缓存。 | `$shop_ids = array_column($shop_data, 'shop_id');`<br>`$configs = $this->ahead_shop_config_second_model->get_batch_by_shop_ids($shop_ids);` | | 🟡 建议 | 全局 | **MVC 职责越界**:Model 中直接调用 `throwError()` / `showErrorView()`。Model 应仅负责数据存取,视图与异常响应应由 Controller 处理。 | 改为抛出 `Exception` 或返回错误码,由 Controller 统一拦截处理。 | `if (empty($data)) { throw new \Exception('门店错误', 404); }` | | 🟡 建议 | 全局 | **命名规范与魔法数字**:方法名混用驼峰(`getAliAuthInfo`)与下划线;大量使用 `86400`, `1`, `-1` 等硬编码。 | 统一使用下划线命名法(CI 规范);定义类常量提升可读性。 | `const STATUS_ACTIVE = 1;`<br>`const TEST_SHOP_FLAG = -1;`<br>`public function get_ali_auth_info($condition)` | | 🟡 建议 | `get_cache_shop_data` 约第 100 行 | **缓存序列化隐患**:`json_encode($shop_data)` 未处理失败情况,且 `$redis->close()` 可能破坏连接池复用。 | 增加 JSON 编码校验;使用 CI 内置 Cache 驱动管理连接。 | `if ($json === false) { log_message('error', 'Redis cache encode failed'); return $shop_data; }` | ## 3. 总结与行动建议 ### 🔑 优先修复的关键问题 1. **修复 SQL 注入**:立即替换所有字符串拼接的 SQL 条件,改用 CI Query Builder 的 `where()`, `where_in()`, `like()` 或参数化绑定。特别是 `FIND_IN_SET` 和 `LIKE` 场景。 2. **消除状态污染**:将 `get_date_shop_no_business_time` 中的 `$this->shop_no_business_time` 改为局部变量,避免并发或多次调用时的数据交叉污染。 3. **修正致命拼写错误**:修复 `$param` vs `$params` 及 `$filed` vs `$fields`,防止运行时崩溃。 4. **规范框架初始化**:移除文件顶部的 `get_instance()` 调用,将依赖模型加载移至 `__construct()`。 ### 🛠 后续重构与优化方向 - **架构分层**:严格遵循 MVC。Model 仅返回数据或抛出 `Exception`,将 `throwError`/`showErrorView` 移至 Controller 或全局异常处理器。 - **性能优化**: - **批量查询**:将循环内的单条查询改为 `WHERE IN` 批量获取,或使用 Redis Hash 缓存门店配置。 - **距离计算下沉**:PHP 层循环计算经纬度距离(Haversine)消耗 CPU。建议在 MySQL 中使用空间函数或 `ST_Distance_Sphere`,或在查询时直接返回排序结果。 - **代码规范**: - 统一方法命名为 `snake_case`。 - 将 `public` 属性改为 `protected`,避免外部随意篡改。 - 提取魔法数字为类常量(如 `const CACHE_TTL = 86400;`)。 - **缓存策略升级**:建议弃用自定义 `get_aliyun_redis_conn()`,改用 CI 官方 `Cache` 驱动(`$this->load->driver('cache', ['adapter' => 'redis'])`),以获得更好的连接池管理与序列化支持。 > 💡 **提示**:若需对 `get_shop_list_order_by_distance` 中的 `FIELD()` 排序进行深度优化,可考虑在数据库层面使用临时表或 `CASE WHEN` 语句,避免在 PHP 中动态拼接超长 SQL。如有特定业务约束无法修改,请确保所有传入参数经过 `intval()` 或白名单过滤。 --- *此 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