2da52e80d0
面板密码安全: - 支持哈希存储 (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>
33 lines
1.4 KiB
Python
33 lines
1.4 KiB
Python
from aiohttp import web, ClientSession
|
|
import json, logging, asyncio
|
|
from ..utils.auth import panel_auth
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
def setup_proxy_routes(app, service_manager, prefix=''):
|
|
async def list_proxies(request):
|
|
ps = service_manager.get_service("proxy")
|
|
return web.json_response({"proxies": ps.list_proxies() if ps else []})
|
|
|
|
async def add_proxy(request):
|
|
try:
|
|
data = await request.json()
|
|
ps = service_manager.get_service("proxy")
|
|
ok = await ps.register_proxy(
|
|
path=data.get("path",""), target_url=data.get("target",""),
|
|
description=data.get("description",""), is_external=data.get("external",False))
|
|
return web.json_response({"ok": ok})
|
|
except Exception as e:
|
|
return web.json_response({"ok": False, "error": str(e)}, status=400)
|
|
|
|
async def remove_proxy(request):
|
|
path = request.match_info.get("path","")
|
|
ps = service_manager.get_service("proxy")
|
|
ps.unregister_proxy(path)
|
|
return web.json_response({"ok": True})
|
|
|
|
app.router.add_get(f'{prefix}/api/proxy', panel_auth(list_proxies))
|
|
app.router.add_post(f'{prefix}/api/proxy', panel_auth(add_proxy, csrf_protect=True))
|
|
app.router.add_delete(f'{prefix}/api/proxy/{{path}}', panel_auth(remove_proxy, csrf_protect=True))
|
|
logger.info(f'🔀 代理路由已注册 ({prefix}/api/proxy) (已加认证)')
|