Files
Nexus/.cursor/rules/nexus-security.mdc
T
Nexus Agent 72d82d737b fix(security): BL-07 WS 403 澄清与 code-review 跟进加固
外网无 token WebSocket 的 HTTP 403 为应用层拒绝而非反代故障;边端 agent
在中心 401 时停止心跳重试;install 锁定路由级 404 且归档失败 fail-closed。
同步安全规范与 BL-06 一致,门控 7/7 PASS。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-07 12:12:49 +08:00

45 lines
1.5 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
description: Nexus 安全规范 — JWT/TOTP/API Key/Fernet/CORSMCP MySQL 只读
globs: server/api/**,server/application/**,server/infrastructure/database/**,web/app/**
alwaysApply: false
---
# Nexus 安全
## 认证矩阵
| 调用方 | 机制 |
|--------|------|
| 管理端 API | JWT Bearer + 可选 TOTP |
| Agent | `X-API-Key`(仅 per-server `agent_api_key`;经 `POST /api/servers/{id}/agent-key` 生成,BL-06 起无 global 回退) |
| WebSocket | JWT query param |
| 安装向导 | 无 JWT(仅安装模式可用) |
## 登录防暴破
- `auth_service.py`:失败计数 → 15min 锁定 → HTTP 429
- 刷新令牌重用检测:旧 refresh 作废、`token_version` 递增
## 密钥(禁改 / 禁提交)
- `.env` 永不入 git`SECRET_KEY` / `API_KEY` / `ENCRYPTION_KEY` / `DATABASE_URL` 不可从 settings 表覆盖
- UI 不展示可改的 `API_KEY`
## 运维信任模型
- 鉴权管理员即信任用户,不做 RBAC
- 必须防御:SQL/命令注入、XSS、凭据泄露
- Shell`shlex.quote()`DELETE/UPDATE 须有 WHEREMCP 同样)
## Cursor MySQL MCP
- 使用 `@yclenove/mysql-mcp-server`**默认 `MYSQL_READONLY=true`**
- `MYSQL_DATABASE_ALLOWLIST=nexus`(或实际库名)
- 禁止在 MCP `env` 或 git 中提交生产密码;连接信息仅写在本地 `.env`
- 查库优先 MCP `query` / `describe_table`,避免手写破坏性 SQL
## 审计
- 所有 CUD 写 `audit_logs`(含 `ip_address`
- WebSSH 会话与 `command_logs` 可追溯