From 6171245fb10aae5db88d30e15defafd5cba4bd68 Mon Sep 17 00:00:00 2001 From: Sanaei Date: Sun, 29 Nov 2026 23:33:09 +0330 Subject: [PATCH] docs(security): rewrite the OSS Scanner threat model against the current code The model predated several boundaries the scanner should test. It listed only the monitor and node-sync token scopes, so node-admin, the three route allowlists and the mTLS-certificate identity were unstated, and it never named validatePushedInbound, the guard that keeps a node-sync push away from the receiving host's files and sockets. The MCP endpoint, the public sponsor routes, the pre-auth listener code, the LDAP login path and the subscription headers persisted into client_hwids were missing as entry points. It now states the default configuration a finding may assume, splits each attacker into the routes and files that serve them, covers third-party content the panel fetches, and rates end-user limit evasion and revoked-client access in the severity rubric. The exercise section names each fuzz target's package and how to mint a restricted token on a live panel. --- .oss-scanner/threat_model.md | 354 +++++++++++++++++++++++++++-------- 1 file changed, 272 insertions(+), 82 deletions(-) diff --git a/.oss-scanner/threat_model.md b/.oss-scanner/threat_model.md index d683202df..aca8897f1 100644 --- a/.oss-scanner/threat_model.md +++ b/.oss-scanner/threat_model.md @@ -1,117 +1,307 @@ # 3x-ui threat model +## What this project does and why it matters + 3x-ui is a self-hosted web control panel for Xray-core. One Go binary stores inbounds, clients and settings in SQLite (default) or PostgreSQL, renders an Xray JSON config from that state, supervises Xray-core and the `mtg-multi` MTProto sidecar as child processes, runs AmneziaWG and TUIC servers in-process, -and serves an embedded React SPA. It is deployed on internet-facing VPS hosts, -usually as root, often in censored regions where a compromise exposes the -people relying on the proxy. Read `docs/architecture.md` in the scanned revision -for the code map; do not assume package names stay fixed. +and serves an embedded React SPA. A second HTTP server hands subscription +configs to end users. -## Trust boundaries and attackers +It runs on internet-facing VPS hosts, usually as root, often in censored +regions. A compromise exposes the proxy credentials, IP addresses and traffic +metadata of the people relying on it, and gives root on the host. Operators +commonly sell access, so they hand subscription links, proxy credentials and +bot access to people they do not trust. -Trusted: the panel administrator (one account, or an admin-scope API token). -The admin can already edit the full Xray config, run a panel update, import a -database and set file paths, so admin-to-root is by design and out of scope. +Read `docs/architecture.md` in the scanned revision for the code map. The +paths below are starting points; do not assume they stay fixed. -Untrusted, in decreasing order of importance: +## Default configuration -1. **Unauthenticated network attacker** reaching the panel port (default 2053) - or the subscription port. Login (`POST /login`, 2FA, LDAP), CSRF/session - handling (`internal/web/session/`), the login rate limiter - (`controller/login_limiter.go`), the `checkAPIAuth` gate in - `controller/api.go` (session, Bearer token, mTLS client cert), - `/csrf-token`, PWA/static routes, and the WebSocket `/ws` upgrade. -2. **Subscription end users.** They know only their own `subId` and fetch - `{subPath}/{subId}`, the JSON/Clash/Mihomo variants and `hwid-status` - (`internal/sub/`). Each must see only their own clients; check subId - guessing, cross-client leakage, header injection, forwarded-header trust - (`internal/sub/forwarded_trust.go`) and the public subscription page. -3. **Limited API tokens.** `monitor` and `node-sync` scopes are restricted by - explicit allowlists in `controller/api.go` (`enforceTokenScope`). Any way - for such a token to reach a route outside its allowlist is a vulnerability. -4. **Master/node peers.** A master panel drives child nodes over HTTPS - (`internal/web/runtime/`, TLS modes verify/skip/pin/mtls). A compromised - or malicious node must not gain control of the master or of other nodes; - node responses (inbound lists, traffic, online clients, certificates, - `descendants`) are untrusted input on the master. -5. **Proxy traffic.** Packets reaching AmneziaWG (`internal/amneziawgnet/`), - TUIC (`internal/tuic/`) and the loopback SOCKS5 relays into Xray. A peer - must not escape its per-peer auth, reach another peer's traffic, or crash - the panel process. -6. **Chat-bot users.** Telegram and Discord bot messages and callback data - (`internal/web/service/tgbot/`, `discord/`). Non-admin chats may only see - their own client (bound via the subId invite token); admin commands must - be unreachable from them. -7. **Imported content** an admin may receive from a third party: share links - and subscription URLs parsed by the import paths (`FuzzParseLink`), and - geosite/geoip `.dat` files (`internal/xray/geodata/`). +Assume these unless a finding states otherwise. A finding that needs a +non-default setting is valid, but must name the setting. -Also in scope: stored or reflected XSS in the SPA or the subscription page -from client remarks, emails, inbound tags or any other value a non-admin can -influence; SQL injection through GORM raw queries; path traversal in file or -certificate handling; secrets leaking into logs, subscription output, API -responses for limited tokens, or node sync payloads. +- Panel: port 2053, base path `/`, plain HTTP until the admin sets a + certificate. The first user gets a random username and password, printed + once at first start. 2FA, LDAP login, node mTLS and the MCP endpoint are off. +- Subscription server: on, port 2096, each of the raw, JSON and Clash paths a + random 16-character segment. JSON and Clash output, and their User-Agent + auto-detection on the raw route, are off. +- Telegram, Discord, email and WeChat notifiers are off. +- Forwarded headers (`X-Forwarded-For`, `X-Real-IP`) are trusted only from + `trustedProxyCIDRs`, default loopback. +- The default Xray template listens for its gRPC API on `127.0.0.1:62789` and + blackholes `geoip:private` destinations. +- An unauthenticated `/panel/api/*` request answers 404, not 401, unless it + carries a `Bearer` header or `X-Requested-With: XMLHttpRequest`. + +## Trust boundaries + +**Trusted: the panel administrator** — the logged-in session, or an API token +of scope `admin`. The admin can edit the full Xray config, update the panel, +import a database, choose file paths and enable every integration, so +admin-to-root is by design and out of scope. + +Everyone below is untrusted, in decreasing order of importance. + +### 1. Unauthenticated network attacker on the panel port + +Reachable without credentials: `GET {base}/` (login page), `/csrf-token`, +`/sponsors`, `/sponsors/logo/:name`, `POST /login`, `/logout`, +`/getTwoFactorEnable`, the PWA files (`/manifest.webmanifest`, +`/service-worker.js`, `/pwa-register.js`, `/icons/:name`), `/assets/*`, and +the refusal paths of `/ws`, `/panel/*` and `/panel/api/*`. + +- Authentication: `controller/index.go` (`login`), `service/panel/user.go` + (bcrypt, TOTP, optional LDAP bind where the submitted username reaches an + LDAP filter), `session/` (signed cookie, `LoginEpoch` invalidation, CSRF + token), `controller/login_limiter.go`. +- The API gate: `checkAPIAuth` then `enforceTokenScope` in + `controller/api.go`, then `middleware.ConfigEnvelopeMiddleware` (zstd body + + SHA-256 header, decoded before the handler) and `CSRFMiddleware`. +- Listener code that parses bytes before any auth: + `internal/web/network/` (auto-HTTPS sniffing, connection limits), + `middleware/` (body limit, domain validator). +- Client-address spoofing: `getRemoteIp` (`controller/util.go`) feeds the + login limiter, the logs and the login notifications. +- The submitted username is copied into the log file and into Telegram, + Discord, email and WeChat login notifications. +- `/ws` accepts a session cookie only and checks `Origin` itself + (`controller/websocket.go`). + +### 2. Subscription users, and anyone who can reach the subscription port + +A subscriber knows only their own `subId`, which is the bearer secret for +`{subPath}/{subId}`, `{subPath}/{subId}/hwid-status`, the JSON, Clash, Mihomo +and legacy Clash variants, and the HTML subscription page (`internal/sub/`). + +- Each subscriber must see only their own clients. Check subId guessing or + enumeration, timing or status differences that confirm a subId, and + cross-client leakage through shared inbounds, hosts, external links or + caches. +- Request headers are attacker-controlled and partly persisted: `X-HWID`, + `User-Agent`, `X-Device-OS`, `X-Ver-OS` and `X-Device-Model` land in + `client_hwids` and are shown to the admin. `User-Agent` also selects the + output format through admin-set regular expressions. +- The subscription page injects JSON into an inline `