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:
39
review_reports/damo_balance_review.md
Normal file
39
review_reports/damo_balance_review.md
Normal file
@@ -0,0 +1,39 @@
|
||||
# damo_balance 评审报告
|
||||
|
||||
## 修复前问题清单 (5项)
|
||||
|
||||
| # | 严重度 | 问题 | 文件 |
|
||||
|---|--------|------|------|
|
||||
| 1 | **致命** | 明文硬编码账号密码 `xsllovemlj/xsl1314520mlj` | AccountSpider.py:main + __init__.py |
|
||||
| 2 | **致命** | 模块级 `spider = AccountSpider()` 共享session,多用户并发冲突 | __init__.py |
|
||||
| 3 | 高 | `input()` 阻塞等待验证码,nonebot环境下必死 | AccountSpider.py:24 |
|
||||
| 4 | 中 | 硬编码绝对路径 `/bot/danding-bot/...` 移动即崩 | AccountSpider.py:22 |
|
||||
| 5 | 中 | 爬虫调用无错误处理,`state = response.text` 可能无余额标签 | AccountSpider.py/commands |
|
||||
|
||||
## 修复内容
|
||||
|
||||
### AccountSpider.py
|
||||
- 移除明文密码,`main()` 改用环境变量 `DAMO_USERNAME`/`DAMO_PASSWORD`
|
||||
- `__init__` 接受 `save_dir` 参数,移除硬编码路径
|
||||
- 移除 `input()` 函数,`get_verification_code()` 直接返回图片字节
|
||||
- 加 `os` import
|
||||
|
||||
### __init__.py
|
||||
- 移除全局 `spider` 实例,改为 handler 内创建并通过 `state["spider"]` 传递
|
||||
- 凭证从环境变量读取,未配置时提示用户
|
||||
- 所有 API 调用加 `try/except` + `logger.error` 错误处理
|
||||
- `state.get("spider")` 安全取值,空时提示重新发送
|
||||
|
||||
## 安全建议(未自动修改)
|
||||
- 建议将环境变量替换为 nonebot `.env` 配置文件
|
||||
- 验证码图片建议用 base64 内联发送后立即删除临时文件
|
||||
|
||||
## 验证
|
||||
- [x] 无明文密码残留
|
||||
- [x] 无 global spider
|
||||
- [x] state 传递 spider 实例
|
||||
- [x] env var 读取凭证
|
||||
- [x] 错误处理覆盖所有 API 调用
|
||||
|
||||
## 代码质量总结
|
||||
安全问题修复后评级:**B** (从 D- 提升)
|
||||
Reference in New Issue
Block a user