[GH-ISSUE #7067] DomainValidatorMiddleware rejects a Host mismatch with an empty 403 — make it diagnosable #6605

Open
opened 2026-11-07 14:33:28 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @OlegEnot on GitHub (Nov 4, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/7067

Problem

When webDomain is set, any request whose Host differs gets 403 with Content-Length: 0
(internal/web/middleware/domainValidator.go):

host := c.Request.Host
if colonIndex := strings.LastIndex(host, ":"); colonIndex != -1 {
    host, _, _ = net.SplitHostPort(c.Request.Host)
}
if host != domain {
    c.AbortWithStatus(http.StatusForbidden)
    return
}

Nothing in the response or in the panel log says why. Clients (metrics exporters, API scripts) and
admins debugging container-to-container access see a blank 403 with valid credentials, which looks
like an authentication or API-version problem rather than a Host mismatch.

Concrete case: a metrics exporter running in Docker reaches the panel as http://3x-ui:3053/<base-path>
(service name on a shared bridge network). With webDomain = panel.example.com every request is
rejected with an empty 403, while the same account works fine in a browser via the domain.

Suggestion

  1. Log a rate-limited warning (same style as the existing CSRF / login warnings), e.g.
    domain validation failed: host=%q expected=%q ip=%s.
  2. Return a small body for JSON/API paths:
    {"success":false,"msg":"host not allowed: configured web domain is \"panel.example.com\""}.
    Browser/SPA routes can keep the empty 403 if returning a body there is undesirable.

This turns a silent 403 into a one-line explanation in both the panel log and the client error.

Originally created by @OlegEnot on GitHub (Nov 4, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/7067 ## Problem When `webDomain` is set, any request whose `Host` differs gets `403` with `Content-Length: 0` (`internal/web/middleware/domainValidator.go`): ```go host := c.Request.Host if colonIndex := strings.LastIndex(host, ":"); colonIndex != -1 { host, _, _ = net.SplitHostPort(c.Request.Host) } if host != domain { c.AbortWithStatus(http.StatusForbidden) return } ``` Nothing in the response or in the panel log says why. Clients (metrics exporters, API scripts) and admins debugging container-to-container access see a blank 403 with valid credentials, which looks like an authentication or API-version problem rather than a Host mismatch. Concrete case: a metrics exporter running in Docker reaches the panel as `http://3x-ui:3053/<base-path>` (service name on a shared bridge network). With `webDomain = panel.example.com` every request is rejected with an empty 403, while the same account works fine in a browser via the domain. ## Suggestion 1. Log a rate-limited warning (same style as the existing CSRF / login warnings), e.g. `domain validation failed: host=%q expected=%q ip=%s`. 2. Return a small body for JSON/API paths: `{"success":false,"msg":"host not allowed: configured web domain is \"panel.example.com\""}`. Browser/SPA routes can keep the empty 403 if returning a body there is undesirable. This turns a silent 403 into a one-line explanation in both the panel log and the client error.
Author
Owner

@OlegEnot commented on GitHub (Nov 4, 2026):

Context for this report: it was found while debugging a metrics exporter (hteppl/3x-ui-exporter#18) that reported the empty 403 as an API-version mismatch.

<!-- gh-comment-id:6636250480 --> @OlegEnot commented on GitHub (Nov 4, 2026): Context for this report: it was found while debugging a metrics exporter (hteppl/3x-ui-exporter#18) that reported the empty 403 as an API-version mismatch.
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#6605
No description provided.