security: P2 生产深度加固 — 路径/鉴权/脱敏/校验/持久化/过期
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>
This commit is contained in:
@@ -44,13 +44,15 @@ if os.name == 'nt':
|
||||
if drive.exists():
|
||||
_ALLOWED_ROOTS.append(drive)
|
||||
else:
|
||||
# Linux / macOS / Android
|
||||
_ALLOWED_ROOTS = [
|
||||
Path("/"),
|
||||
Path("/media/sd"), # Android shared storage
|
||||
Path("/mnt"), # WSL mounts
|
||||
]
|
||||
# Linux / macOS / Android — 默认仅限项目目录 + data/,生产安全
|
||||
_ALLOWED_ROOTS = []
|
||||
_ALLOWED_ROOTS.append(_PROJECT_ROOT)
|
||||
# 从环境变量读取额外允许路径 (逗号分隔)
|
||||
_extra_roots = os.environ.get("SENSU_FILE_ROOTS", "")
|
||||
for r in _extra_roots.split(","):
|
||||
r = r.strip()
|
||||
if r:
|
||||
_ALLOWED_ROOTS.append(Path(r))
|
||||
# Deduplicate and keep only existing
|
||||
_seen = set()
|
||||
_filtered = []
|
||||
|
||||
Reference in New Issue
Block a user