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 401 in issue
id
Primary key.
INTEGER NOT NULL
repo_id
INTEGER
index
INTEGER
poster_id
INTEGER
original_author
TEXT
original_author_id
INTEGER
name
🔍 代码审查报告:app-260519 - 111
TEXT
content
## 自动代码审查报告 **分支**: app-260519 **提交**: `da80aa8372565576d62e8cead61d9d5e542af8a3` **提交人**: zhangjunnan (121158035@qq.com) **时间**: 2026-05-28 15:15:21 --- ## 1. 审查摘要 - **代码质量评分**:4.5 / 10 分 - **总体评价**:该模型类承载了大量订单查询、报表统计与分页逻辑,业务覆盖面广。但代码存在**严重的 SQL 注入隐患**、**硬编码敏感信息**、**SQL 语法错误**及**MVC 职责越界**问题。大量使用字符串拼接构建 SQL、缺乏类型约束、模型层直接进行 `json_encode` 序列化,导致可维护性、安全性与扩展性较低。 - **风险等级**:🔴 高 > 📌 **框架说明**:提供的目录结构、加载方式(`$this->load->model()`、`$this->db->query()`)高度符合 **CodeIgniter 3** 规范。若 `phpci` 为内部定制或衍生框架,以下审查建议仍基于 CI3 核心机制与 PHP 通用最佳实践。若存在差异,请以官方文档为准。 > ⚠️ **局限性提示**:代码在 `get_goods_sales` 方法处意外截断,部分权限校验与关联查询逻辑未能完整评估。 --- ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | 全局多处方法(如 `get_order_manage`, `get_amount_info` 等) | **SQL 注入漏洞**:大量依赖外部传入的 `$addsql` 字符串直接拼接至 SQL 语句中,未使用参数绑定或 Query Builder 过滤。攻击者可构造恶意条件绕过权限或拖库。 | 彻底废弃 `$addsql` 拼接模式。统一改用 CI Query Builder 链式调用,或严格使用 `?` 占位符+参数数组。 | `$this->db->where('_merchant_id', $merchantId)->where('_status !=', 0)->get('ahead_yc_order')->result_array();` | | 🔴 严重 | `get_new_add_people_trend_data` | **SQL 语法错误**:子查询 `NOT IN (select DISTINCT(_ahead_user_id))` 缺失数据源表名,执行必报 `1241 - Operand should contain 1 column(s)` 或语法错误。 | 补全子查询表名及业务条件,明确对比范围。 | `... AND _ahead_user_id NOT IN (SELECT _ahead_user_id FROM ahead_user_buy_log WHERE _is_first_buy = 0)` | | 🔴 严重 | 类属性 `public $encrypt = "Vs!Fs7VT";` | **敏感信息硬编码**:加密密钥直接暴露在类属性中,易随代码库泄露,且多环境部署时无法差异化配置。 | 移至 `application/config/config.php` 或 `.env`,通过 `$this->config->item()` 读取。 | `private $encryptKey; public function __construct() { parent::__construct(); $this->encryptKey = config_item('order_encrypt_key'); }` | | 🟠 警告 | `get_business` 方法 | **类型转换与精度隐患**:`number_format($tmp['actual_pay'] / $sum, 4) * 100` 先格式化字符串再乘 100,依赖 PHP 隐式类型转换,可能丢失精度或触发 `E_WARNING`。 | 先完成浮点运算,最后统一格式化输出。 | `$percent = $sum > 0 ? ($tmp['actual_pay'] / $sum) * 100 : 0; $tmp['percent'] = number_format($percent, 2);` | | 🟠 警告 | `cjy_consumption_trend_data`, `cjy_people_trend_data` | **Query Builder 滥用字符串拼接**:`$this->db->where('_timestamp between "' . $start_date . '" and "' . $end_date . '"')` 破坏框架防注入机制,且日期格式依赖外部输入。 | 使用 CI 原生范围查询语法,确保类型安全。 | `$this->db->where('_timestamp >=', $start_date)->where('_timestamp <=', $end_date);` | | 🟠 警告 | `insert_room_count`, `insert_room_detail` | **DB 驱动兼容性风险**:`$this->db->where(implode(" and ", $where))` 传入完整 SQL 片段字符串。新版 CI 严格校验 `where()` 参数格式,可能抛出异常。 | 拆分为多次 `where()` 调用或使用数组条件。 | `$this->db->where('a._status !=', 0)->where_not_in('a._merchant_id', [11,107,150,110]);` | | 🟠 警告 | `get_order_manage_by_page` | **索引提示滥用**:`force index(_merchant_id)` 基于 `strpos($addsql, '_shop_id')` 硬编码触发,缺乏执行计划验证,可能导致优化器选择次优路径。 | 移除硬编码 `force index`,依赖数据库优化器;或通过 `EXPLAIN` 分析后建立复合索引 `_merchant_id, _shop_id, _timestamp`。 | 直接删除 `force index` 逻辑,确保数据库索引设计合理。 | | 🟡 建议 | `get_consumption_trend_data` 等多处 | **模型层职责越界**:模型中直接调用 `json_encode()` 返回数据,违反 MVC 分离原则,增加 Controller 解析负担且不利于单元测试。 | 模型仅返回标准数组/对象,JSON 序列化统一在 Controller 或 API 响应层处理。 | `return $this->db->query($sql)->result_array();` | | 🟡 建议 | 全局 | **违反 PSR-12 规范**:变量命名混乱(`$_merchant_id`, `addsql`),缺少类型声明,方法过长且包含大量注释掉的调试代码。 | 遵循 PSR-12,使用驼峰命名,添加 PHP 8 类型提示,清理死代码,拆分超长方法。 | `public function getOrderInfo(int $merchantId, string $orderId = '', ...): array` | --- ## 3. 总结与行动建议 ### 🔑 优先修复的关键问题 1. **全面重构 SQL 构建逻辑**:立即停止使用 `$addsql` 字符串拼接。建立统一的查询条件构建器(如 `buildWhereConditions(array $params)`),所有外部输入必须经过类型转换或白名单校验后传入 Query Builder。 2. **修复致命语法错误**:修正 `get_new_add_people_trend_data` 中的子查询缺失表名问题,该错误会导致相关报表接口直接 500 崩溃。 3. **移除硬编码密钥**:将 `$encrypt` 移至配置文件或环境变量,并通过依赖注入或配置项读取,符合安全合规要求。 ### 🛠 后续重构与优化方向 - **架构分层**:当前 Model 承担了“数据查询 + 业务计算 + 分页逻辑 + JSON 序列化”多重职责。建议引入 **Service 层** 处理复杂计算与分页状态,Model 仅负责纯净的数据存取。 - **统一分页组件**:代码中多处手动计算 `offset`、`totalPage`、`pageStatus`。建议封装为独立的 `PaginationService` 或直接使用 CI 原生 `Pagination` 库,避免重复造轮子。 - **类型安全与现代化**:逐步引入 PHP 7.4+/8.0 类型声明(如 `int`, `string`, `array`, `?string`),利用 IDE 静态检查提前拦截类型错误。 - **数据库性能调优**:针对 `ahead_yc_order` 大表,建议对高频查询字段 `(_merchant_id, _shop_id, _timestamp, _status)` 建立复合索引。移除 `force index` 硬编码,依赖 MySQL 优化器动态选择。 - **清理历史债务**:移除所有 `//echo $this->db->last_query();die;`、`//edit by nan` 等调试注释,保持代码库整洁。 > 💡 **实施建议**:由于该类耦合度较高,建议采用**渐进式重构**。优先修复安全漏洞与语法错误,随后将高频查询方法抽离为独立 Service,并编写单元测试覆盖核心统计逻辑。若需针对 `phpci` 框架特定生命周期(如事件钩子、缓存驱动)进行深度适配,请提供框架官方文档或核心基类定义以便进一步审查。 --- *此 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