security: P3+ — 面板密码哈希 + 上传类型白名单 + CSRF Token
面板密码安全: - 支持哈希存储 (password_hash/password_salt) - 登录使用 secrets.compare_digest 时序安全比较 - 回退明文兼容旧配置 - 默认密码 admin 时打印 CRITICAL 警告 文件上传安全: - 拒绝危险扩展名: .exe/.dll/.so/.sh/.bat/.ps1 等 - 拒绝敏感文件名: .htaccess/Makefile/Dockerfile 等 - 上传时检查并返回 403 CSRF 防护: - panel_auth(csrf_protect=True) 参数 - 写操作需 X-CSRF-Token header 匹配 session token - 保护范围: 文件删除/写入/创建/上传/重命名 + 项目启停 + 代理管理 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -120,10 +120,21 @@ async def handle_login(req):
|
||||
|
||||
cfg = req.app.get('panel_config', {})
|
||||
cfg_user = cfg.get('username', 'admin')
|
||||
cfg_pass = cfg.get('password', 'admin')
|
||||
|
||||
# 校验配置中的账号密码
|
||||
if username == cfg_user and password == cfg_pass:
|
||||
# 校验 — 优先哈希比较,回退明文 (向后兼容)
|
||||
pw_hash = cfg.get('password_hash', '')
|
||||
pw_salt = cfg.get('password_salt', '')
|
||||
if pw_hash and pw_salt:
|
||||
import hashlib
|
||||
ok = secrets.compare_digest(
|
||||
pw_hash,
|
||||
hashlib.sha256((password + pw_salt).encode()).hexdigest()
|
||||
)
|
||||
else:
|
||||
cfg_pass = cfg.get('password', 'admin')
|
||||
ok = secrets.compare_digest(username, cfg_user) and secrets.compare_digest(password, cfg_pass)
|
||||
|
||||
if username == cfg_user and ok:
|
||||
_clear_fails(ip)
|
||||
# 登录成功:生成 Token
|
||||
token = secrets.token_hex(16)
|
||||
|
||||
Reference in New Issue
Block a user