[GH-ISSUE #5504] [Bug/Potential]: Node sync can create recursive inbound/client imports between panels #3841

Closed
opened 2026-10-31 20:35:20 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @atem32 on GitHub (Jun 23, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5504

Describe the bug

The new node feature can import inbounds and clients from another 3x-ui panel via API.

When the node feature is enabled, the panel requests another panel through the API and stores the received data into local inbounds and clients.

As a result, the local panel may contain both its own local inbounds/clients and remote inbounds/clients imported from another panel.

This can potentially create a recursive import loop if multiple panels are configured as nodes of each other.

Example topology:

Panel 1 imports nodes: Panel 2 + Panel 3
Panel 3 imports nodes: Panel 1 + Panel 2

In this situation, Panel 1 imports data from Panel 2 and Panel 3.

If Panel 3 also imports data from Panel 1, and Panel 1 already contains imported data from Panel 2 and Panel 3, then Panel 3 may import not only Panel 1's own local data, but also data that Panel 1 previously imported from Panel 2 and Panel 3.

This may create duplicated inbounds/clients or recursive propagation of remote data between panels.

The same problem may happen in the opposite direction when Panel 1 imports Panel 3 again after Panel 3 has already imported data from Panel 1.

The concern is that the node sync mechanism may not distinguish between:

local data created on the source panel

and

remote data imported from another node

If imported remote data is exported again through the API and then imported by another panel, this can create a loop.

How to reproduce the problem

Create three panels:

Panel 1
Panel 2
Panel 3

Enable the node feature on Panel 1.

Configure Panel 1 to import data from:

Panel 2
Panel 3

Enable the node feature on Panel 3.

Configure Panel 3 to import data from:

Panel 1
Panel 2

Let both panels perform node sync.

Panel 1 imports inbounds and clients from Panel 2 and Panel 3.

Panel 3 imports inbounds and clients from Panel 1 and Panel 2.

If the API response from Panel 1 includes not only Panel 1's own local data, but also data previously imported from Panel 2 and Panel 3, then Panel 3 may import duplicated or already-imported data.

After another sync cycle, the same data may be propagated back again.

This can potentially create a loop like this:

Panel 1 = local Panel 1 data + Panel 2 data + Panel 3 data
Panel 3 = local Panel 3 data + Panel 1 data + Panel 2 data

But since Panel 1 data may already contain Panel 2 and Panel 3 imported data, Panel 3 may effectively receive:

Panel 3 = local Panel 3 data + Panel 1 local data + Panel 2 data + Panel 3 imported data + Panel 2 data

This may lead to duplicated inbounds, duplicated clients, inconsistent ownership, or repeated propagation between panels.

Expected behavior

The node sync mechanism should avoid recursive imports.

A panel should not re-export remote data that was imported from another node, unless this behavior is explicitly intended and safely deduplicated.

The panel should distinguish between:

local inbounds/clients

and

remote inbounds/clients imported from another node

When Panel 3 imports data from Panel 1, it should receive only Panel 1's local data, not data that Panel 1 previously imported from Panel 2 or Panel 3.

Alternatively, every imported inbound/client should have metadata such as:

sourcePanelId
sourceNodeId
originalPanelId
importedFromNode
isRemote

The sync process should use this metadata to prevent loops and duplicates.

For example, if Panel 3 receives an inbound from Panel 1, but that inbound originally came from Panel 3, it should be ignored.

If the same client or inbound already exists from the same original source, it should be updated or skipped instead of duplicated.

The system should also detect circular node configurations and either block them or show a warning before saving.

Example warning:

Circular node import detected: Panel 1 imports Panel 3, and Panel 3 imports Panel 1. Remote imported data will not be re-exported.

The safest expected behavior would be:

API used for node sync returns only local inbounds and local clients from the source panel.

or:

API can return remote imported objects, but every object must preserve origin metadata and must be deduplicated by original source.

Actual behavior

It looks like the node feature stores imported API data into local inbounds and clients.

If these imported objects are then exposed again through the same API used by other panels, another panel may import already-imported data.

In a topology where panels are connected to each other as nodes, this can potentially create recursive data propagation.

Example:

Panel 1 imports Panel 2 and Panel 3.
Panel 3 imports Panel 1 and Panel 2.

Panel 1 stores:

Panel 1 local data
Panel 2 imported data
Panel 3 imported data

Panel 3 then imports Panel 1.

If Panel 1 exposes all stored data through API, Panel 3 may receive:

Panel 1 local data
Panel 2 imported data
Panel 3 imported data

This means Panel 3 can receive its own data back through Panel 1, and may also receive Panel 2 data twice.

This may cause duplicated inbounds, duplicated clients, incorrect ownership, or continuous data growth after repeated sync cycles.

I am reporting this as a potential bug / design issue because the current behavior should be clarified and protected against circular node configurations.

Relevant logs

No logs available at the moment.

The issue can be verified by checking the data returned by the node API.

The important thing to check is whether the API returns only local data from the source panel, or whether it also returns data that was previously imported from other nodes.

For example, after configuring:

    Panel 1 imports Panel 2 + Panel 3
    Panel 3 imports Panel 1 + Panel 2

check whether Panel 1 API response includes only Panel 1 local inbounds/clients, or includes imported Panel 2/Panel 3 data as well.

If imported remote data appears in the API response and can be imported by another node again, then recursive propagation is possible.

Screenshots

No screenshots available at the moment.

A diagram of the problematic topology:

Panel 1 imports: Panel 2 + Panel 3
Panel 3 imports: Panel 1 + Panel 2

Potential loop:

Panel 1 -> imports Panel 3
Panel 3 -> imports Panel 1
Panel 1 -> may already contain imported Panel 3 data
Panel 3 -> may receive its own data back from Panel 1

3x-ui version

3.3.1

Xray-core version

26.1.1

How did you install 3x-ui?

install.sh script

Operating system

Debian 12

Which parts of the panel are affected?

Multi-node (sub-nodes)

Browser (only if it is a UI bug)

No response

Is the panel behind a reverse proxy or CDN?

None

Before submitting

  • I searched existing issues and this bug has not been reported.
  • I am running the latest released version of 3x-ui (or have verified the bug still exists on it).
  • This bug report is written in English.
  • I have redacted any sensitive data (tokens, real domains, client UUIDs).
Originally created by @atem32 on GitHub (Jun 23, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5504 ### Describe the bug The new node feature can import inbounds and clients from another 3x-ui panel via API. When the node feature is enabled, the panel requests another panel through the API and stores the received data into local `inbounds` and `clients`. As a result, the local panel may contain both its own local inbounds/clients and remote inbounds/clients imported from another panel. This can potentially create a recursive import loop if multiple panels are configured as nodes of each other. Example topology: Panel 1 imports nodes: Panel 2 + Panel 3 Panel 3 imports nodes: Panel 1 + Panel 2 In this situation, Panel 1 imports data from Panel 2 and Panel 3. If Panel 3 also imports data from Panel 1, and Panel 1 already contains imported data from Panel 2 and Panel 3, then Panel 3 may import not only Panel 1's own local data, but also data that Panel 1 previously imported from Panel 2 and Panel 3. This may create duplicated inbounds/clients or recursive propagation of remote data between panels. The same problem may happen in the opposite direction when Panel 1 imports Panel 3 again after Panel 3 has already imported data from Panel 1. The concern is that the node sync mechanism may not distinguish between: local data created on the source panel and remote data imported from another node If imported remote data is exported again through the API and then imported by another panel, this can create a loop. ### How to reproduce the problem Create three panels: Panel 1 Panel 2 Panel 3 Enable the node feature on Panel 1. Configure Panel 1 to import data from: Panel 2 Panel 3 Enable the node feature on Panel 3. Configure Panel 3 to import data from: Panel 1 Panel 2 Let both panels perform node sync. Panel 1 imports inbounds and clients from Panel 2 and Panel 3. Panel 3 imports inbounds and clients from Panel 1 and Panel 2. If the API response from Panel 1 includes not only Panel 1's own local data, but also data previously imported from Panel 2 and Panel 3, then Panel 3 may import duplicated or already-imported data. After another sync cycle, the same data may be propagated back again. This can potentially create a loop like this: Panel 1 = local Panel 1 data + Panel 2 data + Panel 3 data Panel 3 = local Panel 3 data + Panel 1 data + Panel 2 data But since Panel 1 data may already contain Panel 2 and Panel 3 imported data, Panel 3 may effectively receive: Panel 3 = local Panel 3 data + Panel 1 local data + Panel 2 data + Panel 3 imported data + Panel 2 data This may lead to duplicated inbounds, duplicated clients, inconsistent ownership, or repeated propagation between panels. ### Expected behavior The node sync mechanism should avoid recursive imports. A panel should not re-export remote data that was imported from another node, unless this behavior is explicitly intended and safely deduplicated. The panel should distinguish between: local inbounds/clients and remote inbounds/clients imported from another node When Panel 3 imports data from Panel 1, it should receive only Panel 1's local data, not data that Panel 1 previously imported from Panel 2 or Panel 3. Alternatively, every imported inbound/client should have metadata such as: sourcePanelId sourceNodeId originalPanelId importedFromNode isRemote The sync process should use this metadata to prevent loops and duplicates. For example, if Panel 3 receives an inbound from Panel 1, but that inbound originally came from Panel 3, it should be ignored. If the same client or inbound already exists from the same original source, it should be updated or skipped instead of duplicated. The system should also detect circular node configurations and either block them or show a warning before saving. Example warning: Circular node import detected: Panel 1 imports Panel 3, and Panel 3 imports Panel 1. Remote imported data will not be re-exported. The safest expected behavior would be: API used for node sync returns only local inbounds and local clients from the source panel. or: API can return remote imported objects, but every object must preserve origin metadata and must be deduplicated by original source. ### Actual behavior It looks like the node feature stores imported API data into local `inbounds` and `clients`. If these imported objects are then exposed again through the same API used by other panels, another panel may import already-imported data. In a topology where panels are connected to each other as nodes, this can potentially create recursive data propagation. Example: Panel 1 imports Panel 2 and Panel 3. Panel 3 imports Panel 1 and Panel 2. Panel 1 stores: Panel 1 local data Panel 2 imported data Panel 3 imported data Panel 3 then imports Panel 1. If Panel 1 exposes all stored data through API, Panel 3 may receive: Panel 1 local data Panel 2 imported data Panel 3 imported data This means Panel 3 can receive its own data back through Panel 1, and may also receive Panel 2 data twice. This may cause duplicated inbounds, duplicated clients, incorrect ownership, or continuous data growth after repeated sync cycles. I am reporting this as a potential bug / design issue because the current behavior should be clarified and protected against circular node configurations. ### Relevant logs ```shell No logs available at the moment. The issue can be verified by checking the data returned by the node API. The important thing to check is whether the API returns only local data from the source panel, or whether it also returns data that was previously imported from other nodes. For example, after configuring: Panel 1 imports Panel 2 + Panel 3 Panel 3 imports Panel 1 + Panel 2 check whether Panel 1 API response includes only Panel 1 local inbounds/clients, or includes imported Panel 2/Panel 3 data as well. If imported remote data appears in the API response and can be imported by another node again, then recursive propagation is possible. ``` ### Screenshots No screenshots available at the moment. A diagram of the problematic topology: Panel 1 imports: Panel 2 + Panel 3 Panel 3 imports: Panel 1 + Panel 2 Potential loop: Panel 1 -> imports Panel 3 Panel 3 -> imports Panel 1 Panel 1 -> may already contain imported Panel 3 data Panel 3 -> may receive its own data back from Panel 1 ### 3x-ui version 3.3.1 ### Xray-core version 26.1.1 ### How did you install 3x-ui? install.sh script ### Operating system Debian 12 ### Which parts of the panel are affected? Multi-node (sub-nodes) ### Browser (only if it is a UI bug) _No response_ ### Is the panel behind a reverse proxy or CDN? None ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this bug has not been reported. - [x] I am running the latest released version of 3x-ui (or have verified the bug still exists on it). - [x] This bug report is written in English. - [x] I have redacted any sensitive data (tokens, real domains, client UUIDs).
bsakaguchi 2026-10-31 20:35:20 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@github-actions[bot] commented on GitHub (Jun 23, 2026):

Claude finished @MHSanaei's task in 3m 2s —— View job


Node sync: recursive-import analysis

Thanks for the detailed report. I traced the node-sync path end to end. Short version: your core observation is correct — the sync API does return inbounds a panel previously imported from its own sub-nodes, not just its local ones — but this is intentional for the chained Node1 → Node2 → Node3 topology (#4983), and it is partly protected. The genuine gap is that there is no guard against a true cycle (two panels importing each other), where data can round-trip and create duplicates.

How node sync actually works

The relationship is master → node (import). The master pulls a snapshot from each node and stores it locally:

  • internal/web/job/node_traffic_sync_job.go:345 — FetchTrafficSnapshot per node, then SetRemoteTraffic merges it.
  • internal/web/runtime/remote.go:615-624 — the snapshot is fetched from the node's panel/api/inbounds/list endpoint.
  • That endpoint is InboundService.GetInbounds (internal/web/service/inbound.go:152-163), which returns every inbound owned by the user — including ones with node_id set, i.e. inbounds the node itself imported from its sub-nodes.
  • The merge is setRemoteTrafficLocked (internal/web/service/inbound_node.go:227). Imported inbounds are stored locally with node_id = <that node> and an origin_node_guid attributing them to the panel that physically hosts them (originGuidFor, inbound_node.go:247-252; create path :439-470).

So yes — when Panel 3 fetches Panel 1's list, it receives Panel 1's own inbounds plus Panel 1's imported Panel 2/Panel 3 inbounds. This is deliberate: it is exactly how a master sees inbounds two hops down through an intermediate node.

What is already protected

  • Attribution / counting is deduplicated by origin_node_guid, not by which node forwarded the data. recountByGuid (internal/web/service/node_tree.go:165-241) buckets each inbound and online client under its true physical-host GUID, so a forwarded inbound is not double-counted in the Nodes page. The chained DAG case relies on this and works correctly.
  • Clients do not multiply: client_traffics is keyed unique on email, and the import upsert uses OnConflict{email} DoNothing (inbound_node.go:634), so a re-seen email does not create a second client row.
  • Tag collisions are handled by an n<id>- prefix fallback (pickFreeTag, inbound_node.go:406-437).
  • An empty snapshot is ignored rather than treated as "delete everything" (inbound_node.go:521-533).

The actual gap

There is no check that skips importing an inbound whose origin_node_guid equals the importing panel's own GUID, and no detection of circular node configuration. originGuidFor keeps any different, non-empty origin as-is — it never asks "is this origin me?" In a true cycle (Panel 1 ↔ Panel 3):

  1. Panel 3 imports from Panel 1. Panel 1's list contains a Panel-3-origin inbound (origin_node_guid = guid3).
  2. Panel 3 has no self-origin guard, so it stores that as a new inbound under node_id = <Panel 1's node row>. Because the tag collides with Panel 3's own local inbound, pickFreeTag assigns the n<id>- prefixed variant — a duplicate inbound.
  3. Those duplicate inbounds carry Panel 3's own client emails. Traffic merge then adds deltas for the same emails under a second (node, email) baseline, on top of Panel 3's local Xray counting them — i.e. inflated/double-counted traffic for the round-tripped clients.

The clients themselves stay single rows (email-unique), but the duplicate inbounds and traffic inflation are real, and each sync cycle can keep re-propagating, matching what you described.

Important caveat: this requires an operator to deliberately point two panels at each other as nodes. It is a misconfiguration the system neither prevents nor warns about — not something that arises from a normal tree/DAG of nodes.

On the suggested fixes

  • "Return only local inbounds from the sync API" would regress #4983: the intermediate-node case depends on a node forwarding the inbounds it imported from its own sub-nodes. A blanket local-only filter would make a master blind to anything two hops away.
  • The metadata you suggest (origin/source) already exists as origin_node_guid (internal/database/model/model.go); it is just not used as a loop-breaker on the import side.

The cleanest fix within the existing patterns would be, on import in setRemoteTrafficLocked, to skip any snapshot inbound whose origin_node_guid equals this panel's own panelGuid (available via SettingService.GetPanelGuid(), already used at inbound_node.go:956). That breaks the cycle while preserving legitimate chaining, since a genuine sub-node's inbound never carries the importing panel's own GUID. A complementary, lower-priority improvement would be a warning when a configured node's reported panelGuid matches this panel's own GUID (a self/cycle reference), surfaced where duplicate GUIDs are already detected (warnOnDuplicateGuid, node.go:723).

Note this is research only — I have not made any code change. I have confirmed the data flow and the missing self-origin guard in the current main; whether and how to address it is for the maintainer to decide.
· claude/issue-5504-20260623-1531

<!-- gh-comment-id:4780788995 --> @github-actions[bot] commented on GitHub (Jun 23, 2026): **Claude finished @MHSanaei's task in 3m 2s** —— [View job](https://github.com/MHSanaei/3x-ui/actions/runs/28037215132) --- ### Node sync: recursive-import analysis Thanks for the detailed report. I traced the node-sync path end to end. Short version: your core observation is correct — the sync API does return inbounds a panel previously imported from its own sub-nodes, not just its local ones — but this is **intentional** for the chained `Node1 → Node2 → Node3` topology (#4983), and it is partly protected. The genuine gap is that there is **no guard against a true cycle** (two panels importing each other), where data can round-trip and create duplicates. ### How node sync actually works The relationship is master → node (import). The master pulls a snapshot from each node and stores it locally: - `internal/web/job/node_traffic_sync_job.go:345` — `FetchTrafficSnapshot` per node, then `SetRemoteTraffic` merges it. - `internal/web/runtime/remote.go:615-624` — the snapshot is fetched from the node's `panel/api/inbounds/list` endpoint. - That endpoint is `InboundService.GetInbounds` (`internal/web/service/inbound.go:152-163`), which returns **every** inbound owned by the user — including ones with `node_id` set, i.e. inbounds the node itself imported from *its* sub-nodes. - The merge is `setRemoteTrafficLocked` (`internal/web/service/inbound_node.go:227`). Imported inbounds are stored locally with `node_id = <that node>` and an `origin_node_guid` attributing them to the panel that physically hosts them (`originGuidFor`, `inbound_node.go:247-252`; create path `:439-470`). So yes — when Panel 3 fetches Panel 1's list, it receives Panel 1's own inbounds *plus* Panel 1's imported Panel 2/Panel 3 inbounds. This is deliberate: it is exactly how a master sees inbounds two hops down through an intermediate node. ### What is already protected - **Attribution / counting** is deduplicated by `origin_node_guid`, not by which node forwarded the data. `recountByGuid` (`internal/web/service/node_tree.go:165-241`) buckets each inbound and online client under its true physical-host GUID, so a forwarded inbound is not double-counted in the Nodes page. The chained DAG case relies on this and works correctly. - **Clients do not multiply**: `client_traffics` is keyed unique on `email`, and the import upsert uses `OnConflict{email} DoNothing` (`inbound_node.go:634`), so a re-seen email does not create a second client row. - **Tag collisions** are handled by an `n<id>-` prefix fallback (`pickFreeTag`, `inbound_node.go:406-437`). - An **empty snapshot is ignored** rather than treated as "delete everything" (`inbound_node.go:521-533`). ### The actual gap There is **no check that skips importing an inbound whose `origin_node_guid` equals the importing panel's own GUID**, and **no detection of circular node configuration**. `originGuidFor` keeps any different, non-empty origin as-is — it never asks "is this origin *me*?" In a true cycle (Panel 1 ↔ Panel 3): 1. Panel 3 imports from Panel 1. Panel 1's list contains a Panel-3-origin inbound (`origin_node_guid = guid3`). 2. Panel 3 has no self-origin guard, so it stores that as a **new** inbound under `node_id = <Panel 1's node row>`. Because the tag collides with Panel 3's own local inbound, `pickFreeTag` assigns the `n<id>-` prefixed variant — a **duplicate inbound**. 3. Those duplicate inbounds carry Panel 3's own client emails. Traffic merge then adds deltas for the same emails under a second `(node, email)` baseline, on top of Panel 3's local Xray counting them — i.e. **inflated/double-counted traffic** for the round-tripped clients. The clients themselves stay single rows (email-unique), but the duplicate inbounds and traffic inflation are real, and each sync cycle can keep re-propagating, matching what you described. Important caveat: this requires an operator to deliberately point two panels at each other as nodes. It is a misconfiguration the system neither prevents nor warns about — not something that arises from a normal tree/DAG of nodes. ### On the suggested fixes - "Return only local inbounds from the sync API" would **regress #4983**: the intermediate-node case depends on a node forwarding the inbounds it imported from its own sub-nodes. A blanket local-only filter would make a master blind to anything two hops away. - The metadata you suggest (`origin/source`) **already exists** as `origin_node_guid` (`internal/database/model/model.go`); it is just not used as a loop-breaker on the import side. The cleanest fix within the existing patterns would be, on import in `setRemoteTrafficLocked`, to **skip any snapshot inbound whose `origin_node_guid` equals this panel's own `panelGuid`** (available via `SettingService.GetPanelGuid()`, already used at `inbound_node.go:956`). That breaks the cycle while preserving legitimate chaining, since a genuine sub-node's inbound never carries the importing panel's own GUID. A complementary, lower-priority improvement would be a warning when a configured node's reported `panelGuid` matches this panel's own GUID (a self/cycle reference), surfaced where duplicate GUIDs are already detected (`warnOnDuplicateGuid`, `node.go:723`). Note this is research only — I have not made any code change. I have confirmed the data flow and the missing self-origin guard in the current `main`; whether and how to address it is for the maintainer to decide. · `claude/issue-5504-20260623-1531`
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#3841
No description provided.