[GH-ISSUE #5304] [Bug]: Default xray API inbound port may conflict with user-created inbound port #3717

Closed
opened 2026-10-31 20:34:27 +07:00 by bsakaguchi · 2 comments
Owner

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

Describe the bug

3x-ui creates a default API inbound using the 62789 port. It is possible to create an inbound using the same port without any warning. Xray then listens on the same port with two different inbounds, causing requests to be distributed between them unpredictably.

How to reproduce the problem

Install 3x-ui with default settings.
Create an inbound using 62789 port
Try to connect with xray client/curl/etc

Expected behavior

3x-ui should prevent port conflicts or display a warning when another inbound already uses the selected port. This already happens with inbounds added by users, but not with the default inbound

Actual behavior

Two inbounds listen on the same port. Some requests are handled by the user's inbound and others by the API tunnel inbound, causing intermittent failures.

Relevant logs

sudo ss -lntp 'sport = :62789'
State              Recv-Q              Send-Q                           Local Address:Port                            Peer Address:Port             Process                                                 
LISTEN             0                   4096                                 127.0.0.1:62789                                0.0.0.0:*                 users:(("xray-linux-amd6",pid=10663,fd=4))             
LISTEN             0                   4096                                         *:62789                                      *:*                 users:(("xray-linux-amd6",pid=10663,fd=7))   


curl -v http://127.0.0.1:62789/
*   Trying 127.0.0.1:62789...
* Connected to 127.0.0.1 (127.0.0.1) port 62789
> GET / HTTP/1.1
> Host: 127.0.0.1:62789
> User-Agent: curl/8.5.0
> Accept: */*
> 
< HTTP/1.1 404 Not Found
< Date: Sun, 14 Jun 2026 00:57:28 GMT
< Content-Length: 0
< 
* Connection #0 to host 127.0.0.1 left intact
curl -v http://127.0.0.1:62789/
*   Trying 127.0.0.1:62789...
* Connected to 127.0.0.1 (127.0.0.1) port 62789
> GET / HTTP/1.1
> Host: 127.0.0.1:62789
> User-Agent: curl/8.5.0
> Accept: */*
> 
* Received HTTP/0.9 when not allowed
* Closing connection
curl: (1) Received HTTP/0.9 when not allowed

Screenshots

No response

3x-ui version

3.3.1

Xray-core version

26.6.1

How did you install 3x-ui?

install.sh script

Operating system

Ubuntu 24.04

Which parts of the panel are affected?

Frontend (UI / panel pages), Xray config generation

Browser (only if it is a UI bug)

No response

Is the panel behind a reverse proxy or CDN?

Yes — Nginx

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 @m0nstrum on GitHub (Jun 14, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5304 ### Describe the bug 3x-ui creates a default API inbound using the 62789 port. It is possible to create an inbound using the same port without any warning. Xray then listens on the same port with two different inbounds, causing requests to be distributed between them unpredictably. ### How to reproduce the problem Install 3x-ui with default settings. Create an inbound using 62789 port Try to connect with xray client/curl/etc ### Expected behavior 3x-ui should prevent port conflicts or display a warning when another inbound already uses the selected port. This already happens with inbounds added by users, but not with the default inbound ### Actual behavior Two inbounds listen on the same port. Some requests are handled by the user's inbound and others by the API tunnel inbound, causing intermittent failures. ### Relevant logs ```shell sudo ss -lntp 'sport = :62789' State Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 4096 127.0.0.1:62789 0.0.0.0:* users:(("xray-linux-amd6",pid=10663,fd=4)) LISTEN 0 4096 *:62789 *:* users:(("xray-linux-amd6",pid=10663,fd=7)) curl -v http://127.0.0.1:62789/ * Trying 127.0.0.1:62789... * Connected to 127.0.0.1 (127.0.0.1) port 62789 > GET / HTTP/1.1 > Host: 127.0.0.1:62789 > User-Agent: curl/8.5.0 > Accept: */* > < HTTP/1.1 404 Not Found < Date: Sun, 14 Jun 2026 00:57:28 GMT < Content-Length: 0 < * Connection #0 to host 127.0.0.1 left intact curl -v http://127.0.0.1:62789/ * Trying 127.0.0.1:62789... * Connected to 127.0.0.1 (127.0.0.1) port 62789 > GET / HTTP/1.1 > Host: 127.0.0.1:62789 > User-Agent: curl/8.5.0 > Accept: */* > * Received HTTP/0.9 when not allowed * Closing connection curl: (1) Received HTTP/0.9 when not allowed ``` ### Screenshots _No response_ ### 3x-ui version 3.3.1 ### Xray-core version 26.6.1 ### How did you install 3x-ui? install.sh script ### Operating system Ubuntu 24.04 ### Which parts of the panel are affected? Frontend (UI / panel pages), Xray config generation ### Browser (only if it is a UI bug) _No response_ ### Is the panel behind a reverse proxy or CDN? Yes — Nginx ### 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:34:27 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

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

The bug is confirmed and the root cause is clear.

Root cause

The port-conflict check (checkPortConflict in internal/web/service/port_conflict.go:129) only queries the inbounds database table. The API inbound is not in that table — it is defined in the embedded Xray config template (internal/web/service/config.json, port 62789, listen: "127.0.0.1") and injected at runtime by GetXrayConfig() in internal/web/service/xray.go:107. Because the conflict check never sees the API inbound, AddInbound (line 573) and UpdateInbound (line 934 of inbound.go) both pass validation for port 62789 without any warning.

At Xray start, the resulting merged config contains two inbounds on port 62789:

  • The API tunnel bound to 127.0.0.1:62789 (from the template).
  • The user-created inbound bound to *:62789 (from the database).

This matches exactly what ss -lntp shows in the report.

Additional detail

The API port is not hardcoded to 62789 at the conflict-check layer — users can edit the Xray config template via the panel settings, changing the API inbound's port. Any fix therefore needs to read the current template and extract the actual API inbound port at validation time, rather than hardcoding 62789.

Workaround (until fixed)

Do not use port 62789 (or whichever port is configured for the "api" tag inbound in your Xray config template) for user-created inbounds. You can check the active API port by looking at the inbounds section of your Xray config template in the panel settings under Xray Settings → Xray Configuration.

No additional information is needed to reproduce or fix this issue.

This reply was generated automatically; a maintainer may follow up.

<!-- gh-comment-id:4700337054 --> @github-actions[bot] commented on GitHub (Jun 14, 2026): The bug is confirmed and the root cause is clear. **Root cause** The port-conflict check (`checkPortConflict` in `internal/web/service/port_conflict.go:129`) only queries the `inbounds` database table. The API inbound is not in that table — it is defined in the embedded Xray config template (`internal/web/service/config.json`, port 62789, `listen: "127.0.0.1"`) and injected at runtime by `GetXrayConfig()` in `internal/web/service/xray.go:107`. Because the conflict check never sees the API inbound, `AddInbound` (line 573) and `UpdateInbound` (line 934 of `inbound.go`) both pass validation for port 62789 without any warning. At Xray start, the resulting merged config contains two inbounds on port 62789: - The API tunnel bound to `127.0.0.1:62789` (from the template). - The user-created inbound bound to `*:62789` (from the database). This matches exactly what `ss -lntp` shows in the report. **Additional detail** The API port is not hardcoded to 62789 at the conflict-check layer — users can edit the Xray config template via the panel settings, changing the API inbound's port. Any fix therefore needs to read the current template and extract the actual API inbound port at validation time, rather than hardcoding 62789. **Workaround (until fixed)** Do not use port 62789 (or whichever port is configured for the `"api"` tag inbound in your Xray config template) for user-created inbounds. You can check the active API port by looking at the `inbounds` section of your Xray config template in the panel settings under **Xray Settings → Xray Configuration**. No additional information is needed to reproduce or fix this issue. *This reply was generated automatically; a maintainer may follow up.*
Author
Owner

@MHSanaei commented on GitHub (Jun 15, 2026):

Fixed on main in 0d87bb8b. Creating a local inbound on the reserved Xray API port (default 62789) is now reported as a port conflict instead of silently letting Xray bind the port twice. Nodes are unaffected (they run their own Xray). Ships in the next release.

<!-- gh-comment-id:4709488643 --> @MHSanaei commented on GitHub (Jun 15, 2026): Fixed on `main` in 0d87bb8b. Creating a local inbound on the reserved Xray API port (default `62789`) is now reported as a port conflict instead of silently letting Xray bind the port twice. Nodes are unaffected (they run their own Xray). Ships in the next release.
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#3717
No description provided.