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 431 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-260616 - 1
TEXT
content
## 自动代码审查报告 **分支**: pay-260616 **提交**: `63f7234819a09ce60e0220fa5c8a5ac2e2cf619a` **提交人**: LITTLEMAIDI (11833999+littlemaidi@user.noreply.gitee.com) **时间**: 2026-06-01 17:23:21 --- ## 1. 审查摘要 - **代码质量评分**:4/10 分 - **总体评价**:该文件是一个典型的“上帝 Helper”,承载了短信、微信、OSS、Redis、WebSocket、打印机路由、日志、时间转换等大量异构业务逻辑。代码存在**严重的安全隐患**(硬编码密钥、SQL 拼接注入、关闭 SSL 验证)、**现代 PHP 兼容性问题**(使用已废弃的 `create_function`)、**性能瓶颈**(重复建连、低效去重算法)以及**架构反模式**(Helper 中重度耦合 CI 超对象与数据库操作)。整体可维护性与扩展性较差,亟需重构。 - **风险等级**:🔴 高 > 📌 **框架适配说明**:根据代码特征(`defined('BASEPATH')`、`&get_instance()`、`system/helpers/` 目录结构等),该代码实际基于 **CodeIgniter 3 (CI3)** 架构。若 `phpci` 为贵司内部定制框架,请参照其官方文档对组件加载与生命周期进行对齐。以下审查基于 CI3 最佳实践与 PHP 7.4+ 标准。 ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `decodeUnicode` 函数 | 使用了 PHP 7.2 已废弃、8.0 已移除的 `create_function`,会导致生产环境 Fatal Error。 | 替换为匿名函数(Closure)。 | `preg_replace_callback('/\\\\u([0-9a-f]{4})/i', function($m){ return mb_convert_encoding(pack("H*",$m[1]),"UTF-8","UCS-2BE"); }, $str);` | | 🔴 严重 | `alioss_addObject` | **硬编码云厂商 AccessKey/Secret**,极易泄露至版本库,造成数据被恶意篡改或盗刷。 | 移至 `config/oss.php` 或环境变量,通过 `$CI->config->item()` 读取。 | `'accessId' => config_item('oss_access_id'), 'accessKey' => config_item('oss_access_key')` | | 🔴 严重 | `get_printer` | 多处使用字符串拼接构建 `$where` 条件(如 `'_shop_id= ' . $shop_id`),未做转义,存在 **SQL 注入风险**。 | 全面改用 CI3 Query Builder 或 `$this->db->escape()`。 | `$this->db->where('_shop_id', $shop_id)->where('_status', 1)->where("FIND_IN_SET(?, _checkstand_id)", $checkstand_id)` | | 🔴 严重 | `curlRequest` | 强制关闭 SSL 证书验证 (`CURLOPT_SSL_VERIFYPEER = false`),易受中间人攻击 (MITM)。 | 生产环境必须开启验证,或配置可信 CA 证书路径。 | `curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($curl, CURLOPT_CAINFO, '/path/to/cacert.pem');` | | 🟠 警告 | `generate_code` | 使用 `rand()` 生成验证码,非密码学安全,易被预测或碰撞。 | PHP 7+ 应使用 `random_int()`。 | `return random_int(pow(10, $length - 1), pow(10, $length) - 1);` | | 🟠 警告 | `get_aliyun_redis_conn` | 每次调用均 `new Redis()` 并执行 `connect/auth`,无连接复用机制,高并发下极易耗尽文件描述符或触发 Redis 连接数限制。 | 使用单例模式或 CI3 Redis 驱动,启用 `persistent` 连接。 | `static $redis; if(!$redis){ $redis = new Redis(); $redis->pconnect(...); } return $redis;` | | 🟠 警告 | `unique_rand_OutTradeNo` | `while` 循环内反复调用 `array_flip` 去重,时间复杂度 $O(N^2)$,生成量大时严重拖慢性能。 | 使用 `array_keys` 结合 `do-while` 或 `array_unique`。 | `do { $return[] = createOutTradeNo(...); } while(count(array_unique($return)) < $num);` | | 🟠 警告 | `timeToHour` / `hourToTime` | 依赖硬编码时间戳 `1483200000` (2017-01-01),跨年份或时区切换时会产生严重逻辑偏差。 | 使用 `DateTime` 对象处理相对时间,或基于当日 `00:00:00` 动态计算基准。 | `$base = strtotime(date('Y-m-d')); return date("H:i", $base + $time);` | | 🟡 建议 | 全局 | **严重违反单一职责原则 (SRP)**。Helper 文件应仅包含无状态、轻量级工具函数。当前文件耦合了 DB、网络、缓存、第三方 API,难以测试与维护。 | 拆分为独立 Service/Library:`SmsService`、`WechatService`、`PrinterRouter`、`WebSocketManager` 等。 | 遵循 CI3 规范,将业务逻辑移至 `application/libraries/` 或 `application/services/`。 | | 🟡 建议 | `showErrorView` | 重定向 URL 拼写错误 `eeror.php`,且直接拼接 `$_SERVER['SERVER_NAME']` 未做白名单校验。 | 修正拼写,使用 CI3 的 `site_url()` 或 `base_url()` 生成安全链接。 | `redirect('pay/web/error.php?title=' . urlencode($title) . '&error_msg=' . urlencode($error_msg));` | | 🟡 建议 | 全局 | 命名风格混乱(`doLog` vs `do_log`、`showErrorVies` 注释拼写错误),且大量函数未声明返回值类型与参数类型。 | 统一遵循 PSR-12 规范,补充 PHPDoc 类型声明,统一错误返回结构(如 `['code'=>0, 'msg'=>'', 'data'=>[]]`)。 | `function do_log(string $text, string $dirname, string $filename = ''): void { ... }` | ## 3. 总结与行动建议 ### 🔑 优先修复的关键问题(P0/P1) 1. **立即移除硬编码凭证**:将 OSS、微信、短信等所有敏感配置迁移至 `config/` 目录或 `.env` 文件,严禁提交至代码仓库。 2. **修复 SQL 注入漏洞**:`get_printer` 函数中的 `$where` 拼接必须替换为 CI3 Query Builder 链式调用或参数化查询。 3. **兼容现代 PHP 版本**:全局替换 `create_function` 为匿名函数,将 `rand()` 升级为 `random_int()`,确保代码在 PHP 7.4/8.0+ 环境下稳定运行。 4. **开启 SSL 验证**:`curlRequest` 中恢复证书校验,避免第三方 API 通信被劫持。 ### 🛠 后续重构与优化方向 1. **架构解耦(核心)**: - 将当前 `common_helper.php` 拆分为多个独立组件。CI3 的 Helper 仅保留纯字符串/数组/数学计算等无状态函数。 - 涉及状态保持、网络请求、数据库交互的逻辑,统一封装至 `application/libraries/` 下的 Service 类,并通过 CI3 的 `$this->load->library()` 或依赖注入容器管理。 2. **连接资源池化**: - Redis、WebSocket 客户端应实现单例或连接池管理,避免每次请求重复握手。可考虑使用 `pconnect()` 或引入 `php-redis` 连接池扩展。 3. **统一错误与日志规范**: - 废弃 `do_log` 直接写文件的方式,接入 CI3 的 `log_message()` 或 Monolog,按级别(ERROR, WARNING, INFO)分类,并支持日志轮转与集中收集。 - 统一 API/内部函数返回格式,避免混用 `false`、`[]`、`true` 和数组,降低调用方判断成本。 4. **补充测试覆盖**: - 针对 `get_printer` 路由逻辑、`createOutTradeNo` 唯一性、微信 Token 刷新机制编写 PHPUnit 单元测试,确保重构后业务逻辑不回归。 > 💡 **提示**:由于提供的代码在末尾处被截断(`$CI->ahead_shop_confi`),部分订单打印逻辑未能完整评估。建议在完整提交代码后,针对 `order_printer` 函数进行二次专项审查,重点关注事务一致性与并发打印锁机制。 --- *此 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