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
Delete row 666 from issue
id
666
repo_id
22
index
83
poster_id
1
original_author
original_author_id
0
name
🔍 代码审查报告:app-260616 - 订单退款api
content
## 自动代码审查报告 **分支**: app-260616 **提交**: `fbf39c180
## 自动代码审查报告 **分支**: app-260616 **提交**: `fbf39c1808c9d230b929c3e80aadf2d78042a9f2` **提交人**: LITTLEMAIDI (11833999+littlemaidi@user.noreply.gitee.com) **时间**: 2026-06-10 16:23:08 --- ## 1. 审查摘要 - **代码质量评分**:4.5 / 10 分 - **总体评价**:代码呈现典型的历史遗留系统特征,业务逻辑高度耦合,存在多处严重的安全隐患(硬编码密钥、明文密码比对、SQL 拼接风险)与架构反模式(上帝控制器、构造函数过重、直接操作超全局变量)。整体可维护性、扩展性与安全性均不达标,需进行系统性重构。 - **风险等级**:🔴 高 > 📌 **框架说明**:从 `CI_Controller`、`$this->load->`、`defined('BASEPATH')` 等特征判断,当前代码基于 **CodeIgniter 3** 架构。若 `phpci` 为贵司内部定制框架,以下安全与架构规范同样适用。具体组件调用请以 `phpci` 官方文档为准。 ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `MerchantAppServer.php`<br>`case '0005'` | **硬编码敏感凭证**:科大讯飞 TTS 的 `APISecret`、`APIKey` 直接暴露在业务逻辑中,极易通过版本库或反编译泄露。 | 移至独立配置文件或环境变量,通过框架配置类读取。禁止在代码中明文存储密钥。 | `// config/keys.php\n$config['xfyun'] = ['APPID' => '...', 'APISecret' => '...'];\n// 控制器中\n$xfyun = $this->config->item('xfyun');` | | 🔴 严重 | `MerchantAppServer.php`<br>`case '00064'` | **明文密码存储与比对**:`_discount_pwd` 疑似明文存储,且直接与 `$_old_password` 比对,违反基础安全规范。 | 使用 `password_hash()` 加密存储,`password_verify()` 验证。 | `if (!password_verify($_old_password, $data['_discount_pwd'])) { ... }\n$hash = password_hash($_new_password1, PASSWORD_DEFAULT);` | | 🔴 严重 | `Ahead_yc_order_model.php`<br>多处查询方法 | **SQL 注入风险**:`$addsql`、`$shop_ids`、`$_start_date` 等变量直接拼接入 SQL 字符串,未使用参数绑定。若上游传入恶意数据将导致注入。 | 全面改用 CI Query Builder 或严格使用 `?` 占位符。禁止拼接外部传入的 SQL 片段。 | `$this->db->where_in('_shop_id', explode(',', $shop_ids));\n$this->db->where('_timestamp >=', $start_date);` | | 🔴 严重 | `Ahead_pay_log_model.php`<br>`update_refund_amount()` | **原始 WHERE 条件拼接**:`$where = '_relation_id="' . $relation_id . '" ...'` 存在注入风险且易引发语法错误。 | 使用 CI 数组条件或 Query Builder 方法构建查询。 | `$where = ['_relation_id' => $relation_id, '_type' => $type, '_status' => [1, 4]];` | | 🟠 警告 | `Api.php`<br>`__construct()` & `jsonEcho()` | **输出缓冲滥用 & 未设响应头**:直接操作 `ob_*` 易触发 Warning,且未设置 `Content-Type: application/json`,可能导致客户端解析异常。 | 移除冗余缓冲操作,使用 CI 的 `output` 类统一响应。 | `$this->output->set_content_type('application/json')->set_output(json_encode($result, JSON_UNESCAPED_UNICODE));` | | 🟠 警告 | `MerchantAppServer.php`<br>`__construct()` & `index()` | **构造函数过重 & 上帝方法**:构造函数执行鉴权、日志、配置加载;`index()` 包含数十个 `case`,严重违反单一职责原则,难以测试与维护。 | 将鉴权/日志移至基类控制器或中间件;按业务域拆分控制器,利用 CI 路由分发。 | 拆分为 `AuthController`、`OrderController`、`PrinterController` 等独立控制器。 | | 🟠 警告 | `Api.php`<br>`selfChangeRoom()` | **直接修改 CI 超对象属性**:`$CI->merchant_id = ...` 破坏框架封装,易引发请求间状态污染与并发安全问题。 | 通过参数传递上下文数据至 Model,或使用 Session/Request 对象管理状态。 | `$this->load->model('order_model');\n$this->order_model->change_room($merchant_id, $admin_data, $params);` | | 🟡 建议 | 全局多处 | **浮点数处理金额**:使用 `float` 进行金额加减(如 `bcsub` 未全面覆盖),在 PHP 中可能导致精度丢失(如 `0.1+0.2=0.30000000000000004`)。 | 金额统一以“分”为单位(整数)存储计算,或全面使用 `BCMath` 扩展。 | `$actual_pay = bcsub($pay, $refund, 2);\n$refund_amount = (int)round($refund * 100); // 转为分` | | 🟡 建议 | 全局多处 | **模型重复加载**:在方法内部频繁 `$this->load->model()`,增加 I/O 开销且不符合 CI 最佳实践。 | 移至构造函数统一加载,或配置 `autoload.php` 自动加载高频模型。 | `public function __construct() { parent::__construct(); $this->load->model('vip_model'); }` | ## 3. 总结与行动建议 ### 🚨 优先修复的关键问题(P0) 1. **移除硬编码密钥**:立即将 `MerchantAppServer.php` 中的 `xfyun_tts_config` 迁移至配置文件或密钥管理服务(如 Vault/Env),并轮换已泄露的密钥。 2. **修复密码安全漏洞**:对 `_discount_pwd` 字段执行一次性哈希迁移脚本,后续所有密码比对必须使用 `password_verify()`。 3. **封堵 SQL 注入入口**:全面审查 `$addsql`、`$shop_ids`、`$relation_id` 等变量的来源,替换所有字符串拼接 SQL 为 Query Builder 或参数绑定查询。 ### 🛠 后续重构与优化方向 1. **架构解耦与路由规范化**: - 废弃 `switch ($request['function'])` 的伪路由模式,改用 CI 原生路由配置(`config/routes.php`)映射到独立控制器。 - 将鉴权、日志记录、参数校验等横切关注点抽离至 `MY_Controller` 基类或中间件,保持业务控制器轻量。 2. **统一输入/输出处理**: - 废弃直接读取 `$_POST`/`$_GET`,统一使用 `$this->input->post()`、`$this->input->get()` 或 `$this->input->raw_input_stream`,利用 CI 内置的 XSS/过滤机制。 - 封装统一的 `ApiResponse` 类,替代 `jsonEcho()`,自动处理 Header、状态码与 JSON 序列化。 3. **财务计算精度保障**: - 建立全局金额处理规范,禁止使用 `float` 进行财务运算。引入 `BCMath` 或整数(分)计算,并在入库/出库时进行严格校验。 4. **代码规范与可维护性提升**: - 遵循 PSR-12 规范,统一命名风格(如 `AplicationController` 拼写修正、模型类名大小写统一)。 - 消除魔法数字,将 `1, 2, 3, 15, 16` 等状态码/支付类型提取为类常量或枚举。 - 补充关键方法的 PHPDoc 注释与类型声明(PHP 7.4+ 推荐),提升 IDE 提示与静态分析能力。 > 💡 **提示**:由于提供的代码片段存在截断,部分全局函数(如 `throwError`、`request_frequency`)及基类 `Simple_model` 的实现未完全展示。建议在完整代码库中结合静态分析工具(如 `PHPStan`、`SonarQube`)进行全量扫描,以覆盖潜在的类型不匹配与未捕获异常。 --- *此 Issue 由代码审查服务自动创建*
...
milestone_id
0
priority
0
is_closed
0
is_pull
0
num_comments
0
ref
deadline_unix
0
created_unix
1781079788
updated_unix
1781079788
closed_unix
0
is_locked
0
content_version
0
time_estimate
0
Delete
Cancel