[GH-ISSUE #5622] [Bug]: API endpoints return 404 in 3x-ui v3.4.1 #3922

Closed
opened 2026-10-31 20:35:55 +07:00 by bsakaguchi · 3 comments
Owner

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

Describe the bug

After updating to 3x-ui v3.4.1, the documented API endpoints are not accessible.

The panel is available and works normally through the web interface. The API documentation is also available at:

https://:/<BASE_PATH>/panel/api-docs

I generated an API Token in Settings -> Security and used it as a Bearer token as described in the documentation.

However, every documented API endpoint returns 404 Not Found.

I also tested the login endpoints (/login, /panel/login and /<BASE_PATH>/login). They return 404 or 403.

According to the documentation, programmatic clients should authenticate using a Bearer API Token, so I expected the documented API endpoints to work.

How to reproduce the problem

  1. Install or update to 3x-ui v3.4.1.
  2. Open Settings -> Security and generate an API Token.
  3. Send a request
  4. Observe the response.

Expected behavior

The API should authenticate using the Bearer token and return the requested data (or at least 401/403 if the token is invalid).

Actual behavior

The server responds with:

HTTP/1.1 404 Not Found

The same happens for the documented API endpoints.
The login endpoints also return 404 or 403.

Relevant logs

HTTP/1.1 404 Not Found
Content-Security-Policy: ...
Referrer-Policy: no-referrer
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Content-Type-Options: nosniff
X-Frame-Options: DENY

Screenshots

No response

3x-ui version

3.4.1

Xray-core version

26.6.22

How did you install 3x-ui?

install.sh script

Operating system

Ubuntu

Which parts of the panel are affected?

Backend (API endpoints, login, settings)

Browser (only if it is a UI bug)

No response

Is the panel behind a reverse proxy or CDN?

Yes — Cloudflare Tunnel

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 @hellousersxx on GitHub (Jun 27, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5622 ### Describe the bug After updating to 3x-ui v3.4.1, the documented API endpoints are not accessible. The panel is available and works normally through the web interface. The API documentation is also available at: https://<IP>:<PORT>/<BASE_PATH>/panel/api-docs I generated an API Token in Settings -> Security and used it as a Bearer token as described in the documentation. However, every documented API endpoint returns 404 Not Found. I also tested the login endpoints (/login, /panel/login and /<BASE_PATH>/login). They return 404 or 403. According to the documentation, programmatic clients should authenticate using a Bearer API Token, so I expected the documented API endpoints to work. ### How to reproduce the problem 1. Install or update to 3x-ui v3.4.1. 2. Open Settings -> Security and generate an API Token. 3. Send a request 4. Observe the response. ### Expected behavior The API should authenticate using the Bearer token and return the requested data (or at least 401/403 if the token is invalid). ### Actual behavior The server responds with: HTTP/1.1 404 Not Found The same happens for the documented API endpoints. The login endpoints also return 404 or 403. ### Relevant logs ```shell HTTP/1.1 404 Not Found Content-Security-Policy: ... Referrer-Policy: no-referrer Strict-Transport-Security: max-age=31536000; includeSubDomains X-Content-Type-Options: nosniff X-Frame-Options: DENY ``` ### Screenshots _No response_ ### 3x-ui version 3.4.1 ### Xray-core version 26.6.22 ### How did you install 3x-ui? install.sh script ### Operating system Ubuntu ### Which parts of the panel are affected? Backend (API endpoints, login, settings) ### Browser (only if it is a UI bug) _No response_ ### Is the panel behind a reverse proxy or CDN? Yes — Cloudflare Tunnel ### 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:55 +07:00
Author
Owner

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

The 404 you are seeing from API endpoints is intentional behavior in internal/web/controller/api.go: when a non-XHR request reaches /<BASE_PATH>/panel/api/... and Bearer token authentication fails, the server returns 404 (not 401) to avoid revealing that the endpoint exists. The 403 on /<BASE_PATH>/login is the CSRF middleware rejecting a POST that arrives without a prior X-CSRF-Token header. Both behaviors are by design and do not indicate a routing problem.

The core question is why your Bearer token is not passing auth. Based on the code path in ApiTokenService.Match (internal/web/service/panel/api_token.go:116-133) and your Cloudflare Tunnel setup, there are three things to rule out in order.


Step 1 — Confirm the header reaches 3x-ui (bypass Cloudflare)

Run this directly on the server so the request goes to 3x-ui without touching Cloudflare:

TOKEN="<paste your token here>"
BASE="<your base path, e.g. /abc123/>"
PORT=<your panel port>

curl -v -H "Authorization: Bearer ${TOKEN}" \
  "http://127.0.0.1:${PORT}${BASE}panel/api/server"
  • If you get 200: the token and URL are correct and Cloudflare is the problem (see Step 2).
  • If you still get 404: the token is not being recognized — go to Step 3.

Step 2 — Cloudflare Access stripping the Authorization header

Cloudflare Zero Trust (Cloudflare Access) removes the Authorization header before forwarding requests to the origin and replaces it with a CF-Access-Jwt-Assertion header. If your Cloudflare Tunnel has an Access application protecting it, your Bearer token is silently dropped before 3x-ui ever sees it.

Check in the Cloudflare dashboard under Zero Trust → Access → Applications whether there is a policy covering your panel's hostname or path. If so, you have two options:

  • Create a Bypass policy for the /panel/api/ path to let API requests through without Access authentication.
  • Alternatively, call 3x-ui directly without routing through Cloudflare Access for API traffic.

Even without an Access application, verify that no HTTP header modification rules (Transform Rules) in your Cloudflare zone strip or overwrite the Authorization header.


Step 3 — Regenerate the token

Tokens are stored as SHA-256 hashes (internal/web/service/panel/api_token.go:78). The plaintext is shown exactly once at creation. If there was any copy-paste issue (trailing newline, invisible character, partial copy), the hash will not match.

Go to Settings → Security, delete the existing token, create a new one, and copy it immediately from the panel before navigating away.


Step 4 — Confirm the full URL

The entire panel is mounted under the randomly-generated base path (internal/web/web.go:246). API endpoints are at:

https://<host>/<BASE_PATH>/panel/api/inbounds
https://<host>/<BASE_PATH>/panel/api/server

The paths /login, /panel/login returning 404 is expected — the login endpoint only exists at /<BASE_PATH>/login (POST), and the 403 you saw there is the CSRF protection rejecting a POST without a X-CSRF-Token header obtained from /<BASE_PATH>/csrf-token first.


To help diagnose further, please share:

  1. Result of the local curl test from Step 1 (redact the token itself; just the HTTP status code is enough).
  2. Whether Cloudflare Zero Trust / Access is enabled on the tunnel.
  3. Output of x-ui → Show Panel Settings (or x-ui setting -show), specifically the base path.

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

<!-- gh-comment-id:4822244456 --> @github-actions[bot] commented on GitHub (Jun 27, 2026): The 404 you are seeing from API endpoints is intentional behavior in `internal/web/controller/api.go`: when a non-XHR request reaches `/<BASE_PATH>/panel/api/...` and Bearer token authentication fails, the server returns **404** (not 401) to avoid revealing that the endpoint exists. The 403 on `/<BASE_PATH>/login` is the CSRF middleware rejecting a POST that arrives without a prior `X-CSRF-Token` header. Both behaviors are by design and do not indicate a routing problem. **The core question is why your Bearer token is not passing auth.** Based on the code path in `ApiTokenService.Match` (`internal/web/service/panel/api_token.go:116-133`) and your Cloudflare Tunnel setup, there are three things to rule out in order. --- **Step 1 — Confirm the header reaches 3x-ui (bypass Cloudflare)** Run this directly on the server so the request goes to 3x-ui without touching Cloudflare: ```bash TOKEN="<paste your token here>" BASE="<your base path, e.g. /abc123/>" PORT=<your panel port> curl -v -H "Authorization: Bearer ${TOKEN}" \ "http://127.0.0.1:${PORT}${BASE}panel/api/server" ``` - If you get `200`: the token and URL are correct and Cloudflare is the problem (see Step 2). - If you still get `404`: the token is not being recognized — go to Step 3. --- **Step 2 — Cloudflare Access stripping the Authorization header** Cloudflare Zero Trust (Cloudflare Access) removes the `Authorization` header before forwarding requests to the origin and replaces it with a `CF-Access-Jwt-Assertion` header. If your Cloudflare Tunnel has an Access application protecting it, your Bearer token is silently dropped before 3x-ui ever sees it. Check in the Cloudflare dashboard under **Zero Trust → Access → Applications** whether there is a policy covering your panel's hostname or path. If so, you have two options: - Create a **Bypass** policy for the `/panel/api/` path to let API requests through without Access authentication. - Alternatively, call 3x-ui directly without routing through Cloudflare Access for API traffic. Even without an Access application, verify that no **HTTP header modification rules** (Transform Rules) in your Cloudflare zone strip or overwrite the `Authorization` header. --- **Step 3 — Regenerate the token** Tokens are stored as SHA-256 hashes (`internal/web/service/panel/api_token.go:78`). The plaintext is shown exactly once at creation. If there was any copy-paste issue (trailing newline, invisible character, partial copy), the hash will not match. Go to **Settings → Security**, delete the existing token, create a new one, and copy it immediately from the panel before navigating away. --- **Step 4 — Confirm the full URL** The entire panel is mounted under the randomly-generated base path (`internal/web/web.go:246`). API endpoints are at: ``` https://<host>/<BASE_PATH>/panel/api/inbounds https://<host>/<BASE_PATH>/panel/api/server ``` The paths `/login`, `/panel/login` returning 404 is expected — the login endpoint only exists at `/<BASE_PATH>/login` (POST), and the 403 you saw there is the CSRF protection rejecting a POST without a `X-CSRF-Token` header obtained from `/<BASE_PATH>/csrf-token` first. --- **To help diagnose further, please share:** 1. Result of the local `curl` test from Step 1 (redact the token itself; just the HTTP status code is enough). 2. Whether Cloudflare Zero Trust / Access is enabled on the tunnel. 3. Output of `x-ui` → **Show Panel Settings** (or `x-ui setting -show`), specifically the base path. *This reply was generated automatically; a maintainer may follow up.*
Author
Owner

@hellousersxx commented on GitHub (Jun 27, 2026):

Could you please clarify why this was closed as "not planned"?
I tested the request locally on the server, bypassing Cloudflare, and the documented API endpoint still returns 404 with a valid API token.
If this is expected behavior, could you point me to the correct API endpoint or explain what is wrong with my request?

<!-- gh-comment-id:4822491528 --> @hellousersxx commented on GitHub (Jun 27, 2026): Could you please clarify why this was closed as "not planned"? I tested the request locally on the server, bypassing Cloudflare, and the documented API endpoint still returns 404 with a valid API token. If this is expected behavior, could you point me to the correct API endpoint or explain what is wrong with my request?
Author
Owner

@Sup4ik-cmd commented on GitHub (Jun 29, 2026):

curl -X 'GET' '
'https://ip:your_port/base/panel/api/inbounds/list'
-H 'accept: application/json'
-H 'Authorization: Bearer api_token'
-k

Try this out and see if it gives you a json response

<!-- gh-comment-id:4832123349 --> @Sup4ik-cmd commented on GitHub (Jun 29, 2026): curl -X 'GET' \' \ 'https://ip:your_port/base/panel/api/inbounds/list' \ -H 'accept: application/json' \ -H 'Authorization: Bearer api_token' \ -k Try this out and see if it gives you a json response
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#3922
No description provided.