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 143 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 - 0519
TEXT
content
## 自动代码审查报告 **分支**: app-260519 **提交**: `b8292b8a832fb77ffc57d9ed036a5b2f6eced983` **提交人**: zhangjunnan (121158035@qq.com) **时间**: 2026-05-18 17:53:43 --- ## 1. 审查摘要 - **代码质量评分**:4.5 / 10 分 - **总体评价**:代码实现了较为完整的商家端业务逻辑与支付回调流程,但存在大量历史遗留问题。核心隐患集中在**敏感信息硬编码**、**PHP 8 兼容性断裂**、**密码明文处理**以及**控制器职责过重**。Redis 辅助函数设计存在性能瓶颈与并发风险,部分测试代码未清理即上线。整体可维护性与安全性亟待重构。 - **风险等级**:🔴 高 > 📌 **框架说明**:代码结构、加载方式(`$this->load->`、`BASEPATH`、`CI_DB`)高度符合 **CodeIgniter 3.x** 规范。若 `phpci` 为贵司内部定制框架,请结合其官方文档对底层组件加载方式做适配调整。以下建议基于标准 PHP 7.4+/8.x 及 CI3 最佳实践。 --- ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `common_helper.php` (多处) | **敏感密钥硬编码**:阿里云 AK/SK 及科大讯飞 API 密钥直接写在代码中,极易通过版本库泄露,导致云资源被盗刷。 | 立即迁移至配置文件(如 `config/aliyun.php`)或环境变量,通过 `$this->config->item()` 或 `$_ENV` 读取。 | `$ak = getenv('ALIYUN_ACCESS_KEY_ID') ?: $this->config->item('aliyun_ak');` | | 🔴 严重 | `common_helper.php` (~L1050) | `decodeUnicode` 使用已废弃的 `create_function`,**PHP 8.0+ 将直接抛出 Fatal Error 导致服务崩溃**。 | 替换为现代匿名函数(Closure)。 | `return preg_replace_callback('/\\\\u([0-9a-f]{4})/i', function($m){ return mb_convert_encoding(pack("H*", $m[1]), "UTF-8", "UCS-2BE"); }, $str);` | | 🔴 严重 | `common_helper.php` (~L680) | `rs_hmset` 函数被**重复定义两次**,PHP 解析时会触发 `Fatal error: Cannot redeclare`,直接阻断脚本执行。 | 删除第二个重复的 `if (!function_exists('rs_hmset')) { ... }` 代码块。 | (直接删除重复定义段) | | 🔴 严重 | `MerchantAppServer.php` (~L450) | 修改打折密码时直接比对明文:`$data['_discount_pwd'] != $_old_password`。违反安全基线,且数据库若泄露将导致批量撞库。 | 密码必须使用 `password_hash()` 存储,验证使用 `password_verify()`。 | `if (!password_verify($_old_password, $data['_discount_pwd'])) { $this->error_response('旧密码不正确'); }` | | 🔴 严重 | `WxNotify.php` (~L25, ~L55) | `try-catch` 块中 `$notify` 在 `try` 内部实例化。若实例化前抛异常,`catch` 中调用 `$notify->SetReturn_code()` 将触发 `Undefined variable` 错误,导致微信/支付宝收不到标准响应而重复回调。 | 将 `$notify = new WxPayNotify();` 移至 `try` 外部,或在 `catch` 中安全实例化。 | `$notify = new WxPayNotify(); try { ... } catch(Exception $e) { $notify->SetReturn_code("FAIL"); ... }` | | 🟠 警告 | `MerchantAppServer.php` (~L45) | `__construct` 承载鉴权、配置、DB、时区、日志等逻辑,且 `json_decode` 未做错误处理。若传入非法 JSON,后续数组访问将触发 Warning/Notice 并污染业务流。 | 鉴权逻辑抽离至基类控制器或中间件;增加 JSON 解析校验。 | `$this->stream = json_decode($this->stream, true); if (json_last_error() !== JSON_ERROR_NONE) { $this->error_response('请求参数JSON格式错误'); }` | | 🟠 警告 | `common_helper.php` (~L580) | Redis 辅助函数每次调用都执行 `connect()` 和 `close()`。高并发下频繁创建/销毁 TCP 连接,极易耗尽文件描述符并引发性能雪崩。 | 使用 CI 内置 Redis 驱动或实现连接池复用,避免手动 `close()`。 | 建议统一使用 `$this->load->driver('cache', ['adapter' => 'redis']);` 管理连接生命周期。 | | 🟠 警告 | `common_helper.php` (~L630) | `rs_incrByFloat` 使用 `is_float($float)` 校验。PHP 中浮点数常以字符串形式传入(如 `'0.00'`),该判断会直接返回 `false` 导致逻辑失效。 | 改用 `is_numeric()` 进行安全校验。 | `if (!empty($keyName) && is_numeric($float)) { ... }` | | 🟠 警告 | `WxNotify.php` (~L115) | 支付宝验签公钥硬编码为 `"test"`,且残留 `aliHallNativeNotifytest` 调试方法。线上支付回调将因验签失败而中断,测试代码增加攻击面。 | 从配置读取真实公钥;彻底删除 `test` 后缀方法及双分号等语法瑕疵。 | `$aopClient->alipayPublicKey = $this->config->item('alipay_public_key');` | | 🟡 建议 | `MerchantAppServer.php` (~L100) | `index()` 方法超 500 行,包含大量 `switch-case` 路由分发。违反单一职责原则(SRP),难以进行单元测试与后续迭代。 | 按业务域拆分至独立 Controller,或使用 CI 路由配置替代手动 `switch`。 | 将 `case '0005'` 移至 `MerchantAppLogin.php`,`case '00063'` 移至 `MerchantAppPrinter.php`。 | | 🟡 建议 | `Ahead_ai_vending_cabinet_shelf_model.php` (~L180) | `create_qrcode` 使用递归处理批量生成。当未生成码的柜子较多时,易触发 `Maximum function nesting level` 错误。 | 改为 `while` 循环或交由消息队列异步处理。 | `while (!empty($cabinet)) { $cabinet_id = array_shift($cabinet); ... }` | | 🟡 建议 | 全局 | 存在大量魔法数字(如 `23142`, `0777`, `500000`)及未定义常量(`BRANCHNAME`, `DEBUG_VERSION`)。`@mkdir($dirname, 0777)` 权限过大。 | 提取为类常量或配置文件;日志目录权限改为 `0755`;明确常量定义来源。 | `const MERCHANT_CAMBODIA_ID = 23142;`<br>`@mkdir($dirname, 0755, true);` | --- ## 3. 总结与行动建议 ### 🚨 优先修复的关键问题(P0) 1. **移除硬编码密钥**:立即将阿里云 AK/SK、科大讯飞密钥、支付宝公钥迁移至安全配置中心或环境变量,并轮换已泄露的旧密钥。 2. **修复 PHP 8 兼容性**:替换 `create_function`,删除重复的 `rs_hmset` 定义,否则升级 PHP 版本将直接导致服务宕机。 3. **密码安全改造**:废弃明文密码比对逻辑,全面接入 `password_hash()` / `password_verify()` 标准加密方案。 4. **支付回调容错**:修复 `WxNotify.php` 中 `$notify` 变量作用域问题,确保第三方回调始终能收到标准 XML/JSON 响应,避免资金对账异常。 ### 🛠 后续重构与优化方向 1. **架构瘦身**:`MerchantAppServer.php` 的 `__construct` 和 `index()` 已演变为“上帝类”。建议引入 **路由分发机制** 或 **中间件** 处理 Token 校验、权限拦截与日志记录,控制器仅保留业务编排逻辑。 2. **Redis 连接治理**:废弃当前每次请求新建连接的 Helper 模式。改用 CI 官方 `Cache` 驱动或 `Predis` 连接池,将 `connect/close` 交由框架生命周期管理,预计可降低 30%~50% 的 I/O 延迟。 3. **异步化改造**:`control_line` 中的 `usleep(500000)` 会阻塞 PHP-FPM 工作进程。建议将硬件控制指令投递至 Redis 队列或 RabbitMQ,由独立 Worker 消费执行,提升接口响应速度。 4. **代码规范对齐**:逐步引入 `PHP_CodeSniffer` 配合 `PSR-12` 规则集进行静态扫描;统一命名规范(类名 `PascalCase`,方法/变量 `camelCase`,常量 `UPPER_SNAKE_CASE`);补充类型声明(Type Hints)以提升 IDE 提示与静态分析能力。 > ⚠️ **局限性说明**:提供的 `MerchantAppServer.php`、`common_helper.php` 及 `Ahead_ai_vending_cabinet_shelf_model.php` 末尾存在代码截断(如 `if (isset($`、`$this-` 等语法未完成)。本次审查基于可见代码片段进行,若截断部分包含核心事务处理或敏感逻辑,请补充完整后再次提交审查。 --- *此 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