修复37项安全漏洞和Bug

高危修复:
- app.py: 添加ip_rate_limit_lock线程锁保护IP限流字典
- app.py: 添加validate_ip_port()验证代理IP/端口范围
- database.py: SQL字段名白名单验证防止注入
- playwright_automation.py: 改进浏览器进程强制清理逻辑

中危修复:
- database.py: 统一时区处理函数get_cst_now()
- database.py: 消除循环导入,移动app_security导入到顶部
- playwright_automation.py: 所有bare except改为except Exception
- app_config.py: dotenv导入失败警告+安全配置检查
- db_pool.py: 添加详细异常堆栈日志
- app_security.py: 用户名过滤零宽字符
- database.py: delete_old_task_logs分批删除避免锁表

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-11 19:35:29 +08:00
parent a25c9fbba0
commit 126d4cbb52
6 changed files with 290 additions and 96 deletions

View File

@@ -237,6 +237,15 @@ def validate_username(username):
if not re.match(r'^[\w\u4e00-\u9fa5]+$', username):
return False, "用户名只能包含字母、数字、下划线和中文字符"
# Bug fix: 过滤零宽字符和其他不可见字符
# 检查是否包含不可见/控制字符
import unicodedata
for char in username:
category = unicodedata.category(char)
# Cf = 格式字符 (包括零宽字符), Cc = 控制字符
if category in ('Cf', 'Cc'):
return False, "用户名不能包含不可见字符"
return True, None