[GH-ISSUE #5514] [Bug]: xhttp over Unix socket breaks trustedXForwardedFor JSON typing in UI #3847

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

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

Describe the bug

When configuring an inbound (such as xhttp) that listens on a Unix Domain Socket (UDS), attempting to configure trustedXForwardedFor under the "Sockopt" section triggers a UI bug.

Instead of treating the input as a standard IP/CIDR array for Xray's sockopt block, the UI automatically forces the "Real Client IP" setting to switch to "Cloudflare CDN" mode and displays unrelated HTTP header dropdowns. As a result, the array is not correctly saved into the JSON config, and Xray-core throws constant warnings that sockopt.trustedXForwardedFor is not configured.

How to reproduce the problem

  1. Edit an inbound utilizing the xhttp network protocol.
  2. Set the "Listen" field to a Unix Domain Socket path (e.g., /dev/shm/uds2023.sock,0666).
  3. Toggle the "Sockopt" switch to ON.
  4. Attempt to add a CIDR or IP (like 0.0.0.0/0 or 127.0.0.1) into the Trusted X-Forwarded-For field.
  5. Observe the UI layout glitching, shifting logic to "Cloudflare CDN" and offering header variables instead of plain array inputs.

Expected behavior

The UI should allow administrators to input raw IP/CIDR arrays into trustedXForwardedFor for Unix socket inbounds without triggering CDN/Cloudflare frontend components, ensuring the parameters are successfully written to Xray's sockopt config block.

Actual behavior

The panel misinterprets the setup as a CDN integration, failing to generate a valid configuration for Xray-core. This causes the binary to ignore the header and flood the system logs with unconfigured sockopt warnings.

Relevant logs

Xray-core runtime logs showing the missing parameter warning due to UI stripping:

WARNING - XRAY: common/protocol/http: received "X-Forwarded-For" from 0.0.0.0:0 but "sockopt.trustedXForwardedFor" is not configured; ignoring it and using the real remote address

Screenshots

No response

3x-ui version

3.4.0

Xray-core version

26.6.22

How did you install 3x-ui?

install.sh script

Operating system

Ubuntu 24.04

Which parts of the panel are affected?

Backend (API endpoints, login, settings)

Browser (only if it is a UI bug)

Chrome 148

Is the panel behind a reverse proxy or CDN?

Yes — Nginx

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 @anartikov on GitHub (Jun 23, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5514 ### Describe the bug When configuring an inbound (such as `xhttp`) that listens on a Unix Domain Socket (UDS), attempting to configure `trustedXForwardedFor` under the "Sockopt" section triggers a UI bug. Instead of treating the input as a standard IP/CIDR array for Xray's sockopt block, the UI automatically forces the "Real Client IP" setting to switch to "Cloudflare CDN" mode and displays unrelated HTTP header dropdowns. As a result, the array is not correctly saved into the JSON config, and Xray-core throws constant warnings that `sockopt.trustedXForwardedFor` is not configured. ### How to reproduce the problem 1. Edit an inbound utilizing the `xhttp` network protocol. 2. Set the "Listen" field to a Unix Domain Socket path (e.g., `/dev/shm/uds2023.sock,0666`). 3. Toggle the "Sockopt" switch to ON. 4. Attempt to add a CIDR or IP (like `0.0.0.0/0` or `127.0.0.1`) into the `Trusted X-Forwarded-For` field. 5. Observe the UI layout glitching, shifting logic to "Cloudflare CDN" and offering header variables instead of plain array inputs. ### Expected behavior The UI should allow administrators to input raw IP/CIDR arrays into `trustedXForwardedFor` for Unix socket inbounds without triggering CDN/Cloudflare frontend components, ensuring the parameters are successfully written to Xray's sockopt config block. ### Actual behavior The panel misinterprets the setup as a CDN integration, failing to generate a valid configuration for Xray-core. This causes the binary to ignore the header and flood the system logs with unconfigured sockopt warnings. ### Relevant logs ```shell Xray-core runtime logs showing the missing parameter warning due to UI stripping: WARNING - XRAY: common/protocol/http: received "X-Forwarded-For" from 0.0.0.0:0 but "sockopt.trustedXForwardedFor" is not configured; ignoring it and using the real remote address ``` ### Screenshots _No response_ ### 3x-ui version 3.4.0 ### Xray-core version 26.6.22 ### How did you install 3x-ui? install.sh script ### Operating system Ubuntu 24.04 ### Which parts of the panel are affected? Backend (API endpoints, login, settings) ### Browser (only if it is a UI bug) Chrome 148 ### Is the panel behind a reverse proxy or CDN? Yes — Nginx ### 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:23 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

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

Both issues were traced against the v3.4.0 source. Here is what the code confirms and what remains uncertain.


Bug 1 — trustedXForwardedFor display and the Cloudflare preset

Two distinct problems are conflated here.

UI labelling confusion (confirmed)

In frontend/src/pages/inbounds/form/transport/sockopt.tsx:127-131, the "Real Client IP" segmented control derives its displayed preset solely from whether trustedXForwardedFor is non-empty:

const value: RealClientIpPreset = proxyOn
  ? 'proxy'
  : trusted.length > 0
    ? 'cloudflare'   // any non-empty array → "Cloudflare CDN"
    : 'off';

This means the moment you type any CIDR into the tags field below, the control jumps to "Cloudflare CDN" — not because it replaced your entry, but because the three-state preset has no fourth "custom IPs" state. The CIDR you typed is still held in the form and will be emitted correctly on save.

Cloudflare preset injects a header name, not a CIDR (confirmed bug)

The applyRealClientIpPreset('cloudflare') function (same file, lines 54-58) appends the string "CF-Connecting-IP" to trustedXForwardedFor:

if (\!list.includes('CF-Connecting-IP')) list.push('CF-Connecting-IP');

The golden test fixture at frontend/src/test/golden/fixtures/sockopt/full.json shows the expected wire format for this field is IP CIDRs:

"trustedXForwardedFor": ["10.0.0.0/8", "192.168.0.0/16"]

The xray-core warning you received — received "X-Forwarded-For" from 0.0.0.0:0 but "sockopt.trustedXForwardedFor" is not configured — is an IP-based check: xray-core compares the connecting address against the list of trusted CIDRs and only trusts the X-Forwarded-For header when there is a match. The string "CF-Connecting-IP" is not a valid CIDR, so xray-core silently treats the list as if it were absent.

If you activated the "Cloudflare CDN" preset at any point (rather than typing CIDRs directly), that is what produced "CF-Connecting-IP" in your saved config and is the immediate cause of the runtime warning. The fix would be to populate trustedXForwardedFor with actual IP CIDRs instead (e.g. Cloudflare's published proxy ranges, or 0.0.0.0/0/::/0 to trust all upstream addresses).

UDS and 0.0.0.0:0 (uncertain — xray-core scope)

When listening on a Unix Domain Socket, xray-core reports the connecting address as 0.0.0.0:0. Whether xray-core 26.6.22 matches that pseudo-address against a configured CIDR of 0.0.0.0/0 cannot be determined from the panel source alone. If it does not — meaning IP-based trust is simply inapplicable to UDS connections regardless of what CIDRs are configured — this would be a limitation in xray-core that the panel cannot work around on its own.


Bug 2 — sessionIDLength emitted as a JSON string

This behaviour is intentional in the current code, but may conflict with xray-core 26.6.22.

frontend/src/schemas/protocols/stream/xhttp.ts:71 declares:

sessionIDLength: z.string().default(''),

frontend/src/lib/xray/stream-wire-normalize.ts:22 lists 'sessionIDLength' in PLACEMENT_STRING_FIELDS, which are stripped only when empty. A non-empty value such as "20" is emitted verbatim as the JSON string "sessionIDLength": "20". This design is deliberate because the field also accepts dash-range values like "8-16".

The panel tooltip (en-US.json:540) confirms the intention: "Length or range (e.g. 8-16) of generated session IDs."

If xray-core 26.6.22 changed sessionIDLength from a type that accepts a string-encoded integer ("20") to a plain JSON integer (20), the panel's string output would fail to unmarshal and xray-core would fall back. Whether that change occurred in xray-core 26.6.22 is not verifiable from the panel source. To confirm, inspect the raw Xray JSON config actually written to disk (accessible via the panel's xray config view or directly at /etc/x-ui/x-ui.db) and compare the sessionIDLength field type against what xray-core's Go struct expects in 26.6.22.


To help narrow down the root cause of both issues, it would be useful to share:

  1. The raw streamSettings JSON stored for the affected inbound (copy it from the panel's "Edit → Stream" advanced JSON view).
  2. Whether the xray-core "not configured" warning appears even when trustedXForwardedFor contains only valid CIDRs (e.g. 0.0.0.0/0) and the "Cloudflare CDN" preset was never applied.
  3. Whether sessionIDLength behaves differently with a range value like "8-16" versus a plain integer string like "20".

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

<!-- gh-comment-id:4782434778 --> @github-actions[bot] commented on GitHub (Jun 23, 2026): Both issues were traced against the v3.4.0 source. Here is what the code confirms and what remains uncertain. --- **Bug 1 — `trustedXForwardedFor` display and the Cloudflare preset** Two distinct problems are conflated here. *UI labelling confusion (confirmed)* In `frontend/src/pages/inbounds/form/transport/sockopt.tsx:127-131`, the "Real Client IP" segmented control derives its displayed preset solely from whether `trustedXForwardedFor` is non-empty: ```ts const value: RealClientIpPreset = proxyOn ? 'proxy' : trusted.length > 0 ? 'cloudflare' // any non-empty array → "Cloudflare CDN" : 'off'; ``` This means the moment you type any CIDR into the tags field below, the control jumps to "Cloudflare CDN" — not because it replaced your entry, but because the three-state preset has no fourth "custom IPs" state. The CIDR you typed is still held in the form and will be emitted correctly on save. *Cloudflare preset injects a header name, not a CIDR (confirmed bug)* The `applyRealClientIpPreset('cloudflare')` function (same file, lines 54-58) appends the string `"CF-Connecting-IP"` to `trustedXForwardedFor`: ```ts if (\!list.includes('CF-Connecting-IP')) list.push('CF-Connecting-IP'); ``` The golden test fixture at `frontend/src/test/golden/fixtures/sockopt/full.json` shows the expected wire format for this field is IP CIDRs: ```json "trustedXForwardedFor": ["10.0.0.0/8", "192.168.0.0/16"] ``` The xray-core warning you received — `received "X-Forwarded-For" from 0.0.0.0:0 but "sockopt.trustedXForwardedFor" is not configured` — is an IP-based check: xray-core compares the connecting address against the list of trusted CIDRs and only trusts the `X-Forwarded-For` header when there is a match. The string `"CF-Connecting-IP"` is not a valid CIDR, so xray-core silently treats the list as if it were absent. If you activated the "Cloudflare CDN" preset at any point (rather than typing CIDRs directly), that is what produced `"CF-Connecting-IP"` in your saved config and is the immediate cause of the runtime warning. The fix would be to populate `trustedXForwardedFor` with actual IP CIDRs instead (e.g. Cloudflare's published proxy ranges, or `0.0.0.0/0`/`::/0` to trust all upstream addresses). *UDS and `0.0.0.0:0` (uncertain — xray-core scope)* When listening on a Unix Domain Socket, xray-core reports the connecting address as `0.0.0.0:0`. Whether xray-core 26.6.22 matches that pseudo-address against a configured CIDR of `0.0.0.0/0` cannot be determined from the panel source alone. If it does not — meaning IP-based trust is simply inapplicable to UDS connections regardless of what CIDRs are configured — this would be a limitation in xray-core that the panel cannot work around on its own. --- **Bug 2 — `sessionIDLength` emitted as a JSON string** This behaviour is intentional in the current code, but may conflict with xray-core 26.6.22. `frontend/src/schemas/protocols/stream/xhttp.ts:71` declares: ```ts sessionIDLength: z.string().default(''), ``` `frontend/src/lib/xray/stream-wire-normalize.ts:22` lists `'sessionIDLength'` in `PLACEMENT_STRING_FIELDS`, which are stripped only when empty. A non-empty value such as `"20"` is emitted verbatim as the JSON string `"sessionIDLength": "20"`. This design is deliberate because the field also accepts dash-range values like `"8-16"`. The panel tooltip (en-US.json:540) confirms the intention: "Length or range (e.g. 8-16) of generated session IDs." If xray-core 26.6.22 changed `sessionIDLength` from a type that accepts a string-encoded integer (`"20"`) to a plain JSON integer (`20`), the panel's string output would fail to unmarshal and xray-core would fall back. Whether that change occurred in xray-core 26.6.22 is not verifiable from the panel source. To confirm, inspect the raw Xray JSON config actually written to disk (accessible via the panel's xray config view or directly at `/etc/x-ui/x-ui.db`) and compare the `sessionIDLength` field type against what xray-core's Go struct expects in 26.6.22. --- **To help narrow down the root cause of both issues**, it would be useful to share: 1. The raw `streamSettings` JSON stored for the affected inbound (copy it from the panel's "Edit → Stream" advanced JSON view). 2. Whether the xray-core `"not configured"` warning appears even when `trustedXForwardedFor` contains only valid CIDRs (e.g. `0.0.0.0/0`) and the "Cloudflare CDN" preset was never applied. 3. Whether `sessionIDLength` behaves differently with a range value like `"8-16"` versus a plain integer string like `"20"`. --- *This reply was generated automatically; a maintainer may follow up.*
Author
Owner

@anartikov commented on GitHub (Jun 23, 2026):

Update Details and Test Results (Xray-core v26.6.22)

1. Raw streamSettings JSON (Sanitized)

After saving 0.0.0.0/0 in the UI, the following configuration is written to streamSettings (emails, UUIDs, and domains have been redacted):

{
  "network": "xhttp",
  "xhttpSettings": {
    "path": "/secret-path",
    "host": "example.com",
    "mode": "packet-up",
    "xPaddingBytes": "100-1000",
    "scMaxBufferedPosts": 30
  },
  "security": "none",
  "externalProxy": [
    {
      "forceTls": "tls",
      "dest": "example.com",
      "port": 443,
      "remark": "",
      "sni": "example.com",
      "fingerprint": "firefox",
      "alpn": [
        "h2",
        "http/1.1"
      ]
    }
  ],
  "sockopt": {
    "tcpFastOpen": true,
    "domainStrategy": "UseIPv4",
    "tcpKeepAliveIdle": 300,
    "tcpcongestion": "cubic",
    "trustedXForwardedFor": [
      "0.0.0.0/0"
    ]
  }
}

2. Behavior of trustedXForwardedFor with a Valid CIDR on UDS

When manually entering 0.0.0.0/0 (while ignoring the UI visually switching back to the Cloudflare preset) and saving the configuration, the JSON array is stored correctly in trustedXForwardedFor, as shown above.

However, at runtime Xray-core produces a different error instead of the previous warning:

ERROR - XRAY: common/protocol/http: ignored potentially forged "X-Forwarded-For" from 0.0.0.0:0: MY_REAL_IP

This indicates that even when 0.0.0.0/0 is correctly applied in the configuration, Xray-core's IP matching mechanism still treats the UDS pseudo-address (0.0.0.0:0) as forged or otherwise not matching standard IP/CIDR validation logic.


3. sessionIDLength: Range vs Fixed Integer String

The behavior appears to confirm the original hypothesis.

Working configuration

Using a range value such as:

"sessionIDLength": "16-24"

or

"sessionIDLength": "8-16"

works correctly and the tunnel remains stable.

Failing configuration

Using a fixed string value such as:

"sessionIDLength": "20"

causes the fallback/loop failure.

It appears that Xray-core v26.6.22 expects an actual JSON integer for fixed values, while the panel always serializes the field as a string. As a result, fixed-length values are rejected, whereas range-based values continue to work because string ranges are accepted by the parser.

This makes the range format a viable workaround for the issue.

<!-- gh-comment-id:4782502166 --> @anartikov commented on GitHub (Jun 23, 2026): # Update Details and Test Results (Xray-core v26.6.22) ## 1. Raw `streamSettings` JSON (Sanitized) After saving `0.0.0.0/0` in the UI, the following configuration is written to `streamSettings` (emails, UUIDs, and domains have been redacted): ```json { "network": "xhttp", "xhttpSettings": { "path": "/secret-path", "host": "example.com", "mode": "packet-up", "xPaddingBytes": "100-1000", "scMaxBufferedPosts": 30 }, "security": "none", "externalProxy": [ { "forceTls": "tls", "dest": "example.com", "port": 443, "remark": "", "sni": "example.com", "fingerprint": "firefox", "alpn": [ "h2", "http/1.1" ] } ], "sockopt": { "tcpFastOpen": true, "domainStrategy": "UseIPv4", "tcpKeepAliveIdle": 300, "tcpcongestion": "cubic", "trustedXForwardedFor": [ "0.0.0.0/0" ] } } ``` --- ## 2. Behavior of `trustedXForwardedFor` with a Valid CIDR on UDS When manually entering `0.0.0.0/0` (while ignoring the UI visually switching back to the Cloudflare preset) and saving the configuration, the JSON array is stored correctly in `trustedXForwardedFor`, as shown above. However, at runtime Xray-core produces a different error instead of the previous warning: ```text ERROR - XRAY: common/protocol/http: ignored potentially forged "X-Forwarded-For" from 0.0.0.0:0: MY_REAL_IP ``` This indicates that even when `0.0.0.0/0` is correctly applied in the configuration, Xray-core's IP matching mechanism still treats the UDS pseudo-address (`0.0.0.0:0`) as forged or otherwise not matching standard IP/CIDR validation logic. --- ## 3. `sessionIDLength`: Range vs Fixed Integer String The behavior appears to confirm the original hypothesis. ### Working configuration Using a range value such as: ```json "sessionIDLength": "16-24" ``` or ```json "sessionIDLength": "8-16" ``` works correctly and the tunnel remains stable. ### Failing configuration Using a fixed string value such as: ```json "sessionIDLength": "20" ``` causes the fallback/loop failure. It appears that Xray-core v26.6.22 expects an actual JSON integer for fixed values, while the panel always serializes the field as a string. As a result, fixed-length values are rejected, whereas range-based values continue to work because string ranges are accepted by the parser. This makes the range format a viable workaround for the issue.
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#3847
No description provided.