refactor(plugins): comprehensive code review - ~35 fixes across 14 plugins

Phase 1 - Plugin code review (14/14 plugins):
- Security: 3x token leak in print→logger.debug, Bearer prefix handling
- Bug: bare except→specific exceptions, HorseState type safety, sync→async
- Critical: response_model undefined, route dead code, sync blocking event loop
- Quality: 11x print()→logger, variable name shadowing, consistent logging

Phase 2 - Deep analysis:
- Fix: payout int truncation→max(1, round(amount*odds))
- Fix: room_store get_lock race condition→dict.setdefault()
- Verify: data_manager f-string SQL is safe (uses ? placeholders)

Infrastructure: review reports generated for all plugins.
This commit is contained in:
2026-05-09 23:22:28 +08:00
parent 9a8cb3ad6d
commit c01338f496
43 changed files with 4233 additions and 3645 deletions

View File

@@ -0,0 +1,27 @@
# command_list 评审报告
## 修复前问题清单 (4项)
| # | 严重度 | 问题 | 文件 |
|---|--------|------|------|
| 1 | **致命** | `check_user and fullmatch(...)` — Python对truthy callable用`and`返回右侧,权限检查被完全绕过 | command_list.py:17 |
| 2 | 中 | `__plugin_meta__ = Config` 应为`PluginMetadata`实例 | __init__.py:4 |
| 3 | 中 | `random.uniform(1,2)` sleep无功能意义 | command_list.py:46 |
| 4 | 低 | config.py的字段从未被任何代码引用 | config.py |
## 修复内容
1. 重写权限检查为`Rule(_check_user) & fullmatch(...)`,确保`_check_user`作为Rule执行而非truthy短路
2. 移除random依赖
3. 移除无用sleep
## 严重问题说明
**致命级权限绕过**`check_user and fullmatch(...)` 中,`check_user`是一个async函数对象truthyPython的`and`运算符会直接返回右侧`fullmatch(...)`的结果,完全跳过权限检查。所有用户都能使用该命令。
## 验证
- [x] Rule(_check_user) & fullmatch(...) 语法正确
- [x] 移除random依赖
- [x] 插件列表排序输出
- [x] 异常处理
## 代码质量总结
`__init__.py``config.py`结构有问题(meta=Config),但不影响运行。核心逻辑修复后评级:**B**