fcac02d920
4.3 文件管理器路径收紧:
- 默认移除 Path('/') 全文件系统访问
- 仅允许项目目录 + data/ + 环境变量 SENSU_FILE_ROOTS 指定路径
3.4 插件路由鉴权修复:
- _check_plugin_auth 增加 panel_token 用户身份验证
- 先验证用户登录, 再检查插件权限
4.2 错误脱敏:
- security middleware 捕获异常 → 通用 'Internal server error'
- 堆栈详情仅写入日志, 不暴露给客户端
4.4 命令参数校验:
- POST /api/command 拒绝 shell 元字符 (;&|`$(){}!#~<>)
- 防止命令注入
4.5 Session 持久化:
- 登录/退出时保存到 SenSuDB.config_kv
- 框架重启后自动恢复已持久化会话
4.6 Token 过期: 24h → 2h
Co-Authored-By: Claude <noreply@anthropic.com>
29 lines
954 B
Python
29 lines
954 B
Python
from aiohttp import web
|
|
from ..utils.auth import panel_auth
|
|
import re
|
|
|
|
# Shell 元字符黑名单 — 防止命令注入
|
|
_SHELL_DANGER = re.compile(r'[;&|`$(){}!#~<>]')
|
|
|
|
|
|
def setup_routes(app, prefix=''):
|
|
app.router.add_post(f'{prefix}/api/command', panel_auth(exec_cmd))
|
|
|
|
|
|
async def exec_cmd(req):
|
|
d = await req.json()
|
|
raw = d.get('command', '')
|
|
# 安全检查: 拒绝含 shell 元字符的命令
|
|
if _SHELL_DANGER.search(raw):
|
|
return web.json_response(
|
|
{"success": False, "error": "命令包含不允许的字符"}, status=400
|
|
)
|
|
cs = req.app.get('service_manager').get_service("command")
|
|
if not cs:
|
|
return web.json_response({"error": "Missing"}, status=503)
|
|
try:
|
|
res = await cs.execute_command(raw)
|
|
return web.json_response({"success": True, "output": str(res)})
|
|
except Exception:
|
|
return web.json_response({"success": False, "error": "命令执行失败"})
|