[PR #4065] [MERGED] Fix xhttp xPadding settings missing from generated links (panel + subs) #5588

Closed
opened 2026-10-31 20:48:01 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/4065
Author: @pwnnex
Created: 4/21/2026
Status: ✅ Merged
Merged: 4/21/2026
Merged by: @MHSanaei

Base: main ← Head: fix/xhttp-padding-obfs-in-subs


📝 Commits (2)

  • 37ac0a2 Fix: propagate xhttp xPadding settings into generated subscription links
  • 0a99f19 Also propagate xhttp xPadding settings into the panel's own Info/QR links

📊 Changes

3 files changed (+155 additions, -2 deletions)

View changed files

📝 sub/subService.go (+71 -0)
📝 web/assets/js/model/inbound.js (+58 -0)
📝 web/assets/js/model/outbound.js (+26 -2)

📄 Description

Summary

Admins configuring an xhttp inbound with a non-default xPaddingBytes, or enabling obfs mode with a custom xPaddingKey / xPaddingHeader / xPaddingPlacement / xPaddingMethod, end up with working server settings but a client link that doesn't mention any of them. The client keeps xray / sing-box's internal defaults, every request it sends fails the server's padding validation and the inbound log fills with

invalid padding (queryInHeader=Referer, key=x_padding) length: 0

With the custom-key case, xray ends up looking for a header/cookie that the client never sets, so the key-side of the error looks like key="" to the admin. The client-visible symptom is "no matter what I put in Padding Key, only the default x_padding + Referer actually work" — user reports on OpenWRT / Podkop / sing-box.

This PR closes the gap in every place where 3x-ui generates a link from an xhttp stream.

What was dropped before

All four link generators only copied path, host, mode out of xhttpSettings and silently discarded:

  • xPaddingBytes
  • xPaddingObfsMode
  • xPaddingKey
  • xPaddingHeader
  • xPaddingPlacement
  • xPaddingMethod

This happened both in:

  • sub/subService.go — the subscription service that serves /sub/<id> to external clients,
  • web/assets/js/model/inbound.js — the panel's own "Copy URL" / QR / Info buttons in the inbound details modal.

So regardless of how the admin obtained the link (fetching a subscription or copying from the panel UI), the padding settings never reached them.

Fix

Three files, three mirrored changes:

sub/subService.go (server-side)

New helper applyXhttpPaddingParams(xhttp, params) writes two encodings side-by-side:

  • x_padding_bytes=<range> — flat query param, read by sing-box-family clients (Podkop, OpenWRT sing-box, Karing, NekoBox, …).
  • extra=<url-encoded JSON> — full xhttp settings blob, read by xray-core-family clients (v2rayNG, Happ, Furious, Exclave, …), including the obfs-mode key / header / placement / method.

Called from genVlessLink, genTrojanLink, genShadowsocksLink. genVmessLink copies the same fields directly into the VMess base64 JSON body.

web/assets/js/model/inbound.js (panel UI)

Add two static helpers on Inbound:

  • Inbound.applyXhttpPaddingToParams(xhttp, params) — for vless:// / trojan:// / ss:// URLs. Same two-encoding scheme as the Go helper.
  • Inbound.applyXhttpPaddingToObj(xhttp, obj) — for the VMess JSON blob.

Called from genVmessLink, genVLESSLink, genTrojanLink, genSSLink.

web/assets/js/model/outbound.js (latent positional-arg bug)

Both the VMess-JSON path (L933) and fromParamLink (L975) were calling:

new xHTTPStreamSettings(json.path, json.host, json.mode)

The constructor signature is (path, host, headers, scMaxBufferedPosts, scMaxEachPostBytes, scStreamUpServerSecs, noSSEHeader, xPaddingBytes, mode, …), so mode was silently landing in the headers slot and the real mode field kept its "auto" default.

Fixed by constructing the object with only path/host positionally and setting mode by name. While touching the VLESS URL parser, also pick up x_padding_bytes and the extra JSON blob from the imported URL so the symmetric import of a padded link works too.

Zero-impact on simple inbounds

All additions guard on "is the field actually set?" — empty strings and xPaddingObfsMode: false are skipped. An inbound that uses the UI defaults produces the exact same URL it produced before this patch, so existing subscriptions / deep-links are unaffected.

Test plan

  • go build ./... + go vet ./sub/... clean
  • Inbound with no padding override → URL unchanged vs. pre-patch
  • Inbound with xPaddingBytes="80-600" only → URL gains x_padding_bytes=80-600 and extra={"xPaddingBytes":"80-600"}; obfs-only fields not emitted
  • Inbound with obfs enabled + xPaddingKey="remixsid" + xPaddingHeader="Cookie" + placement/method → all set values land in extra; empty ones are omitted so xray falls back to its own defaults
  • Same result whether the admin pulls the link from the panel (genVmessLink / genVLESSLink / genTrojanLink / genSSLink) or from /sub/<id>
  • Importing a VLESS URL that carries x_padding_bytes=... and/or extra=... into an outbound now round-trips mode and the padding settings, instead of dropping mode into the headers slot

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/4065 **Author:** [@pwnnex](https://github.com/pwnnex) **Created:** 4/21/2026 **Status:** ✅ Merged **Merged:** 4/21/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/xhttp-padding-obfs-in-subs` --- ### 📝 Commits (2) - [`37ac0a2`](https://github.com/MHSanaei/3x-ui/commit/37ac0a2abda7d9e01a875bc0e2fad4cc183d43c8) Fix: propagate xhttp xPadding settings into generated subscription links - [`0a99f19`](https://github.com/MHSanaei/3x-ui/commit/0a99f199509b2531c6f199ac97e921d214beb6a0) Also propagate xhttp xPadding settings into the panel's own Info/QR links ### 📊 Changes **3 files changed** (+155 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `sub/subService.go` (+71 -0) 📝 `web/assets/js/model/inbound.js` (+58 -0) 📝 `web/assets/js/model/outbound.js` (+26 -2) </details> ### 📄 Description ## Summary Admins configuring an xhttp inbound with a non-default `xPaddingBytes`, or enabling obfs mode with a custom `xPaddingKey` / `xPaddingHeader` / `xPaddingPlacement` / `xPaddingMethod`, end up with working **server** settings but a **client link** that doesn't mention any of them. The client keeps xray / sing-box's internal defaults, every request it sends fails the server's padding validation and the inbound log fills with ``` invalid padding (queryInHeader=Referer, key=x_padding) length: 0 ``` With the custom-key case, xray ends up looking for a header/cookie that the client never sets, so the key-side of the error looks like `key=""` to the admin. The client-visible symptom is *"no matter what I put in Padding Key, only the default `x_padding` + Referer actually work"* — user reports on OpenWRT / Podkop / sing-box. This PR closes the gap in **every** place where 3x-ui generates a link from an xhttp stream. ## What was dropped before All four link generators only copied `path`, `host`, `mode` out of `xhttpSettings` and silently discarded: - `xPaddingBytes` - `xPaddingObfsMode` - `xPaddingKey` - `xPaddingHeader` - `xPaddingPlacement` - `xPaddingMethod` This happened both in: * `sub/subService.go` — the subscription service that serves `/sub/<id>` to external clients, * `web/assets/js/model/inbound.js` — the panel's own "Copy URL" / QR / Info buttons in the inbound details modal. So regardless of how the admin obtained the link (fetching a subscription or copying from the panel UI), the padding settings never reached them. ## Fix Three files, three mirrored changes: ### `sub/subService.go` (server-side) New helper `applyXhttpPaddingParams(xhttp, params)` writes two encodings side-by-side: - `x_padding_bytes=<range>` — flat query param, read by sing-box-family clients (Podkop, OpenWRT sing-box, Karing, NekoBox, …). - `extra=<url-encoded JSON>` — full xhttp settings blob, read by xray-core-family clients (v2rayNG, Happ, Furious, Exclave, …), including the obfs-mode key / header / placement / method. Called from `genVlessLink`, `genTrojanLink`, `genShadowsocksLink`. `genVmessLink` copies the same fields directly into the VMess base64 JSON body. ### `web/assets/js/model/inbound.js` (panel UI) Add two static helpers on `Inbound`: - `Inbound.applyXhttpPaddingToParams(xhttp, params)` — for `vless://` / `trojan://` / `ss://` URLs. Same two-encoding scheme as the Go helper. - `Inbound.applyXhttpPaddingToObj(xhttp, obj)` — for the VMess JSON blob. Called from `genVmessLink`, `genVLESSLink`, `genTrojanLink`, `genSSLink`. ### `web/assets/js/model/outbound.js` (latent positional-arg bug) Both the VMess-JSON path (L933) and `fromParamLink` (L975) were calling: ```js new xHTTPStreamSettings(json.path, json.host, json.mode) ``` The constructor signature is `(path, host, headers, scMaxBufferedPosts, scMaxEachPostBytes, scStreamUpServerSecs, noSSEHeader, xPaddingBytes, mode, …)`, so `mode` was silently landing in the `headers` slot and the real `mode` field kept its `"auto"` default. Fixed by constructing the object with only `path`/`host` positionally and setting `mode` by name. While touching the VLESS URL parser, also pick up `x_padding_bytes` and the `extra` JSON blob from the imported URL so the symmetric *import* of a padded link works too. ## Zero-impact on simple inbounds All additions guard on *"is the field actually set?"* — empty strings and `xPaddingObfsMode: false` are skipped. An inbound that uses the UI defaults produces the exact same URL it produced before this patch, so existing subscriptions / deep-links are unaffected. ## Test plan - [x] `go build ./...` + `go vet ./sub/...` clean - [x] Inbound with no padding override → URL unchanged vs. pre-patch - [x] Inbound with `xPaddingBytes="80-600"` only → URL gains `x_padding_bytes=80-600` and `extra={"xPaddingBytes":"80-600"}`; obfs-only fields not emitted - [x] Inbound with obfs enabled + `xPaddingKey="remixsid"` + `xPaddingHeader="Cookie"` + placement/method → all set values land in `extra`; empty ones are omitted so xray falls back to its own defaults - [x] Same result whether the admin pulls the link from the panel (`genVmessLink` / `genVLESSLink` / `genTrojanLink` / `genSSLink`) or from `/sub/<id>` - [x] Importing a VLESS URL that carries `x_padding_bytes=...` and/or `extra=...` into an outbound now round-trips mode and the padding settings, instead of dropping mode into the headers slot --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 20:48:01 +07:00
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#5588
No description provided.