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 430 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 **提交**: `7611b0455ec2701f8e5a7f013783bc5ee996c0a3` **提交人**: LITTLEMAIDI (11833999+littlemaidi@user.noreply.gitee.com) **时间**: 2026-06-01 17:22:29 --- ## 1. 审查摘要 - **代码质量评分**:4/10 分 - **总体评价**:该文件是一个典型的“上帝助手(God Helper)”,承载了短信、日志、OSS、微信API、WebSocket、打印机路由等十余个跨域功能。代码存在**硬编码敏感凭证、原始SQL拼接注入风险、已废弃函数调用**等严重问题。整体缺乏现代 PHP 类型约束与 PSR-12 规范,且未充分利用框架提供的安全与查询组件。若直接上线,存在较高安全与稳定性风险。 - **风险等级**:🔴 高 > 📌 **框架说明**:根据代码特征(`defined('BASEPATH')`、`&get_instance()`、`$CI->load->model()` 等),实际框架为 **CodeIgniter 3**。若确为 `phpci`,请核对官方文档,但以下审查基于 CI3 架构与通用 PHP 最佳实践。 --- ## 2. 问题详情 | 严重程度 | 文件/行号 | 问题描述 | 建议修改方案 | 代码示例 (可选) | | :--- | :--- | :--- | :--- | :--- | | 🔴 严重 | `alioss_addObject` | **硬编码云凭证**:`accessId`、`accessKey` 直接写死在代码中,极易导致云存储被盗刷或数据泄露。 | 移至 `application/config/oss.php`,通过 `$CI->config->item()` 读取,并配合环境变量管理。 | `$param = $CI->config->item('ali_oss');`<br>`$obj = new Alioss($param);` | | 🔴 严重 | `get_printer` (多处) | **SQL 注入风险**:使用字符串拼接构造 `FIND_IN_SET` 等条件(如 `'_shop_id= ' . $shop_id`),未使用参数绑定或查询构造器。 | 使用 CI 查询构造器或参数化查询,避免直接拼接用户/请求输入。 | `$this->db->where('FIND_IN_SET(?, _checkstand_id)', $checkstand_id, FALSE);`<br>`$this->db->where('_status', 1);` | | 🔴 严重 | `decodeUnicode` | **使用已废弃函数**:`create_function()` 在 PHP 7.2+ 已废弃,PHP 8.0+ 直接致命错误。 | 替换为匿名函数(Closure)或箭头函数。 | `preg_replace_callback('/\\\\u([0-9a-f]{4})/i', fn($m) => mb_convert_encoding(pack('H*', $m[1]), 'UTF-8', 'UCS-2BE'), $str);` | | 🟠 警告 | `curlRequest` | **关闭 SSL 验证**:`CURLOPT_SSL_VERIFYPEER => false` 使请求易受中间人攻击(MITM)。 | 生产环境必须开启验证,并配置正确的 CA 证书路径。 | `curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);`<br>`curl_setopt($curl, CURLOPT_CAINFO, '/path/to/cacert.pem');` | | 🟠 警告 | `unique_rand_OutTradeNo` | **低效去重算法**:循环内反复执行 `array_flip(array_flip($return))`,时间复杂度趋近 O(N²),并发或量大时性能骤降。 | 使用 `do-while` 配合 `isset()` 集合或 `array_unique()` 替代。 | `do { $val = createOutTradeNo(...); } while(isset($seen[$val])); $return[] = $val;` | | 🟠 警告 | `web_socket_client` 系列 | **连接泄漏隐患**:使用 `static` 缓存客户端实例但从未调用 `close()`,长驻进程会导致文件描述符耗尽。 | 增加连接状态检查,或注册 `register_shutdown_function` 统一释放资源。 | `register_shutdown_function(function() use ($client) { if($client) $client->close(); });` | | 🟡 建议 | 全局函数命名 | **违反 PSR-12 规范**:混用驼峰(`sendSMS`)、下划线(`do_log`)、大小写(`AliSendSMS`),可读性与自动补全体验差。 | 统一采用 `snake_case` 命名,并补充 PHPDoc 类型声明。 | `function send_sms(string $to, array $msg, int $v = 2): array` | | 🟡 建议 | `do_log` / `characet` | **错误抑制与不可靠编码检测**:`@mkdir`/`@file_put_contents` 掩盖真实错误;`mb_detect_encoding` 准确率极低。 | 移除 `@`,使用 CI 内置日志 `$CI->log->write_log()`;明确约定输入输出均为 UTF-8。 | `log_message('debug', $text);`<br>`return mb_convert_encoding($data, 'UTF-8', 'auto');` | | 🟡 建议 | `timeToHour` / `hourToTime` | **魔法数字硬编码**:依赖固定时间戳 `1483200000`(2017-01-01),跨年或时区变更易引发逻辑错乱。 | 使用 `DateTime` 对象或相对时间计算,消除绝对时间戳依赖。 | `$dt = new DateTime('2017-01-01 ' . $time); return $dt->getTimestamp() - 1483200000;` | --- ## 3. 总结与行动建议 ### 🔑 优先修复的关键问题(P0) 1. **立即移除硬编码凭证**:将 `alioss_addObject` 中的 `accessId`/`accessKey` 抽离至配置文件,并建议接入 KMS 或环境变量管理。 2. **修复 SQL 注入漏洞**:全面重构 `get_printer` 中的 `$where` 拼接逻辑,强制使用 CI3 的 `$this->db->where()` 或 `$this->db->query($sql, $binds)` 进行参数化查询。 3. **替换 `create_function`**:全局搜索并替换为匿名函数,确保兼容 PHP 7.4+ / 8.x。 ### 🛠 后续重构与优化方向 1. **拆分“上帝助手”**:当前文件超 1000 行且职责混杂。建议按业务域拆分为: - `application/helpers/sms_helper.php` - `application/helpers/wechat_helper.php` - `application/helpers/websocket_helper.php` - `application/helpers/printer_helper.php` 2. **引入现代 PHP 特性**:若项目允许升级至 PHP 7.4+,建议为核心函数添加类型声明(`declare(strict_types=1);`、参数类型、返回类型),大幅提升可维护性与静态分析能力。 3. **规范日志与错误处理**:废弃自定义 `do_log`,全面迁移至 CI3 内置 `log_message()` 或 Monolog;移除 `@` 错误抑制符,通过异常或返回值明确传递失败状态。 4. **框架适配优化**:CI3 中频繁在 Helper 中调用 `$CI->load->model()` 会拖慢性能。建议将高频依赖的 Model 在 Controller 层预加载,或封装为 Service 类(如 `app/services/SmsService.php`)统一管理依赖注入。 > ⚠️ **局限性说明**:您提供的代码在末尾 `order_printer` 函数处被截断(`$CI->ahead_shop_confi`),无法完整评估该函数的逻辑闭环。建议补充完整代码后再次提交审查。 --- *此 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