[GH-ISSUE #4915] [Bug]: 使用订阅转换时会把本地面板识别成本机网络 #3436

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

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

Describe the bug

当有多个节点 使用订阅转换https://acl4ssr-sub.github.io/ 本地节点的会被识别成订阅转换的地址 可能是127.0.0.1这个造成的

How to reproduce the problem

使用订阅转换https://acl4ssr-sub.github.io/ 转换clash的 本地节点会被识别成api.wcc.best

Expected behavior

No response

Actual behavior

No response

Relevant logs


Screenshots

No response

3x-ui version

3.2.7

Xray-core version

No response

How did you install 3x-ui?

install.sh script

Operating system

ubuntu

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?

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 @yifeng623 on GitHub (Jun 4, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/4915 ### Describe the bug 当有多个节点 使用订阅转换https://acl4ssr-sub.github.io/ 本地节点的会被识别成订阅转换的地址 可能是127.0.0.1这个造成的 ### How to reproduce the problem 使用订阅转换https://acl4ssr-sub.github.io/ 转换clash的 本地节点会被识别成api.wcc.best ### Expected behavior _No response_ ### Actual behavior _No response_ ### Relevant logs ```shell ``` ### Screenshots _No response_ ### 3x-ui version 3.2.7 ### Xray-core version _No response_ ### How did you install 3x-ui? install.sh script ### Operating system ubuntu ### 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? 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:32:25 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

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

感谢反馈!已查看相关源码,确认这是一个真实的代码级 Bug,以下是分析与临时解决方案。


根本原因

acl4ssr(通过 api.wcc.best 后端)在请求你面板订阅地址时,会在 HTTP 请求头里注入 X-Forwarded-Host: api.wcc.best,表明自己是一个代理。

3x-ui 的 ResolveRequest(sub/subService.go 第 1979 行)优先读取 X-Forwarded-Host,将其作为请求来源主机:

if h, err := getHostFromXFH(c.GetHeader("X-Forwarded-Host")); err == nil && h \!= "" {
    host = h  // 变成了 "api.wcc.best"
}

随后 PrepareForRequest(第 56 行)的逻辑如下:

if \!isRoutableHost(host) {  // api.wcc.best 是可路由的,所以不进入此分支
    if d := s.configuredPublicHost(); d \!= "" {
        host = d  // 面板里配置的订阅域名本应在此生效,但被跳过了
    }
}
s.address = host  // 结果:s.address = "api.wcc.best"

由于 api.wcc.best 是可路由的域名,代码不会读取面板"设置 → 订阅 → 订阅域名(subDomain)"里配置的值,而是直接用 api.wcc.best 作为地址。

最终在 resolveInboundAddress(第 727 行),对于监听地址为 127.0.0.1 或 0.0.0.0 的入站(这两个都不是可对外路由的地址),会回退到 s.address:

if listen := inbound.Listen; listen \!= "" && isRoutableHost(listen) {
    return listen  // 127.0.0.1 / 0.0.0.0 不满足条件,跳过
}
return s.address  // 返回 "api.wcc.best"

因此订阅链接里出现了 api.wcc.best 作为服务器地址。


当前版本(3.2.7)的临时解决方案

推荐方案:使用面板内置的 Clash 订阅,不走第三方转换器

  1. 进入面板 设置 → 订阅 页面
  2. 勾选 启用 Clash 订阅(对应配置项 subClashEnable,默认关闭)
  3. 保存后,在客户端信息页面可看到 Clash 订阅链接,格式为:http://服务器IP:端口/clash/<subid>
  4. 将此链接直接填入 Clash,无需再使用 acl4ssr 或其他第三方转换器

这样 Clash 客户端直接请求你的面板,Host 头就是你服务器的真实 IP/域名,不会出现地址被替换的问题。


代码层面的修复方向

真正的修复是:若面板中已配置 subDomain(或 webDomain),PrepareForRequest 应始终优先使用该配置值,而不仅仅是在请求来源不可路由时才使用。目前代码只在请求主机为回环/未指定地址时才读取已配置的域名,导致第三方代理注入的域名可以覆盖本应使用的服务器地址。

<!-- gh-comment-id:4623676029 --> @github-actions[bot] commented on GitHub (Jun 4, 2026): 感谢反馈!已查看相关源码,确认这是一个真实的代码级 Bug,以下是分析与临时解决方案。 --- ## 根本原因 `acl4ssr`(通过 `api.wcc.best` 后端)在请求你面板订阅地址时,会在 HTTP 请求头里注入 `X-Forwarded-Host: api.wcc.best`,表明自己是一个代理。 3x-ui 的 `ResolveRequest`(`sub/subService.go` 第 1979 行)优先读取 `X-Forwarded-Host`,将其作为请求来源主机: ```go if h, err := getHostFromXFH(c.GetHeader("X-Forwarded-Host")); err == nil && h \!= "" { host = h // 变成了 "api.wcc.best" } ``` 随后 `PrepareForRequest`(第 56 行)的逻辑如下: ```go if \!isRoutableHost(host) { // api.wcc.best 是可路由的,所以不进入此分支 if d := s.configuredPublicHost(); d \!= "" { host = d // 面板里配置的订阅域名本应在此生效,但被跳过了 } } s.address = host // 结果:s.address = "api.wcc.best" ``` 由于 `api.wcc.best` 是可路由的域名,代码**不会**读取面板"设置 → 订阅 → 订阅域名(subDomain)"里配置的值,而是直接用 `api.wcc.best` 作为地址。 最终在 `resolveInboundAddress`(第 727 行),对于监听地址为 `127.0.0.1` 或 `0.0.0.0` 的入站(这两个都不是可对外路由的地址),会回退到 `s.address`: ```go if listen := inbound.Listen; listen \!= "" && isRoutableHost(listen) { return listen // 127.0.0.1 / 0.0.0.0 不满足条件,跳过 } return s.address // 返回 "api.wcc.best" ``` 因此订阅链接里出现了 `api.wcc.best` 作为服务器地址。 --- ## 当前版本(3.2.7)的临时解决方案 **推荐方案:使用面板内置的 Clash 订阅,不走第三方转换器** 1. 进入面板 **设置 → 订阅** 页面 2. 勾选 **启用 Clash 订阅**(对应配置项 `subClashEnable`,默认关闭) 3. 保存后,在客户端信息页面可看到 Clash 订阅链接,格式为:`http://服务器IP:端口/clash/<subid>` 4. 将此链接直接填入 Clash,**无需**再使用 `acl4ssr` 或其他第三方转换器 这样 Clash 客户端直接请求你的面板,`Host` 头就是你服务器的真实 IP/域名,不会出现地址被替换的问题。 --- ## 代码层面的修复方向 真正的修复是:若面板中已配置 `subDomain`(或 `webDomain`),`PrepareForRequest` 应始终优先使用该配置值,而不仅仅是在请求来源不可路由时才使用。目前代码只在请求主机为回环/未指定地址时才读取已配置的域名,导致第三方代理注入的域名可以覆盖本应使用的服务器地址。
Author
Owner

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

english please

<!-- gh-comment-id:4626561516 --> @MHSanaei commented on GitHub (Jun 4, 2026): english please
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#3436
No description provided.