[GH-ISSUE #3864] xhttp custom headers not included in generated client links #2613

Closed
opened 2026-10-31 20:26:43 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @samush on GitHub (Feb 26, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/3864

Describe the bug

Good day,

When an xhttp inbound has custom headers configured, those headers are absent
from both the subscription link and the panel copy-link. Clients connecting
with the bare URL never send the headers, making the connection unusable in
setups that require them.

Use case

I use a custom header on the proxy server as a routing signal: requests that
carry the correct header are forwarded to xray, everything else gets a 404.
This is a lightweight defense against probing. Without the header being
present in the client link, there is no way for clients to connect
automatically — the header has to be added manually in each app.

Inbound configuration

{
  "listen": "127.0.0.1",
  "port": 10001,
  "protocol": "vless",
  "settings": {
    "clients": [
      {
        "email": "test-00",
        "flow": "",
        "id": "bb4b6af2-replaced-1a86c73c9265"
      }
    ],
    "decryption": "none",
    "encryption": "none"
  },
  "sniffing": {
    "destOverride": ["http", "tls", "quic", "fakedns"],
    "enabled": true,
    "metadataOnly": false,
    "routeOnly": false
  },
  "streamSettings": {
    "network": "xhttp",
    "security": "tls",
    "tlsSettings": {
      "alpn": ["h2", "http/1.1"],
      "certificates": [
        {
          "certificateFile": "/etc/ssl/my.crt",
          "keyFile": "/etc/ssl/my.key",
          "usage": "encipherment"
        }
      ],
      "minVersion": "1.2",
      "maxVersion": "1.3"
    },
    "xhttpSettings": {
      "path": "/ojdni8eu3n",
      "host": "",
      "mode": "auto",
      "headers": {
        "vskey": "secret-string-here"
      }
    }
  },
  "tag": "inbound-127.0.0.1:10001"
}

Expected vs actual

Generated link (actual) — extra parameter is missing:

vless://bb4b6af2-replaced-1a86c73c9265@my.domain.wtf:443?type=xhttp&encryption=none&path=%2Fojdni8eu3n&host=&mode=auto&security=tls&fp=chrome&alpn=h2%2Chttp%2F1.1#xhttp-test-00

Working link (expected) — extra encodes the headers:

vless://bb4b6af2-replaced-1a86c73c9265@my.domain.wtf:443?type=xhttp&host=&path=/ojdni8eu3n&mode=auto&extra=%257B%250A%2520%2520%2522headers%2522%2520:%2520%257B%250A%2520%2520%2520%2520%2522vskey%2522%2520:%2520%2522secret-string-here%2522%250A%2520%2520%257D%250A%257D&security=tls&sni=&alpn=h2,http/1.1&fp=chrome&allowInsecure=0#xhttp-test-00

The correct URL was obtained by importing the broken link into the HAP app and
adding the header manually there — HAP then exports it with the extra
parameter properly encoded.

HAP app with header added manually

I am not a programmer, so i used ai-tools to find the way how to fix this issue
The following was found by claude.

Root cause

In sub/subService.go,
the case "xhttp" block reads headers only to extract the Host value.
All other headers are silently discarded:

case "xhttp":
    xhttp, _ := stream["xhttpSettings"].(map[string]any)
    params["path"] = xhttp["path"].(string)
    if host, ok := xhttp["host"].(string); ok && len(host) > 0 {
        params["host"] = host
    } else {
        headers, _ := xhttp["headers"].(map[string]any)
        params["host"] = searchHost(headers)  // only Host is extracted
    }
    params["mode"] = xhttp["mode"].(string)
    // custom headers are never encoded into params["extra"]

The same omission exists in web/assets/js/model/inbound.js for the
panel's copy-link button (genVLESSLink, genSSLink, genTrojanLink).

Suggested fix

Collect non-host headers, wrap them in {"headers":{...}}, and store the
URL-encoded JSON as params["extra"]. The subsequent url.Values.Encode()
call applies a second encoding layer, which is what xray-core clients expect.

case "xhttp":
    xhttp, _ := stream["xhttpSettings"].(map[string]any)
    params["path"] = xhttp["path"].(string)
    if host, ok := xhttp["host"].(string); ok && len(host) > 0 {
        params["host"] = host
    } else {
        headers, _ := xhttp["headers"].(map[string]any)
        params["host"] = searchHost(headers)
    }
    params["mode"] = xhttp["mode"].(string)
    if headers, ok := xhttp["headers"].(map[string]any); ok && len(headers) > 0 {
        extraHeaders := make(map[string]any)
        for k, v := range headers {
            if !strings.EqualFold(k, "host") {
                extraHeaders[k] = v
            }
        }
        if len(extraHeaders) > 0 {
            if jsonBytes, err := json.Marshal(map[string]any{"headers": extraHeaders}); err == nil {
                params["extra"] = url.QueryEscape(string(jsonBytes))
            }
        }
    }

The same pattern applies to the genTrojanLink and genShadowsocksLink
functions, and to the three case "xhttp" blocks in inbound.js.

I applied this fix locally, and at least subscription service now returns client's links with extra block.

Best regards

How to repeat the problem?

  • Create inbound with xhttp transport and add some extra headers
  • then generate client's link
  • extra headers are missing

Expected action

Working link (expected) — extra encodes the headers:

vless://bb4b6af2-replaced-1a86c73c9265@my.domain.wtf:443?type=xhttp&host=&path=/ojdni8eu3n&mode=auto&extra=%257B%250A%2520%2520%2522headers%2522%2520:%2520%257B%250A%2520%2520%2520%2520%2522vskey%2522%2520:%2520%2522secret-string-here%2522%250A%2520%2520%257D%250A%257D&security=tls&sni=&alpn=h2,http/1.1&fp=chrome&allowInsecure=0#xhttp-test-00

Received action

Generated link (actual) — extra parameter is missing:

vless://bb4b6af2-replaced-1a86c73c9265@my.domain.wtf:443?type=xhttp&encryption=none&path=%2Fojdni8eu3n&host=&mode=auto&security=tls&fp=chrome&alpn=h2%2Chttp%2F1.1#xhttp-test-00

3x-ui Version

2.8.10

Xray-core Version

26.2.6

Checklist

  • This bug report is written entirely in English.
  • This bug report is new and no one has reported it before me.
Originally created by @samush on GitHub (Feb 26, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/3864 ### Describe the bug Good day, When an xhttp inbound has custom headers configured, those headers are absent from both the subscription link and the panel copy-link. Clients connecting with the bare URL never send the headers, making the connection unusable in setups that require them. ### Use case I use a custom header on the proxy server as a routing signal: requests that carry the correct header are forwarded to xray, everything else gets a 404. This is a lightweight defense against probing. Without the header being present in the client link, there is no way for clients to connect automatically — the header has to be added manually in each app. ### Inbound configuration ```json { "listen": "127.0.0.1", "port": 10001, "protocol": "vless", "settings": { "clients": [ { "email": "test-00", "flow": "", "id": "bb4b6af2-replaced-1a86c73c9265" } ], "decryption": "none", "encryption": "none" }, "sniffing": { "destOverride": ["http", "tls", "quic", "fakedns"], "enabled": true, "metadataOnly": false, "routeOnly": false }, "streamSettings": { "network": "xhttp", "security": "tls", "tlsSettings": { "alpn": ["h2", "http/1.1"], "certificates": [ { "certificateFile": "/etc/ssl/my.crt", "keyFile": "/etc/ssl/my.key", "usage": "encipherment" } ], "minVersion": "1.2", "maxVersion": "1.3" }, "xhttpSettings": { "path": "/ojdni8eu3n", "host": "", "mode": "auto", "headers": { "vskey": "secret-string-here" } } }, "tag": "inbound-127.0.0.1:10001" } ``` ### Expected vs actual **Generated link (actual)** — `extra` parameter is missing: ``` vless://bb4b6af2-replaced-1a86c73c9265@my.domain.wtf:443?type=xhttp&encryption=none&path=%2Fojdni8eu3n&host=&mode=auto&security=tls&fp=chrome&alpn=h2%2Chttp%2F1.1#xhttp-test-00 ``` **Working link (expected)** — `extra` encodes the headers: ``` vless://bb4b6af2-replaced-1a86c73c9265@my.domain.wtf:443?type=xhttp&host=&path=/ojdni8eu3n&mode=auto&extra=%257B%250A%2520%2520%2522headers%2522%2520:%2520%257B%250A%2520%2520%2520%2520%2522vskey%2522%2520:%2520%2522secret-string-here%2522%250A%2520%2520%257D%250A%257D&security=tls&sni=&alpn=h2,http/1.1&fp=chrome&allowInsecure=0#xhttp-test-00 ``` The correct URL was obtained by importing the broken link into the HAP app and adding the header manually there — HAP then exports it with the `extra` parameter properly encoded. <img width="1170" height="770" alt="HAP app with header added manually" src="https://github.com/user-attachments/assets/de29655e-0723-4308-bc8c-c5629df69f06" /> I am not a programmer, so i used ai-tools to find the way how to fix this issue The following was found by claude. ### Root cause In [`sub/subService.go`](https://github.com/MHSanaei/3x-ui/blob/159b85f9794576a283f981778445836dc8819a5e/sub/subService.go#L399-L409), the `case "xhttp"` block reads `headers` only to extract the `Host` value. All other headers are silently discarded: ```go case "xhttp": xhttp, _ := stream["xhttpSettings"].(map[string]any) params["path"] = xhttp["path"].(string) if host, ok := xhttp["host"].(string); ok && len(host) > 0 { params["host"] = host } else { headers, _ := xhttp["headers"].(map[string]any) params["host"] = searchHost(headers) // only Host is extracted } params["mode"] = xhttp["mode"].(string) // custom headers are never encoded into params["extra"] ``` The same omission exists in `web/assets/js/model/inbound.js` for the panel's copy-link button (`genVLESSLink`, `genSSLink`, `genTrojanLink`). ### Suggested fix Collect non-host headers, wrap them in `{"headers":{...}}`, and store the URL-encoded JSON as `params["extra"]`. The subsequent `url.Values.Encode()` call applies a second encoding layer, which is what xray-core clients expect. ```go case "xhttp": xhttp, _ := stream["xhttpSettings"].(map[string]any) params["path"] = xhttp["path"].(string) if host, ok := xhttp["host"].(string); ok && len(host) > 0 { params["host"] = host } else { headers, _ := xhttp["headers"].(map[string]any) params["host"] = searchHost(headers) } params["mode"] = xhttp["mode"].(string) if headers, ok := xhttp["headers"].(map[string]any); ok && len(headers) > 0 { extraHeaders := make(map[string]any) for k, v := range headers { if !strings.EqualFold(k, "host") { extraHeaders[k] = v } } if len(extraHeaders) > 0 { if jsonBytes, err := json.Marshal(map[string]any{"headers": extraHeaders}); err == nil { params["extra"] = url.QueryEscape(string(jsonBytes)) } } } ``` The same pattern applies to the `genTrojanLink` and `genShadowsocksLink` functions, and to the three `case "xhttp"` blocks in `inbound.js`. I applied this fix locally, and at least subscription service now returns client's links with extra block. Best regards ### How to repeat the problem? - Create inbound with xhttp transport and add some extra headers - then generate client's link - extra headers are missing ### Expected action **Working link (expected)** — `extra` encodes the headers: ``` vless://bb4b6af2-replaced-1a86c73c9265@my.domain.wtf:443?type=xhttp&host=&path=/ojdni8eu3n&mode=auto&extra=%257B%250A%2520%2520%2522headers%2522%2520:%2520%257B%250A%2520%2520%2520%2520%2522vskey%2522%2520:%2520%2522secret-string-here%2522%250A%2520%2520%257D%250A%257D&security=tls&sni=&alpn=h2,http/1.1&fp=chrome&allowInsecure=0#xhttp-test-00 ``` ### Received action **Generated link (actual)** — `extra` parameter is missing: ``` vless://bb4b6af2-replaced-1a86c73c9265@my.domain.wtf:443?type=xhttp&encryption=none&path=%2Fojdni8eu3n&host=&mode=auto&security=tls&fp=chrome&alpn=h2%2Chttp%2F1.1#xhttp-test-00 ``` ### 3x-ui Version 2.8.10 ### Xray-core Version 26.2.6 ### Checklist - [x] This bug report is written entirely in English. - [x] This bug report is new and no one has reported it before me.
bsakaguchi 2026-10-31 20:26:43 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@Arjentix commented on GitHub (May 28, 2026):

Note that sni is also missing in generated url, this caused bugs for me

<!-- gh-comment-id:4564448664 --> @Arjentix commented on GitHub (May 28, 2026): Note that `sni` is also missing in generated url, this caused bugs for me
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#2613
No description provided.