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 447 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-260616 - 1
TEXT
content
## 自动代码审查报告 **分支**: app-260616 **提交**: `968ac094f22bcb20643193e3370a6e503bce9135` **提交人**: LITTLEMAIDI (11833999+littlemaidi@user.noreply.gitee.com) **时间**: 2026-06-02 10:01:39 --- ## 1. 审查摘要 - **代码质量评分**:4/10 分 - **总体评价**:该模型类承载了大量核心订单查询、报表统计与分页逻辑,业务覆盖面广。但代码存在**严重的 SQL 注入风险**、**硬编码敏感信息**、**分页逻辑重复造轮子**及**模型职责过重**等问题。整体风格偏向早期 PHP 开发模式,未遵循现代 PSR-12 规范与框架最佳实践,可维护性与安全性亟待提升。 - **风险等级**:🔴 高 > 📌 **框架说明**:根据代码结构(`$CI =& get_instance()`、`$this->load->model()`、`system/` 目录规范等),该代码实际基于 **CodeIgniter 3** 框架。若确为内部定制版 `phpci` 框架,请对照其官方文档调整底层组件调用方式。以下审查基于 CI3 标准及通用 PHP 最佳实践。 --- ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | 多处(如 `get_order_manage`, `get_consumption_trend_data`, `cjy_get_other_order_info` 等) | **SQL 注入漏洞**:大量使用 `$addsql`、`$shop_ids` 直接拼接 SQL 字符串,未做参数绑定或白名单过滤。攻击者可传入恶意闭合语句执行任意 SQL。 | 1. 废弃字符串拼接,全面改用 CI3 Query Builder (`$this->db->where()`, `where_in()`)。<br>2. 若必须使用原生 SQL,严格使用 `?` 占位符。<br>3. 在 Controller 层对传入参数进行类型强校验。 | `$this->db->where_in('_shop_id', array_map('intval', explode(',', $shop_ids)));`<br>`$this->db->where($validated_addsql_array);` | | 🔴 严重 | 第 23 行 | **敏感信息硬编码**:加密串 `public $encrypt = "Vs!Fs7VT";` 直接暴露在类属性中,易随代码库泄露或被反编译获取。 | 移至 `application/config/config.php` 或环境变量,通过配置项读取。 | `// config.php<br>$config['order_encrypt_key'] = 'Vs!Fs7VT';`<br>`// Model内<br>$this->config->item('order_encrypt_key');` | | 🟠 警告 | `get_business` 方法 | **除零异常风险**:`$sum = array_sum(...)` 可能为 `0`,后续 `$tmp['actual_pay'] / $sum` 将触发 `DivisionByZeroError` 或返回 `NaN`。 | 增加安全除法判断,或使用 `bcdiv` 处理浮点精度。 | `if ($sum > 0) { $tmp['percent'] = number_format($tmp['actual_pay'] / $sum, 4) * 100; } else { $tmp['percent'] = 0; }` | | 🟠 警告 | 文件顶部 & 全局 | **框架生命周期误用**:文件顶部直接调用 `$CI =& get_instance(); $CI->load->model('Simple_model');` 违反 CI 依赖加载规范,易导致内存泄漏或实例冲突。 | 移除全局 `$CI` 调用,在 `__construct()` 中按需加载依赖。 | `public function __construct() { parent::__construct(); $this->load->model('Simple_model'); }` | | 🟠 警告 | `set_page_info`, `get_page_info`, `cjy_get_page_info` | **重复造轮子(分页逻辑)**:多处手写分页计算,状态判断(`over_page`/`last_page`)不一致,且未利用框架内置组件,维护成本极高。 | 统一使用 CI3 `Pagination` 库,或封装独立 `PaginationService`。 | `$this->load->library('pagination'); $this->pagination->initialize($config); $data['links'] = $this->pagination->create_links();` | | 🟡 建议 | 全文 | **返回类型不一致**:部分方法返回 `array`,部分返回 `false`,部分返回 `-1`,部分直接返回 `json_encode()` 字符串。增加调用方处理成本。 | 统一返回结构化数组,**JSON 序列化应移至 Controller/View 层**。 | `return ['status' => true, 'data' => $result, 'msg' => ''];` | | 🟡 建议 | `get_consumption_trend_data` 等 | **日期处理缺乏边界校验**:直接使用 `strtotime()` 转换外部日期,若格式非法将返回 `false`,导致 SQL 语法错误或逻辑异常。 | 增加日期格式校验,或使用 `DateTimeImmutable` 处理。 | `if (!strtotime($start_date)) { throw new InvalidArgumentException('Invalid start_date format'); }` | | 🟡 建议 | 全文 | **不符合 PSR-12 规范 & 违反单一职责**:方法过长(如 `cjy_get_other_order_info` 超 80 行),变量命名混用下划线与驼峰,注释陈旧。 | 遵循 PSR-12,拆分大方法为独立私有方法,使用 PHP 7.4+ 类型声明。 | `public function getOrderInfo(int $merchantId, string $orderId = ''): array` | --- ## 3. 总结与行动建议 ### 🔑 优先修复的关键问题 1. **立即修复 SQL 注入**:全局排查 `$addsql`、`$shop_ids`、`$_order_id` 等外部参数拼接点,替换为 Query Builder 或参数化查询。这是当前最高危的安全漏洞。 2. **移除硬编码密钥**:将 `$encrypt` 迁移至配置文件或环境变量,避免敏感信息随版本控制系统泄露。 3. **统一数据返回格式**:废除模型层直接返回 `json_encode()` 或混合返回 `false/-1` 的做法,统一使用 `['code' => 0, 'data' => [], 'msg' => '']` 结构,由 Controller 层负责序列化。 ### 🛠 后续重构与优化方向 1. **模型职责拆分(SRP)**:当前 `Ahead_yc_order_model` 承担了订单查询、报表统计、分页计算、退款调用、权限校验等职责。建议拆分为: - `OrderRepository`:专注数据查询与构建 - `OrderReportService`:专注统计与聚合逻辑 - `OrderRefundService`:专注支付退款流程 2. **全面拥抱 Query Builder**:逐步替换原生 SQL。CI3 的 Query Builder 已足够应对复杂查询,且能自动防注入、支持缓存、便于单元测试。 3. **性能优化策略**: - 移除手动 `force index`,通过 `EXPLAIN` 分析慢查询并建立复合索引。 - 报表类查询建议引入读写分离或定时任务预聚合(如 ClickHouse/ES 或 MySQL 汇总表),避免实时 `GROUP BY` 拖垮主库。 - 避免在循环或高频方法中重复调用 `strtotime()` 或 `load->model()`。 4. **代码规范升级**: - 启用 PHP-CS-Fixer 自动格式化至 PSR-12。 - 为所有公开方法添加 `@param`、`@return` 类型声明,逐步迁移至 PHP 8.1+ 的强类型语法。 - 清理 2016 年遗留注释,改用 PHPDoc 规范。 > ⚠️ **局限性说明**:您提供的代码在 `get_goods_sales` 方法末尾被截断(`$this->ahead_yc_merchant_user_model->get_one(['_id' => $para`)。若该方法涉及复杂联表或动态条件拼接,可能存在与上述相同的注入或逻辑隐患,建议补充完整代码后二次审查。 --- *此 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