本文由 FlintHub 开发文档归档发布。原始文档日期见标题前缀,来源:暂存20260913/plugins_audit_report.md。
插件代码审计报告
审计日期:2026-08-26
审计范围:d:\phpstudy_pro\WWW\plugins\ 下所有插件的 views/ 和 hook/ 文件
检查项:7类问题(内联CSS/JS、硬编码URL、缺少$this->e()、非法icon名、语言key格式、缺失lang文件、资源URL缺少filemtime)
1. content_review
文件:
views/admin.phphook/layout_head_end.php
问题:
| # | 类别 | 文件 | 行号 | 问题描述 |
|---|---|---|---|---|
| 1 | 硬编码URL / 缺filemtime | views/admin.php | 293 | <link rel="stylesheet" href="/plugins/content_review/assets/style.css"> 未使用BASE_PATH,无filemtime版本参数 |
| 2 | 内联JS | views/admin.php | 294–317+ | <script> 块直接嵌入视图文件,应提取到 assets/script.js |
| 3 | 硬编码URL / 缺filemtime | hook/layout_head_end.php | 14 | href="/plugins/content_review/assets/style.css" 同上,且应在hook中用BASE_PATH |
2. seo
文件:
views/admin.php
问题:
| # | 类别 | 文件 | 行号 | 问题描述 |
|---|---|---|---|---|
| 1 | 硬编码URL / 缺filemtime | views/admin.php | 9 | <link rel="stylesheet" href="/plugins/seo/assets/style.css"> 未使用BASE_PATH,无filemtime |
3. friend_links
文件:
views/admin.php
问题:
| # | 类别 | 文件 | 行号 | 问题描述 |
|---|---|---|---|---|
| 1 | 硬编码URL / 缺filemtime | views/admin.php | 226 | <link rel="stylesheet" href="/plugins/friend_links/assets/style.css"> |
| 2 | 硬编码URL / 缺filemtime | views/admin.php | 227 | <script src="/plugins/friend_links/assets/script.js"></script> |
4. daily_checkin
文件:
views/index.phphook/nav_plugin_links.phphook/nav_main_links.php
问题:
| # | 类别 | 文件 | 行号 | 问题描述 |
|---|---|---|---|---|
| 1 | 硬编码URL / 缺filemtime | views/index.php | 9 | <link rel="stylesheet" href="/plugins/daily_checkin/assets/style.css"> |
| 2 | 硬编码URL | hook/nav_plugin_links.php | 13–15 | href="/checkin" 未使用BASE_PATH(出现2处,正常icon版+emoji版) |
| 3 | 硬编码URL | hook/nav_main_links.php | 12–14 | href="/checkin" 同上 |
5. red_packet
文件:
views/index.phpviews/detail.php
问题:
| # | 类别 | 文件 | 行号 | 问题描述 |
|---|---|---|---|---|
| 1 | 硬编码URL / 缺filemtime | views/index.php | 69 | <link rel="stylesheet" href="/plugins/red_packet/assets/style.css"> |
| 2 | 硬编码URL | views/index.php | 25 | action="/redpacket/create" |
| 3 | 硬编码URL | views/index.php | 44, 58 | href="/redpacket/..." 链接未使用BASE_PATH |
| 4 | 硬编码URL / 缺filemtime | views/detail.php | 81 | <link rel="stylesheet" href="/plugins/red_packet/assets/style.css"> |
| 5 | 硬编码URL | views/detail.php | 40 | action="/redpacket/.../grab" |
| 6 | 硬编码URL | views/detail.php | 78 | href="/redpacket" |
6. dice
文件:
DiceController.phphook/nav_plugin_links.phpviews/index.php
问题:
| # | 类别 | 文件 | 行号 | 问题描述 |
|---|---|---|---|---|
| 1 | 内联JS / 硬编码URL | DiceController.php | 123–125 | JS字符串中硬编码 src="/plugins/dice/assets/images/...gif",无BASE_PATH |
| 2 | 硬编码URL | hook/nav_plugin_links.php | 12–14 | href="/dice" 未使用BASE_PATH(正常icon版+emoji版) |
注:
views/index.php中资源URL已正确使用$this->url()+ filemtime,表现良好。
7. quiz_duel
文件:
views/index.phpviews/my.phpviews/detail.phpviews/create.phphook/right_sidebar_after.php
问题:
| # | 类别 | 文件 | 行号 | 问题描述 |
|---|---|---|---|---|
| 1 | 硬编码URL | views/index.php | — | href="/duel" / href="/duel/create" 等多处链接 |
| 2 | 硬编码URL | views/my.php | — | href="/duel/my" |
| 3 | 硬编码URL | views/detail.php | — | href="/duel/detail/{id}" |
| 4 | 硬编码URL | views/create.php | — | 表单action及链接 |
| 5 | 硬编码URL | hook/right_sidebar_after.php | 15 | href="/duel" 虽定义了 $base 变量但未在链接中使用 |
8. notifications
文件:
hook/nav_user_menu_items.phphook/nav_pc_user_links.php
问题:
| # | 类别 | 文件 | 行号 | 问题描述 |
|---|---|---|---|---|
| 1 | 硬编码URL | hook/nav_user_menu_items.php | 33 | href="/notifications" |
| 2 | 硬编码URL | hook/nav_pc_user_links.php | 29 | href="/notifications" |
9. medal
文件:
hook/nav_plugin_links.phpviews/admin.php
问题:
| # | 类别 | 文件 | 行号 | 问题描述 |
|---|---|---|---|---|
| 1 | 硬编码URL | hook/nav_plugin_links.php | 13–15 | href="/medal" 未使用BASE_PATH |
| 2 | 缺少$this->e() | views/admin.php | 30, 104, 118, 135, 151, 184 | $csrf、$mid 等变量输出未用 $this->e() 转义 |
10. ai_assistant
文件:
views/admin.php
问题:
| # | 类别 | 文件 | 行号 | 问题描述 |
|---|---|---|---|---|
| 1 | 非法icon名 | views/admin.php | 22 | $this->icon('robot', 16) — 'robot' 不在 TemplateCompiler 图标映射表中,将返回空白占位符  |
11. user_profile
文件:
views/front.php
问题:
| # | 类别 | 文件 | 行号 | 问题描述 |
|---|---|---|---|---|
| 1 | 缺少$this->e() | views/front.php | 37 | <input name="csrf" value="<?php echo $csrfToken; ?>"> 未转义(虽为hex安全值,但与规范不一致) |
12. mod_system
文件:
views/_reports_panel.phpviews/_config_panel.php
问题:
| # | 类别 | 文件 | 行号 | 问题描述 |
|---|---|---|---|---|
| 1 | 缺少$this->e() | views/_reports_panel.php | 47, 50, 90, 181, 187, 193 | $csrfToken、$defaultBanDays 等变量输出未用 $this->e() 转义 |
| 2 | 缺少$this->e() | views/_config_panel.php | 20 | <input name="csrf" value="<?php echo $csrfToken; ?>"> 未转义 |
13. invite
文件:
views/index.php
问题:
| # | 类别 | 文件 | 行号 | 问题描述 |
|---|---|---|---|---|
| 1 | 缺少$this->e() | views/index.php | 30 | <input name="csrf" value="<?php echo $csrfToken; ?>"> 未转义 |
| 2 | 缺少$this->e() | views/index.php | 55 | <td><?php echo $status; ?></td> 未转义 |
各插件合规情况汇总
| 插件 | 内联CSS/JS | 硬编码URL | 缺$this->e() | 非法icon | 语言key格式 | 缺失lang文件 | 缺filemtime |
|---|---|---|---|---|---|---|---|
| content_review | ❌ | ❌ | — | — | — | — | ❌ |
| seo | — | — | — | — | — | — | ❌ |
| friend_links | — | ❌ | — | — | — | — | ❌ |
| daily_checkin | — | ❌ | — | — | — | — | ❌ |
| red_packet | — | ❌ | — | — | — | — | ❌ |
| dice | ❌ | ❌ | — | — | — | — | ✅ |
| quiz_duel | — | ❌ | — | — | — | — | — |
| notifications | — | ❌ | — | — | — | — | — |
| medal | — | ❌ | ❌ | — | — | — | — |
| ai_assistant | — | — | — | ❌ | — | — | — |
| user_profile | — | — | ❌ | — | — | — | — |
| mod_system | — | — | ❌ | — | — | — | — |
| invite | — | — | ❌ | — | — | — | — |
良好示例(供参考)
以下插件的代码实现符合规范,可作为其他插件的参考:
| 插件 | 文件 | 正确做法 |
|---|---|---|
| task_center | hook/layout_head_end.php | <?php echo \defined('BASE_PATH') ? BASE_PATH : ''; ?>/plugins/task_center/assets/style.css + filemtime |
| qa | views/*.php | 正确使用 BASE_PATH + filemtime |
| single_page | views/*.php | 正确使用 BASE_PATH |
| code_repo | views/*.php | 使用 $base 变量封装 BASE_PATH |
| post_favorite | hook/layout_head_end.php | 正确使用 filemtime |
| points_mall | hook/layout_head_end.php | 正确使用 filemtime |
| mod_system | Plugin.php | 在插件初始化时正确使用 filemtime 注册资源 |
| code_audit | views/*.php | 正确使用 filemtime |
| dice | views/index.php | href="<?php echo $this->url('/plugins/dice/assets/style.css?v=' . (@filemtime(__DIR__ . '/../assets/style.css') ?: 1)); ?>" |
修复优先级建议
高优先级(安全风险):
mod_system/invite/medal/user_profile— 缺少$this->e()转义,存在XSS风险ai_assistant— 非法icon名称导致图标不显示
中优先级(功能兼容性):
- 所有插件的硬编码
/plugins/xxx/URL — 影响子目录部署(BASE_PATH场景) content_review/dice— 内联JS应移至assets/目录
低优先级(规范性):
- 所有缺少 filemtime 版本参数的资源URL — 影响浏览器缓存更新
seo/friend_links/daily_checkin/red_packet/quiz_duel/notifications— 仅硬编码URL问题