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 469 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 **提交**: `67f40bda4fe54e9ed5e8f551606cdea0973b268b` **提交人**: LITTLEMAIDI (11833999+littlemaidi@user.noreply.gitee.com) **时间**: 2026-06-02 15:52:23 --- ## 1. 审查摘要 - **代码质量评分**:4.5 / 10 分 - **总体评价**:该控制器实现了商家端 App 的核心路由与业务分发功能,业务覆盖较广。但存在明显的架构反模式(巨型 `switch` 充当路由器、构造函数职责过重)、严重的安全隐患(硬编码密钥、CORS 通配符、疑似明文密码比对)以及大量重复逻辑。代码可维护性、安全性与扩展性均处于较低水平,亟需重构。 - **风险等级**:🔴 高 ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | ~380-385 | **硬编码第三方服务密钥**:科大讯飞 TTS 的 `APPID`、`APISecret`、`APIKey` 直接写死在代码中,极易随版本库泄露,导致服务被盗刷或数据泄露。 | 将敏感凭证移至 `application/config/` 独立配置文件或服务器环境变量中,通过 `$this->config->item()` 读取。 | `'xfyun_tts_config' => $this->config->item('xfyun_tts')` | | 🔴 严重 | ~100-105 | **CORS 通配符配置**:`Access-Control-Allow-Origin: *` 允许任意域名跨域请求,结合 Token 鉴权机制,极易遭受 CSRF 攻击或敏感接口被恶意调用。 | 限制为可信域名白名单,或通过配置项动态输出,禁止使用 `*`。 | `header("Access-Control-Allow-Origin: " . $this->config->item('allowed_origins'));` | | 🔴 严重 | ~450-455 | **密码校验与存储不规范**:`if ($data['_discount_pwd'] != $_old_password)` 疑似直接比对明文密码;且更新时未进行哈希处理,违反现代密码安全规范。 | 使用 `password_hash()` 存储,`password_verify()` 校验。若历史数据为明文,需规划平滑迁移方案。 | `if (!password_verify($_old_password, $data['_discount_pwd'])) { $this->error_response('旧密码不正确'); }`<br>`$this->ahead_yc_merchant_user_model->update(['_discount_pwd' => password_hash($_new_password1, PASSWORD_DEFAULT)], ['_id' => $uid]);` | | 🟠 警告 | ~15-20 | **构造函数职责过重**:`__construct` 中混合了请求解析、CORS 设置、鉴权、权限校验、配置加载、日志记录等,严重违反单一职责原则(SRP),且影响单元测试。 | 将鉴权、日志、配置初始化抽离至中间件或基类控制器(如 `BaseApiController`);构造函数仅保留核心依赖注入。 | 提取 `AuthMiddleware::handle()`、`ApiLogger::log()` | | 🟠 警告 | ~200-350 | **巨型 Switch 充当路由器**:`index()` 方法使用超长 `switch` 分发 30+ 个接口,导致方法膨胀、难以维护,且每次请求都会加载大量未使用的 Model。 | 采用 CI3 原生路由配置,或改为动态方法调用(如 `$this->{$method}()`),将每个 `case` 拆分为独立方法。 | `public function func_0005() { /* 登录逻辑 */ }`<br>`$method = 'func_' . $request['function']; if (method_exists($this, $method)) { return $this->$method(); }` | | 🟠 警告 | ~250-260 | **重复的权限校验与菜单过滤**:登录接口中多次调用 `check_priv`,且硬编码菜单 ID(Magic Numbers),业务规则与代码强耦合。 | 将菜单过滤规则配置化(如 `config/menus.php`);提取独立的 `MenuService` 或 `PermissionService` 处理组装逻辑。 | `$this->menu_service->filterByPriv($menus, $user_type, $role_id);` | | 🟠 警告 | ~500-530 | **支付方式过滤逻辑冗余**:`00066` 接口中针对 `api_type` 的过滤存在大量重复的 `if` 与 `array_diff`,违反 DRY 原则。 | 使用映射数组统一管理排除规则,通过循环批量处理。 | `$exclude_map = ['bill_pay' => [10], 'vip_recharge' => [3,7,8...]];`<br>`$exclude = $exclude_map[$api_type] ?? [];`<br>`$data['paytype'] = array_values(array_diff($data['paytype'], $exclude));` | | 🟡 建议 | ~10 | **基类拼写错误**:`extends AplicationController` 疑似拼写错误,可能导致类继承失败或 IDE 无法识别。 | 修正为正确的基类名称(如 `CI_Controller` 或 `ApplicationController`)。 | `class MerchantAppServer extends CI_Controller` | | 🟡 建议 | ~30-40 | **JSON 解析缺乏容错**:`json_decode($this->stream, true)` 未校验解析结果,若客户端传入非法 JSON 会导致后续逻辑崩溃或返回 500 错误。 | 增加 `json_last_error()` 校验,并统一使用 `php://input` 读取请求体。 | `$raw = file_get_contents('php://input');`<br>`$data = json_decode($raw, true);`<br>`if (json_last_error() !== JSON_ERROR_NONE) { $this->error_response('请求数据格式错误'); }` | | 🟡 建议 | 全文 | **代码规范与可读性**:缩进不一致、长行未换行、变量命名混杂(如 `$this->stream` 与 `$this->get_stream`)、缺少类型声明与注释,不符合 PSR-12。 | 使用 `PHP-CS-Fixer` 或 IDE 自动格式化;统一使用驼峰/蛇形命名;为复杂逻辑添加 PHPDoc。 | 略(建议接入 CI/CD 静态检查流水线) | > 📝 **注**:代码在 `case "1001":` 处被截断,无法评估该分支的完整逻辑与潜在风险。若该分支涉及订单状态变更或资金操作,请补充完整代码以便进行深度审查。 ## 3. 总结与行动建议 ### 🔑 优先修复的关键问题 1. **立即移除硬编码密钥**:将 `xfyun_tts_config` 等敏感信息迁移至配置文件或 `.env`,并检查 Git 历史是否已泄露。 2. **修复密码安全逻辑**:全面排查 `_discount_pwd` 及其他密码字段的存储与校验方式,强制引入 `password_hash`/`password_verify`。 3. **收敛 CORS 策略**:将 `Access-Control-Allow-Origin: *` 替换为业务域名白名单,避免接口被恶意跨域调用。 4. **增加输入校验容错**:对 `json_decode`、`file_get_contents('php://input')` 增加异常捕获与格式校验,防止恶意请求导致服务崩溃。 ### 🛠 后续重构与优化方向 1. **架构解耦(核心)**: - 废弃 `index()` 巨型 `switch` 路由,改用 **CI3 原生路由** 或 **命令模式/动态方法分发**。 - 将鉴权、日志、配置加载等横切关注点抽离至 **中间件** 或 **基类控制器**,保持业务方法纯净。 2. **服务层拆分**: - 将菜单组装、权限校验、支付方式过滤等复杂逻辑下沉至独立的 `Service` 类,控制器仅负责参数接收、调用服务、返回响应。 - 消除硬编码的 Magic Numbers(如菜单 ID、支付平台 ID),统一收敛至配置中心或数据库字典表。 3. **性能与规范提升**: - 模型加载统一移至构造函数或按需懒加载,避免在 `switch` 分支中重复调用 `$this->load->model()`。 - 引入 PSR-12 代码规范检查工具(如 `php-cs-fixer`),统一命名风格,补充关键方法的 PHPDoc 注释。 - 针对高频接口(如登录、个人中心)考虑引入 Redis 缓存菜单/配置数据,降低 DB 查询压力。 > 💡 **框架适配提示**:当前代码特征与 **CodeIgniter 3** 高度吻合。若 `phpci` 为内部定制框架,请确认其是否支持中间件机制与动态路由。若不支持,建议优先采用 `BaseController` 继承模式与 `call_user_func_array` 实现轻量级分发,逐步向现代 MVC 架构演进。 --- *此 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