mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[GH-ISSUE #6947] [Feature]: RFC: Secure, versioned plugin API for optional 3x-ui extensions #4598
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#4598
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @HamedSanaei on GitHub (Oct 26, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6947
Is your feature request related to a problem?
3x-ui should remain lightweight, stable, and focused on core proxy management. However, there are useful features that only a small subset of operators need. Merging all of them into the core increases maintenance, database, CPU, and memory costs for everyone.
For example, traffic history by arbitrary date range (#6353) is useful to some operators but does not justify mandatory historical storage for all installations. A community member has already built an external companion for that use case: 3x-ui-traffic-monitor.
I propose a documented, versioned plugin/extension standard so operators can add optional features without forking 3x-ui or making the core panel carry every specialized requirement.
Prior art / not a duplicate: The general plugin request #4306 was closed, and PR #5789 (manifest, ZIP installation, catalog/UI, but no executable runtime) was closed without merging. This issue requests agreement on a minimal, secure extension contract and integration points, rather than immediately adding an unrestricted plugin installer.
Describe the solution you'd like
An opt-in, capability-based plugin API, with the following design principles:
Important accounting limitation: Xray's current per-user stats aggregate traffic by email across inbounds. A plugin cannot reliably apply different coefficients to Hosts, IPv6, CDN, or individual inbounds without a trustworthy source of per-route/per-inbound byte attribution. The standard should expose only accurate, available signals (e.g. per-node deltas when attributable), clearly distinguish raw usage from billable usage, and never silently approximate or overwrite core quota counters. Any quota-affecting plugin would require a separately reviewed, atomic accounting policy hook.
Concrete use cases
Suggested minimal implementation / acceptance criteria
Phase 1 — RFC and protocol first: Agree on the security boundaries, permission model, versioned manifest, supported read APIs/events, delivery/retry semantics, and compatibility rules. Reuse existing authenticated panel APIs where sufficient. Demonstrate one read-only companion plugin end to end.
Phase 2 — opt-in extension host: Add explicit plugin registration/lifecycle and a small set of safe, versioned event/API hooks. Verify disabled-plugin overhead is negligible, failures are isolated, upgrades remain backward compatible, and behavior is tested on SQLite/PostgreSQL and multi-node setups.
Phase 3 — privileged extensions only after separate review: Billing modifiers, delegated-admin authorization, and other operations that affect quotas or access control need dedicated design and security reviews, not generic unrestricted hooks.
Acceptance: Existing installations operate unchanged when no plugins are enabled; no silent traffic double-counting; no privilege escalation; documented sample, tests, migration/rollback and failure-handling strategy.
Alternatives you've considered
Maintainer discussion requested
@MHSanaei, would a small, secure, out-of-process plugin API standard be acceptable in principle, or do you prefer third-party integrations to remain entirely external through the existing REST API? If acceptable, I suggest agreeing on the contract and MVP scope before opening another large implementation PR.
Related: #4306 (closed), #5789 (closed, unmerged), #6353, #5791, #6509.
Which parts of the panel would this affect?
Backend/API, frontend/plugin management, security/permissions, optional statistics and subscription integration, database only if strictly necessary.
Before submitting
@github-actions[bot] commented on GitHub (Oct 26, 2026):
This is a feature request and a design question for the maintainer. The current code has no plugin or extension host. Whether to add one is a project-direction decision that the source can't answer, so this reply only maps what exists today against what the RFC asks for.
What already exists that an out-of-process companion can use
/panel/api/*acceptAuthorization: Bearer <token>(internal/web/controller/api.go:46). The token's scope is enforced byenforceTokenScope(api.go:142). The known scopes are fixed ininternal/database/model/model.go:167-170:admin,monitor,node-sync,node-admin.monitorscope is too narrow for your use cases. It is a GET-only allowlist of server/Xray/node health endpoints (monitorScopeAllow,api.go:84-95). It does not cover inbound or client traffic reads. So a read-only companion like the traffic-monitor project you link has to hold anadmintoken today. That gap matches your "lack a consistent permission/capability contract" point. A narrower read-only scope (e.g. clients/traffic GET-only) would be the smallest concrete step toward your Phase 1, and it fits the existing allowlist mechanism.internal/eventbus/events.go:8-26defines onlyoutbound.down/up,xray.crash,node.down/up,cpu.high,memory.highandlogin.attempt. Its only subscribers are the in-process email, Discord and Telegram notifiers (internal/web/web.go:670,678,754). There are no client lifecycle or traffic events, and no webhook delivery (nowebhookmatch anywhere underinternal/). Your Phase 2 would need new event types, plus a delivery, retry and idempotency layer that doesn't exist yet.Your accounting caveat is correct. Client traffic is parsed from Xray stats by
clientTrafficRegex = regexp.MustCompile(\user>>>([^>]+)>>>traffic>>>(downlink|uplink)`)(internal/xray/api.go:51`). That counter is keyed only by email, so per-inbound or per-route coefficients can't be attributed from it.Prior attempts: #4306 (generic plugin request) is closed, and PR #5789 ("add plugin contract and installer UI") was closed without being merged. #6353 (traffic history by date range) is still open. This RFC is a narrower re-proposal, not a duplicate.
You asked the maintainer about this directly, so the decision is theirs. A practical way to split it: (1) a read-only API-token scope for client/inbound/traffic data, and (2) outbound client lifecycle events. Each can be decided on its own, before any generic plugin host is designed.
Verdict: Feature request
This reply was generated automatically; a maintainer may follow up.
@HamedSanaei commented on GitHub (Oct 28, 2026):
Proposal: a secure, versioned Extension Platform (discussion draft)
I reviewed the current Go/Gin backend, REST authorization, in-process event bus, React/Vite frontend, and the closed plugin PR #5789. My recommendation is to build a VS Code-like extension developer experience, but not to execute arbitrary third-party Go/JS code inside the 3x-ui process. The first milestone should be an agreed, versioned integration contract—not a ZIP installer or marketplace.
1. Architecture and trust boundary
2. Versioned manifest and compatibility contract
For discussion only (not currently supported):
Document unique IDs, JSON Schema, stable capability naming, API/manifest versions, compatibility negotiation, optional vs required permissions, upgrade/downgrade and rollback rules, configuration/secrets handling, disable/uninstall behavior, and a sample SDK/companion. Requested capabilities should be individually approved and server-enforced, not trusted merely because they appear in a manifest.
3. Reuse existing infrastructure without assuming it is sufficient
Auth and APIs:
internal/web/controller/api.goalready supports Bearer tokens and exact route/method allowlists, butmonitoris limited to health and metrics. A read-only analytics companion currently needs a broadadmintoken to read clients/inbounds/traffic. A narrow read-only scope (or capability-based authorization) with pagination, filtering, redaction and negative authorization tests would be a useful standalone first PR. Do not leak secrets, private keys, or unrelated tenants' information.Events:
internal/eventbus/bus.gois best-effort, in-memory, and explicitly drops events on full queues; process restart also loses buffered events. It should not be treated as reliable billing/event delivery. For integration events requiring delivery guarantees, use an opt-in transactional outbox (SQLite + PostgreSQL), stable event IDs and schemas, at-least-once delivery, bounded retries/backoff, replay/retention, subscriber checkpoints and idempotent consumers. Avoid synchronous callbacks/network I/O in the traffic hot path. If this is too much for v1, use a pull-only read API first.Frontend: React/Vite is compiled and embedded, and routes/sidebar are built from
frontend/src/routes/panelRoutes.tsx. A single compiled/extensions/:id/*host route with registered sidebar metadata is preferable to dynamic arbitrary module injection. Render any third-party UI via a sandboxed iframe on an isolated origin, with CSP and a tightly validatedpostMessagebridge; no third-party JS in the authenticated panel origin. Backend-only extensions should work without any UI contribution.Master/node: Define plugin scope (master, node, or per-installation), node identity and permissions, deduplication, and the provenance of traffic/events. Extensions must not bypass node-sync authorization or double-count master/node data.
4. Important accounting/security limitations
internal/xray/api.go). They cannot prove per-Host/CDN/IPv6 route byte attribution, so a generic extension cannot safely implement such multipliers using existing counters.5. Suggested PR sequence
For each applicable PR, cover SQLite and PostgreSQL, disabled-plugin behavior, failed/unavailable extensions, restart/recovery, and master/node integration. A runnable, genuinely read-only sample is essential for verifying the API contract.
6. Questions for maintainers and contributors
PR #5789 is useful prior art but was closed without merge; I would not resurrect it as a single large PR. I'd rather establish a minimal contract and land independently reviewable foundations.
Success criterion: with extensions disabled, existing installations behave exactly as before with negligible idle overhead; enabled extensions cannot escalate privileges or disrupt core services; the API stays versioned and testable.