[PR #6134] [CLOSED] fix(sub): honor trustedProxyCIDRs before letting forwarded headers steer URLs #6097

Closed
opened 2026-11-02 04:06:21 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6134
Author: @PathGao
Created: 7/29/2026
Status: ❌ Closed

Base: main ← Head: fix-sub-forwarded-header-trust


📝 Commits (3)

  • 9692e7d fix(sub): honor trustedProxyCIDRs before letting forwarded headers steer URLs
  • 161da9d fix(sub): evaluate the forwarded-header gate once and log when it bites
  • 457503e fix(sub): enforce forwarded-header trust by default

📊 Changes

3 files changed (+296 additions, -6 deletions)

View changed files

➕ internal/sub/forwarded_trust.go (+77 -0)
➕ internal/sub/forwarded_trust_test.go (+202 -0)
📝 internal/sub/service.go (+17 -6)

📄 Description

Summary

Subscription URLs now apply trustedProxyCIDRs with the same trust boundary as panel-generated links. Before this change, a request reaching the subscription server could steer generated hosts and schemes through forwarded headers even when the setting was unset, empty, or still at its default; now those states trust only loopback, while a configured value trusts exactly its listed addresses and CIDRs.

This is an intentional default-behavior change. Deployments using a remote reverse proxy for the subscription endpoint must add that proxy to trustedProxyCIDRs or configure subURI; this matches the setting's documented meaning and the panel's existing behavior. Rejected forwarded headers are logged at debug level, with one process-level warning when they first affect URL generation.

Tests

  • Table-driven request coverage for unset, empty, factory-default, loopback, custom-CIDR, malformed, and IPv4-mapped proxy origins.
  • Coverage that untrusted X-Real-IP cannot bypass the forwarded-header gate.
  • The local checkout has no Go toolchain, so the Go suite could not be run here.

🔄 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/6134 **Author:** [@PathGao](https://github.com/PathGao) **Created:** 7/29/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix-sub-forwarded-header-trust` --- ### 📝 Commits (3) - [`9692e7d`](https://github.com/MHSanaei/3x-ui/commit/9692e7dfb70a30b86f36750322fd95a4c4670b74) fix(sub): honor trustedProxyCIDRs before letting forwarded headers steer URLs - [`161da9d`](https://github.com/MHSanaei/3x-ui/commit/161da9d30a0c27470f416615e616cc1a05e907fd) fix(sub): evaluate the forwarded-header gate once and log when it bites - [`457503e`](https://github.com/MHSanaei/3x-ui/commit/457503e130593cf5064e4a38fd4feffb04a415f7) fix(sub): enforce forwarded-header trust by default ### 📊 Changes **3 files changed** (+296 additions, -6 deletions) <details> <summary>View changed files</summary> ➕ `internal/sub/forwarded_trust.go` (+77 -0) ➕ `internal/sub/forwarded_trust_test.go` (+202 -0) 📝 `internal/sub/service.go` (+17 -6) </details> ### 📄 Description ## Summary Subscription URLs now apply `trustedProxyCIDRs` with the same trust boundary as panel-generated links. Before this change, a request reaching the subscription server could steer generated hosts and schemes through forwarded headers even when the setting was unset, empty, or still at its default; now those states trust only loopback, while a configured value trusts exactly its listed addresses and CIDRs. This is an intentional default-behavior change. Deployments using a remote reverse proxy for the subscription endpoint must add that proxy to `trustedProxyCIDRs` or configure `subURI`; this matches the setting's documented meaning and the panel's existing behavior. Rejected forwarded headers are logged at debug level, with one process-level warning when they first affect URL generation. ## Tests - Table-driven request coverage for unset, empty, factory-default, loopback, custom-CIDR, malformed, and IPv4-mapped proxy origins. - Coverage that untrusted `X-Real-IP` cannot bypass the forwarded-header gate. - The local checkout has no Go toolchain, so the Go suite could not be run here. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:06:21 +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#6097
No description provided.