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 641 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 - Merge branch 'app-260616' of https://gitea.g-hi.co
TEXT
content
## 自动代码审查报告 **分支**: app-260616 **提交**: `c7aa286e291b5ee2230354e0e05df24e5d5a433d` **提交人**: LITTLEMAIDI (11833999+littlemaidi@user.noreply.gitee.com) **时间**: 2026-06-09 16:14:18 --- ## 1. 审查摘要 - **代码质量评分**:4.5 / 10 分 - **总体评价**:代码实现了较为复杂的商户端业务逻辑,但存在明显的架构反模式(胖控制器、模型内重复加载组件)、严重的安全隐患(硬编码敏感密钥、SQL拼接注入风险)及事务一致性缺陷。代码风格与 PSR-12 规范差距较大,可维护性与扩展性较低。 - **风险等级**:🔴 高 > 📌 **框架说明**:提交代码的结构、加载方式(`$this->load->`、`$this->db->`、`Simple_model`)高度符合 **CodeIgniter 3.x** 规范。若 `phpci` 为贵司内部定制框架,请结合其官方生命周期文档微调以下建议。 --- ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `MerchantAppServer.php`<br>~L295 | **硬编码第三方敏感密钥**:`xfyun_tts_config` 直接明文写入控制器,极易随代码库泄露,违反安全基线。 | 将密钥迁移至 `config/` 配置文件或 `.env` 环境变量中,通过 `config_item()` 或 `getenv()` 读取。 | ```php<br>// config/xfyun.php<br>return [<br> 'appid' => getenv('XFYUN_APPID'),<br> 'secret' => getenv('XFYUN_SECRET'),<br> 'key' => getenv('XFYUN_KEY')<br>];<br>// 控制器中<br>$this->config->load('xfyun');<br>$config = $this->config->item('xfyun');<br>``` | | 🔴 严重 | `Ahead_deposit_model.php`<br>~L385 | **SQL 注入风险**:`$where['where'][] = '(deposit._admin_id = '.$uid.' or deposit._admin_id = 0)';` 未对 `$uid` 进行类型强转或参数绑定,若传入恶意字符串将导致注入。 | 强制类型转换或使用 CI 查询构建器安全拼接。 | ```php<br>// 推荐写法<br>$uid = (int)$uid;<br>$this->db->group_start();<br>$this->db->where('deposit._admin_id', $uid);<br>$this->db->or_where('deposit._admin_id', 0);<br>$this->db->group_end();<br>``` | | 🔴 严重 | `Ahead_book_order_model.php`<br>~L115-180 | **事务与外部 API 调用耦合**:`invalid_book` 开启数据库事务后,在 `refund_by_notify` 中直接调用微信/银联退款 API。若外部退款成功但后续 DB 操作失败触发 `trans_rollback()`,将导致**资金已退但订单状态未更新**的资损问题。 | 将外部支付退款剥离出数据库事务。采用“先更新本地状态为退款中 -> 调用外部API -> 回调更新最终状态”的异步/补偿机制,或使用消息队列保证最终一致性。 | ```php<br>// 架构建议<br>$this->db->trans_start();<br>$this->update(['_status' => 3], ['_id' => $id]); // 3:退款处理中<br>$this->db->trans_complete();<br><br>// 事务外调用退款<br$refundRes = $this->refund_by_notify($order_data, ...);<br>if ($refundRes['status']) {<br> $this->update(['_status' => 4], ['_id' => $id]);<br>}<br>``` | | 🟠 警告 | `MerchantAppServer.php`<br>~L100-450 | **控制器严重违反单一职责原则 (SRP)**:`index()` 方法通过 `switch` 处理登录、个人中心、打印机、支付配置等数十个接口,代码超 500 行,难以测试与维护。 | 按业务域拆分控制器(如 `LoginController`, `ProfileController`, `PrinterController`),或使用路由分发+Service 层处理业务逻辑。 | 拆分示例:<br>`class MerchantLoginController extends AplicationController { public function login() { ... } }` | | 🟠 警告 | 所有 Model 文件<br>顶部 L2-L3 | **文件顶部全局实例化 CI 对象**:`$CI = &get_instance(); $CI->load->model('Simple_model');` 在文件加载时即执行,增加不必要的内存开销,且不符合框架懒加载机制。 | 移除文件顶部的实例化代码。模型继承 `Simple_model` 即可,CI 会自动处理基类加载。 | ```php<br>// 删除这两行<br>$CI = &get_instance();<br>$CI->load->model('Simple_model');<br>``` | | 🟠 警告 | 所有文件<br>多处 | **模型内重复加载组件**:大量使用 `$this->load->model()` 在方法内部动态加载。CI 虽会缓存,但频繁调用仍影响性能且破坏依赖注入原则。 | 将高频使用的 Model 移至 `__construct()` 中加载,或配置 `autoload.php`。 | ```php<br>public function __construct() {<br> parent::__construct();<br> $this->load->model('ahead_yc_merchant_user_model');<br> $this->load->model('ahead_shop_config_model');<br>}<br>``` | | 🟡 建议 | `MerchantAppServer.php`<br>~L10 | **拼写错误与命名不规范**:`AplicationController` 拼写错误;属性 `$createOutTradeNo` 使用驼峰,其余多用下划线,违反一致性。 | 修正拼写为 `ApplicationController`;统一属性命名风格(推荐 `snake_case` 或 `camelCase` 全量统一)。 | `class MerchantAppServer extends ApplicationController` | | 🟡 建议 | `MerchantAppServer.php`<br>~L35 | **输入流处理不规范**:混用 `$_POST['post_content_data']` 与 `file_get_contents('php://input')`,未校验 Content-Type 与数据长度,易受畸形请求攻击。 | 统一使用 CI 提供的 `$this->input->raw_input_stream`,并增加 JSON 解析异常捕获与大小限制。 | ```php<br>$raw = $this->input->raw_input_stream;<br>if (strlen($raw) > 1024 * 100) exit('Payload too large');<br>$this->stream = json_decode($raw, true);<br>if (json_last_error() !== JSON_ERROR_NONE) {<br> $this->error_response('JSON格式错误');<br>}<br>``` | --- ## 3. 总结与行动建议 ### 🔑 优先修复的关键问题 1. **移除硬编码密钥**:立即将 `xfyun_tts_config` 等敏感信息迁移至环境变量或加密配置文件中,避免代码仓库泄露导致资损。 2. **修复 SQL 注入漏洞**:对 `Ahead_deposit_model.php` 中的 `$uid` 拼接进行强制类型转换 `(int)`,或全面改用 CI Query Builder 的 `where()` 链式调用。 3. **解耦事务与外部支付**:重构 `invalid_book` 与 `refund_by_notify` 的调用链路,确保数据库事务仅包裹本地数据操作,外部 API 调用移至事务外或采用异步补偿机制。 ### 🛠 后续重构与优化方向 1. **架构分层**:当前控制器承担了路由分发、参数校验、业务逻辑、数据组装等多重职责。建议引入 **Service 层** 处理核心业务,控制器仅负责请求接收、参数校验与响应格式化。 2. **依赖管理优化**:清理文件顶部的 `$CI = &get_instance()` 滥用,统一在构造函数中声明依赖。对于高频调用的 Model,建议配置自动加载。 3. **规范与可维护性**: - 遵循 PSR-12 规范统一命名风格(属性、方法、常量)。 - 为长方法(如 `index()`、`search_deposit_list()`)添加类型声明(PHP 7.4+ 支持 `array`, `int`, `string` 等)与 PHPDoc 注释。 - 引入静态分析工具(如 `PHPStan` 或 `Psalm`)与代码规范检查(`PHP_CodeSniffer`)纳入 CI/CD 流程。 > ⚠️ **局限性说明**:本次审查基于您提供的代码片段。由于 `MerchantAppServer.php` 末尾被截断,部分业务闭环逻辑(如 `case "1001"` 后续处理)未能完整评估。建议补充完整代码或提供对应单元测试用例,以便进行更精准的边界条件与异常流审查。 --- *此 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