mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #5514] [Bug]: xhttp over Unix socket breaks trustedXForwardedFor JSON typing in UI #3847
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#3847
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 configuretrustedXForwardedForunder 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.trustedXForwardedForis not configured.How to reproduce the problem
xhttpnetwork protocol./dev/shm/uds2023.sock,0666).0.0.0.0/0or127.0.0.1) into theTrusted X-Forwarded-Forfield.Expected behavior
The UI should allow administrators to input raw IP/CIDR arrays into
trustedXForwardedForfor 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
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
@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 —
trustedXForwardedFordisplay and the Cloudflare presetTwo 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 whethertrustedXForwardedForis non-empty: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"totrustedXForwardedFor:The golden test fixture at
frontend/src/test/golden/fixtures/sockopt/full.jsonshows the expected wire format for this field is IP CIDRs: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 theX-Forwarded-Forheader 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 populatetrustedXForwardedForwith actual IP CIDRs instead (e.g. Cloudflare's published proxy ranges, or0.0.0.0/0/::/0to 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 of0.0.0.0/0cannot 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 —
sessionIDLengthemitted as a JSON stringThis behaviour is intentional in the current code, but may conflict with xray-core 26.6.22.
frontend/src/schemas/protocols/stream/xhttp.ts:71declares:frontend/src/lib/xray/stream-wire-normalize.ts:22lists'sessionIDLength'inPLACEMENT_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
sessionIDLengthfrom 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 thesessionIDLengthfield 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:
streamSettingsJSON stored for the affected inbound (copy it from the panel's "Edit → Stream" advanced JSON view)."not configured"warning appears even whentrustedXForwardedForcontains only valid CIDRs (e.g.0.0.0.0/0) and the "Cloudflare CDN" preset was never applied.sessionIDLengthbehaves 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.
@anartikov commented on GitHub (Jun 23, 2026):
Update Details and Test Results (Xray-core v26.6.22)
1. Raw
streamSettingsJSON (Sanitized)After saving
0.0.0.0/0in the UI, the following configuration is written tostreamSettings(emails, UUIDs, and domains have been redacted):2. Behavior of
trustedXForwardedForwith a Valid CIDR on UDSWhen 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 intrustedXForwardedFor, as shown above.However, at runtime Xray-core produces a different error instead of the previous warning:
This indicates that even when
0.0.0.0/0is 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 StringThe behavior appears to confirm the original hypothesis.
Working configuration
Using a range value such as:
or
works correctly and the tunnel remains stable.
Failing configuration
Using a fixed string value such as:
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.