Files
DanDingNoneBot/review_reports/chatai_review.md
Mr.Xia c01338f496 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.
2026-05-09 23:22:28 +08:00

1.9 KiB
Raw Permalink Blame History

chatai 评审报告

修复前问题清单 (9项)

# 严重度 问题 文件
1 致命 模块导入即执行force_kill_chrome()杀死系统所有Chrome进程 init.py:59
2 except:吞掉所有异常(3处) init.py:55,84,182
3 markdown输出直接注入HTML模板存在XSS风险 screenshot.py:9
4 create_task未保存引用task可能被GC回收 init.py:170
5 os._exit(0)绕过所有清理逻辑 init.py:70
6 threading.Lock保护async对象(应用asyncio.Lock) init.py:34
7 图片路径硬编码output.png,并发请求互相覆盖 init.py:163
8 每次API调用创建新OpenAI client init.py:121
9 未使用导入: types/T_State/signal/atexit/threading/subprocess(部分) init.py

修复内容

init.py (重写)

  • 移除模块级force_kill_chrome(),改为@driver.on_startup延迟执行
  • 移除signal/atexit/threading/os._exit使用NoneBot生命周期管理
  • threading.Lockasyncio.Lock
  • except:except Exception + 日志
  • create_task_recall_tasks集合 + add_done_callback
  • OpenAI client → 单例_get_ai_client()
  • 图片路径 → f"data/chatai/output_{event.message_id}.png",发送后清理
  • except FinishedException: passraise(不可吞)

screenshot.py (重构)

  • html.escape()防XSS后用markdown.markdown()转换
  • 变量名htmlhtml_content避免冲突
  • page提前初始化为Nonelocals()检查 → 直接变量检查
  • 资源清理加try/except防止二次异常
  • from pyppeteer import launch延迟导入到需要时

config.py (不变)

  • 无问题,保持原样

chrome_manager.py (不变)

  • 独立脚本,无安全问题