[GH-ISSUE #6324] [Bug]: "Request failed with status code 403" when logging in to the panel #4294

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

Originally created by @Rockst4r4 on GitHub (Aug 25, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6324

Describe the bug

Request failed with status code 403
Im reciving this error when im tring to login to console

How to reproduce the problem

Request failed with status code 403

Expected behavior

No response

Actual behavior

No response

Relevant logs


Screenshots

No response

3x-ui version

3.7.0

Xray-core version

No response

How did you install 3x-ui?

install.sh script

Operating system

ubuntu 24

Which parts of the panel are affected?

No response

Browser (only if it is a UI bug)

No response

Is the panel behind a reverse proxy or CDN?

No response

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 @Rockst4r4 on GitHub (Aug 25, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6324 ### Describe the bug Request failed with status code 403 Im reciving this error when im tring to login to console ### How to reproduce the problem Request failed with status code 403 ### Expected behavior _No response_ ### Actual behavior _No response_ ### Relevant logs ```shell ``` ### Screenshots _No response_ ### 3x-ui version 3.7.0 ### Xray-core version _No response_ ### How did you install 3x-ui? install.sh script ### Operating system ubuntu 24 ### Which parts of the panel are affected? _No response_ ### Browser (only if it is a UI bug) _No response_ ### Is the panel behind a reverse proxy or CDN? _No response_ ### 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:38:37 +07:00
Author
Owner

@github-actions[bot] commented on GitHub (Aug 25, 2026):

I could not evaluate this report as filed — a 403 on login has three distinct sources in v3.7.0 and the issue contains nothing that tells them apart. But one detail in your report is a concrete lead, so please read the first section before answering the questions at the bottom.

The error string you quoted cannot come from a v3.7.0 panel

The exact wording matters here. v3.7.0's UI builds its error message as:

// frontend/src/api/http-init.ts:21
super(`Request failed with status ${status}`);

That is Request failed with status 403 — no code. The wording you quoted, Request failed with status code 403, is axios's message format, and axios was removed from this project in commit bc309ed9 ("refactor(frontend): replace axios with the native Fetch API"), which first shipped in v3.5.0. The last release that bundled axios is v3.4.2 (frontend/package.json:30: "axios": "^1.18.1"), and a repo-wide search finds no axios anywhere on the current default branch.

So either the panel actually running is v3.4.2 or older, or the message is coming from a different client (a third-party manager app, a script) rather than the panel's own login page. Please confirm with:

x-ui -v

What actually returns 403 on the login path in v3.7.0

Worth stating up front: a wrong username or password never produces a 403. Both the credential check and the brute-force limiter answer with HTTP 200 and a JSON error body (internal/web/controller/index.go:91 and :111). A 403 means the request was rejected before your credentials were ever looked at. Only three things can do that:

  1. The CSRF check on POST /<basePath>/login (internal/web/controller/index.go:46 wires middleware.CSRFMiddleware() onto the route). It aborts with a bare, empty-bodied 403:

    // internal/web/middleware/security.go:51-54
    if !session.ValidateCSRFToken(c) {
        c.AbortWithStatus(http.StatusForbidden)
        return
    }
    

    ValidateCSRFToken (internal/web/session/csrf.go:33-47) compares the X-CSRF-Token header against the token stored in your browser's session cookie. The login page ships that token as a <meta name="csrf-token"> tag minted server-side (internal/web/controller/dist.go:123-128), and the UI even retries once with a freshly fetched token when it sees a 403 (frontend/src/api/http-init.ts:177-184). For this to still fail, the 3x-ui session cookie has to not be coming back on the POST at all.

  2. The "Listen Domain" setting. If Settings → Panel Settings → Listen Domain (webDomain) is non-empty, this middleware runs on every panel route (internal/web/web.go:183-185) and rejects anything whose Host header is not an exact, case-sensitive match:

    // internal/web/middleware/domainValidator.go:24-27
    if host != domain {
        c.AbortWithStatus(http.StatusForbidden)
        return
    }
    
  3. Something in front of the panel — Cloudflare (WAF, Bot Fight Mode, a Cache Rule), a Cloudflare Tunnel, or an nginx deny rule — returning its own 403 before the request ever reaches the Go process. You left the reverse-proxy/CDN section of the form blank, so I cannot rule this out.

Two things worth trying before you answer, since they are free: open the panel in a private/incognito window, and if that works, clear cookies for the panel's origin in your normal profile. A stale or undecodable 3x-ui cookie leaves the session empty, which lands you in case 1. (This is the shape #5931 took — that reporter's log showed securecookie: error ... gob: name not registered for interface: "github.com/mhsanaei/3x-ui/v2/database/model.User", a leftover v2 cookie. I have not confirmed that mechanism in the source, so treat it as a hypothesis, not a diagnosis.)

What I need to take this further

  1. The output of x-ui -v on the server — the quoted error string is only produced by v3.4.2 and older, so this decides whether we are even looking at v3.7.0 code.
  2. Is the panel behind a reverse proxy, Cloudflare, or a Cloudflare Tunnel? (The form section was left blank, and case 3 above is indistinguishable from case 1 without it.)
  3. From the browser's DevTools → Network tab, reproduced live: which request returns 403 — the page load, GET /<basePath>/csrf-token, or POST /<basePath>/login? Is the response body empty, or an HTML block page? Does it carry a cf-ray or server: cloudflare header? Please paste the headers as text — I cannot open screenshots.
  4. Is Listen Domain set under Settings → Panel Settings? If yes, does it match the hostname in your address bar character for character (no https://, no trailing /, same case)?
  5. The panel log around the failed attempt: journalctl -u x-ui -e --no-pager -n 200. Every request that reaches the login handler logs a line, success or failure (internal/web/controller/index.go:100, :102, :116, :129) — so silence there is itself the answer: it proves the request was blocked earlier. Also grep it for securecookie.

I retitled the issue for searchability — it was [Bug]: with an empty summary. It still states your problem, not a conclusion.

Verdict: Insufficient information
Severity: N/A — cannot be rated until the 403's origin is known
Confidence: High (that the report as filed cannot be evaluated; the 403 source mapping below is confirmed at the cited lines)
Root cause: Not established. Three mutually exclusive candidates, all confirmed present in v3.7.0: (a) CSRFMiddleware at internal/web/middleware/security.go:51-54, applied to POST /login at internal/web/controller/index.go:46, triggered when the 3x-ui session cookie carries no CSRF token; (b) DomainValidatorMiddleware at internal/web/middleware/domainValidator.go:24-27, triggered on any Host mismatch when webDomain is set (internal/web/web.go:183-185); (c) an upstream proxy/CDN 403 that never reaches the Go process. Credentials are excluded — a bad login is HTTP 200 (internal/web/controller/index.go:91, :111).
Already fixed: Not applicable — no defect identified yet. All three 403 paths above are present on the default branch (f727d04f, v3.7.0).
Duplicate of: Related: #5931 (same symptom, closed as not-planned for lack of information; root cause never confirmed). Related: #4547 (persistent 403 that private-browsing mode cleared; also never root-caused).
Evidence: frontend/src/api/http-init.ts:21 — super(`Request failed with status ${status}`): v3.5.0+ emits no "code" in that string; repo-wide grep for Request failed with status matches only this line and its test. frontend/package.json at tag v3.4.2, line 30 — "axios": "^1.18.1"; removed by bc309ed9, whose earliest containing tag is v3.5.0 (git tag --contains bc309ed9 → dev-latest, v3.5.0, v3.6.0, v3.7.0). internal/web/controller/index.go:46 — g.POST("/login", middleware.CSRFMiddleware(), a.login). internal/web/middleware/security.go:51-54 and internal/web/session/csrf.go:33-47 — the CSRF 403. internal/web/middleware/domainValidator.go:24-27 and internal/web/web.go:183-185 — the Listen Domain 403. internal/web/controller/dist.go:123-128 — the server-minted <meta name="csrf-token"> on login.html. frontend/src/api/http-init.ts:177-184 — the single 403-retry with a refreshed token. internal/web/translation/en-US.json:1206 — "panelListeningDomain": "Listen Domain".
Not determined: Which of the three 403 sources applies, and whether the running panel is really v3.7.0. The single check that settles the first: the DevTools Network entry for the failing request (item 3) — a cf-ray/server: cloudflare header points at the CDN, an empty-bodied 403 on POST /<basePath>/login points at CSRF, and a 403 on the page load itself points at Listen Domain. x-ui -v (item 1) settles the second.

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

<!-- gh-comment-id:5412223179 --> @github-actions[bot] commented on GitHub (Aug 25, 2026): I could not evaluate this report as filed — a `403` on login has three distinct sources in v3.7.0 and the issue contains nothing that tells them apart. But one detail in your report is a concrete lead, so please read the first section before answering the questions at the bottom. ## The error string you quoted cannot come from a v3.7.0 panel The exact wording matters here. v3.7.0's UI builds its error message as: ```ts // frontend/src/api/http-init.ts:21 super(`Request failed with status ${status}`); ``` That is `Request failed with status 403` — no `code`. The wording you quoted, `Request failed with status code 403`, is **axios**'s message format, and axios was removed from this project in commit `bc309ed9` ("refactor(frontend): replace axios with the native Fetch API"), which first shipped in **v3.5.0**. The last release that bundled axios is v3.4.2 (`frontend/package.json:30`: `"axios": "^1.18.1"`), and a repo-wide search finds no axios anywhere on the current default branch. So either the panel actually running is **v3.4.2 or older**, or the message is coming from a different client (a third-party manager app, a script) rather than the panel's own login page. Please confirm with: ```bash x-ui -v ``` ## What actually returns 403 on the login path in v3.7.0 Worth stating up front: **a wrong username or password never produces a 403.** Both the credential check and the brute-force limiter answer with HTTP 200 and a JSON error body (`internal/web/controller/index.go:91` and `:111`). A 403 means the request was rejected *before* your credentials were ever looked at. Only three things can do that: 1. **The CSRF check** on `POST /<basePath>/login` (`internal/web/controller/index.go:46` wires `middleware.CSRFMiddleware()` onto the route). It aborts with a bare, empty-bodied 403: ```go // internal/web/middleware/security.go:51-54 if !session.ValidateCSRFToken(c) { c.AbortWithStatus(http.StatusForbidden) return } ``` `ValidateCSRFToken` (`internal/web/session/csrf.go:33-47`) compares the `X-CSRF-Token` header against the token stored in *your browser's session cookie*. The login page ships that token as a `<meta name="csrf-token">` tag minted server-side (`internal/web/controller/dist.go:123-128`), and the UI even retries once with a freshly fetched token when it sees a 403 (`frontend/src/api/http-init.ts:177-184`). For this to still fail, the `3x-ui` session cookie has to not be coming back on the POST at all. 2. **The "Listen Domain" setting.** If Settings → Panel Settings → **Listen Domain** (`webDomain`) is non-empty, this middleware runs on *every* panel route (`internal/web/web.go:183-185`) and rejects anything whose `Host` header is not an exact, case-sensitive match: ```go // internal/web/middleware/domainValidator.go:24-27 if host != domain { c.AbortWithStatus(http.StatusForbidden) return } ``` 3. **Something in front of the panel** — Cloudflare (WAF, Bot Fight Mode, a Cache Rule), a Cloudflare Tunnel, or an nginx `deny` rule — returning its own 403 before the request ever reaches the Go process. You left the reverse-proxy/CDN section of the form blank, so I cannot rule this out. Two things worth trying before you answer, since they are free: open the panel in a **private/incognito window**, and if that works, clear cookies for the panel's origin in your normal profile. A stale or undecodable `3x-ui` cookie leaves the session empty, which lands you in case 1. (This is the shape #5931 took — that reporter's log showed `securecookie: error ... gob: name not registered for interface: "github.com/mhsanaei/3x-ui/v2/database/model.User"`, a leftover v2 cookie. I have not confirmed that mechanism in the source, so treat it as a hypothesis, not a diagnosis.) ## What I need to take this further 1. The output of `x-ui -v` on the server — the quoted error string is only produced by v3.4.2 and older, so this decides whether we are even looking at v3.7.0 code. 2. Is the panel behind a reverse proxy, Cloudflare, or a Cloudflare Tunnel? (The form section was left blank, and case 3 above is indistinguishable from case 1 without it.) 3. From the browser's DevTools → Network tab, reproduced live: **which** request returns 403 — the page load, `GET /<basePath>/csrf-token`, or `POST /<basePath>/login`? Is the response body empty, or an HTML block page? Does it carry a `cf-ray` or `server: cloudflare` header? Please paste the headers as text — I cannot open screenshots. 4. Is **Listen Domain** set under Settings → Panel Settings? If yes, does it match the hostname in your address bar character for character (no `https://`, no trailing `/`, same case)? 5. The panel log around the failed attempt: `journalctl -u x-ui -e --no-pager -n 200`. Every request that reaches the login handler logs a line, success or failure (`internal/web/controller/index.go:100`, `:102`, `:116`, `:129`) — so silence there is itself the answer: it proves the request was blocked earlier. Also grep it for `securecookie`. I retitled the issue for searchability — it was `[Bug]:` with an empty summary. It still states your problem, not a conclusion. Verdict: Insufficient information Severity: N/A — cannot be rated until the 403's origin is known Confidence: High (that the report as filed cannot be evaluated; the 403 source mapping below is confirmed at the cited lines) Root cause: Not established. Three mutually exclusive candidates, all confirmed present in v3.7.0: (a) `CSRFMiddleware` at `internal/web/middleware/security.go:51-54`, applied to `POST /login` at `internal/web/controller/index.go:46`, triggered when the `3x-ui` session cookie carries no CSRF token; (b) `DomainValidatorMiddleware` at `internal/web/middleware/domainValidator.go:24-27`, triggered on any `Host` mismatch when `webDomain` is set (`internal/web/web.go:183-185`); (c) an upstream proxy/CDN 403 that never reaches the Go process. Credentials are excluded — a bad login is HTTP 200 (`internal/web/controller/index.go:91`, `:111`). Already fixed: Not applicable — no defect identified yet. All three 403 paths above are present on the default branch (f727d04f, v3.7.0). Duplicate of: Related: #5931 (same symptom, closed as not-planned for lack of information; root cause never confirmed). Related: #4547 (persistent 403 that private-browsing mode cleared; also never root-caused). Evidence: `frontend/src/api/http-init.ts:21` — ``super(`Request failed with status ${status}`)``: v3.5.0+ emits no "code" in that string; repo-wide grep for `Request failed with status` matches only this line and its test. `frontend/package.json` at tag v3.4.2, line 30 — `"axios": "^1.18.1"`; removed by `bc309ed9`, whose earliest containing tag is v3.5.0 (`git tag --contains bc309ed9` → dev-latest, v3.5.0, v3.6.0, v3.7.0). `internal/web/controller/index.go:46` — `g.POST("/login", middleware.CSRFMiddleware(), a.login)`. `internal/web/middleware/security.go:51-54` and `internal/web/session/csrf.go:33-47` — the CSRF 403. `internal/web/middleware/domainValidator.go:24-27` and `internal/web/web.go:183-185` — the Listen Domain 403. `internal/web/controller/dist.go:123-128` — the server-minted `<meta name="csrf-token">` on `login.html`. `frontend/src/api/http-init.ts:177-184` — the single 403-retry with a refreshed token. `internal/web/translation/en-US.json:1206` — `"panelListeningDomain": "Listen Domain"`. Not determined: Which of the three 403 sources applies, and whether the running panel is really v3.7.0. The single check that settles the first: the DevTools Network entry for the failing request (item 3) — a `cf-ray`/`server: cloudflare` header points at the CDN, an empty-bodied 403 on `POST /<basePath>/login` points at CSRF, and a 403 on the page load itself points at Listen Domain. `x-ui -v` (item 1) settles the second. *This reply was generated automatically; a maintainer may follow up.* <!-- claude-issue:analyst -->
Author
Owner

@Mw-HbCK commented on GitHub (Sep 7, 2026):

I had the same 403 Forbidden issue when trying to log in through the API with Python requests.

After checking the browser login flow, I found that sending a POST request directly to /login was not enough.

The working flow for me was:

  1. First send a GET request to the panel login page (/<base-path>/).
  2. Keep the returned 3x-ui session cookie using requests.Session().
  3. Extract the CSRF token from the HTML:
<meta name="csrf-token" content="...">
  1. Send the login request as application/x-www-form-urlencoded instead of JSON.
  2. Include the CSRF token in the request header:
X-CSRF-Token: <csrf-token>

Example:

session = requests.Session()

# Get login page and session cookie
response = session.get(f"{api_base_url}/", verify=False)

# Extract CSRF token
csrf_token = re.search(
    r'<meta\s+name=["\']csrf-token["\']\s+content=["\']([^"\']+)["\']',
    response.text
).group(1)

# Login
response = session.post(
    f"{api_base_url}/login",
    data={
        "username": username,
        "password": password,
        "twoFactorCode": ""
    },
    headers={
        "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
        "X-CSRF-Token": csrf_token,
        "X-Requested-With": "XMLHttpRequest"
    },
    verify=False
)

print(response.status_code)
print(response.text)

After adding the CSRF token and using the same session, the login succeeded with HTTP 200:

{
    "success": true
}

So if you are getting 403, try fetching the login page first and include the CSRF token in the login request.

<!-- gh-comment-id:5572668018 --> @Mw-HbCK commented on GitHub (Sep 7, 2026): I had the same `403 Forbidden` issue when trying to log in through the API with Python `requests`. After checking the browser login flow, I found that sending a POST request directly to `/login` was not enough. The working flow for me was: 1. First send a `GET` request to the panel login page (`/<base-path>/`). 2. Keep the returned `3x-ui` session cookie using `requests.Session()`. 3. Extract the CSRF token from the HTML: ```html <meta name="csrf-token" content="..."> ``` 4. Send the login request as `application/x-www-form-urlencoded` instead of JSON. 5. Include the CSRF token in the request header: ```text X-CSRF-Token: <csrf-token> ``` Example: ```python session = requests.Session() # Get login page and session cookie response = session.get(f"{api_base_url}/", verify=False) # Extract CSRF token csrf_token = re.search( r'<meta\s+name=["\']csrf-token["\']\s+content=["\']([^"\']+)["\']', response.text ).group(1) # Login response = session.post( f"{api_base_url}/login", data={ "username": username, "password": password, "twoFactorCode": "" }, headers={ "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", "X-CSRF-Token": csrf_token, "X-Requested-With": "XMLHttpRequest" }, verify=False ) print(response.status_code) print(response.text) ``` After adding the CSRF token and using the same session, the login succeeded with HTTP 200: ```json { "success": true } ``` So if you are getting `403`, try fetching the login page first and include the CSRF token in the login request.
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#4294
No description provided.