Files
blackbird/docs/security/smtp_SECURITY_AUDIT_20260801.md
T
qing a7a78d1424 docs: aggregate project documentation under docs/ with unified index
- Move all per-module security audit reports to docs/security/
- Move code review logs to docs/reviews/, analysis reports to docs/reports/
- Add docs/INDEX.md as single entry point for all project documentation
- Add documentation management conventions section to README.md
- Clean up empty per-module docs/ directories
2026-08-03 13:21:48 +08:00

68 lines
2.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# smtp 模块安全审计报告
**审计日期**: 2026-08-01
**审计范围**: `smtp.py`(旧版)、`smtp_v2.py`(新版)
**代码版本**: dev_qing 分支
---
## 修复进度
| 优先级 | 总数 | 已修复 | 待修复 |
|--------|------|--------|--------|
| P0 | 2 | 1(v2已修复) | 1(旧版需下线) |
| P1 | 2 | 部分 | 1 |
---
## 🔴 P0 — 严重问题
### P0-1: 旧版 smtp.py 存在大量致命漏洞(需立即下线)
- **位置**: `smtp.py`
- **问题**: 旧版 smtp.py 缺乏关键防护:
1. 无发送速率限制(可被用于邮件炸弹)
2. 无同邮箱 60 秒发送冷却
3. 无验证码过期清理机制
4. 无连续失败锁定机制
- **修复建议**:
1. **确认 `_run.sh` 使用的是 `smtp_v2.py`**
2. 删除或重命名旧版 `smtp.py` 防止误用
3. 在代码注释中明确标记废弃
### P0-2: 依赖 pymsg 无认证(缓解:绑定 127.0.0.1)
- **说明**: 与其他 pymsg 服务相同,当前依赖网络层隔离
---
## 🟠 P1 — 高危问题
| # | 问题 | 说明 |
|---|------|------|
| P1-1 | 验证码存储在进程内存,服务重启后所有未使用验证码失效 | 可被利用造成拒绝服务(频繁重启导致用户无法注册) |
| P1-2 | 全局发送熔断配置需确认生效(`SMTP_HOURLY_LIMIT`) | smtp_v2 已有但需验证环境变量正确加载 |
---
## ✅ 已有安全机制(smtp_v2.py)
1. ✅ **同邮箱 60 秒发送冷却**: 冷却期拒绝并返回 `retry_after`
2. ✅ **邮箱级限流**(gateway 层双窗口:3次/小时 + 10次/天)
3. ✅ **验证码一次性消费**: 校验通过立即删除,防重放
4. ✅ **连续失败 5 次自动作废**: 防暴力破解验证码
5. ✅ **10 分钟有效期**: 惰性过期清理
6. ✅ **发送失败不计入冷却**: 防止网络错误误限制
7. ✅ **全局熔断(可选)**: `SMTP_HOURLY_LIMIT` 默认 100 封/小时
8. ✅ **fail-closed**: SMTP 异常时验证码校验失败
---
## 修复路线图
### 立即(24小时)
- [ ] 确认 smtp 服务运行的是 smtp_v2.py,旧版下线
- [ ] 删除或隔离 smtp.py 防止误用
### 短期
- [ ] 验证全局熔断配置生效
- [ ] 验证码存储考虑持久化(可选,当前内存实现适合单实例)