Skip to content

Option to disable automatic X-Forwarded-For append/add#8576

Open
lextiz wants to merge 1 commit intoenvoyproxy:mainfrom
lextiz:disable-forwarded-for
Open

Option to disable automatic X-Forwarded-For append/add#8576
lextiz wants to merge 1 commit intoenvoyproxy:mainfrom
lextiz:disable-forwarded-for

Conversation

@lextiz
Copy link

@lextiz lextiz commented Mar 23, 2026

What type of PR is this?

api: add ClientTrafficPolicy option to disable automatic X-Forwarded-For append

What this PR does / why we need it:

This PR adds a new ClientTrafficPolicy option to disable Envoy Gateway’s automatic appending of the downstream address to the X-Forwarded-For header.

Today, EG appends to X-Forwarded-For in both the default HTTP connection manager path and the XFF original IP detection path, without a user-facing way to turn that off. This change exposes a policy-level switch and wires it through to the relevant Envoy settings while preserving existing behavior by default.

The motivation is similar to #8527, which made x-forwarded-host behavior configurable.

Which issue(s) this PR fixes:

No issue exists

Release Notes: Yes

@lextiz lextiz requested a review from a team as a code owner March 23, 2026 11:40
@netlify
Copy link

netlify bot commented Mar 23, 2026

Deploy Preview for cerulean-figolla-1f9435 canceled.

Name Link
🔨 Latest commit 8634dde
🔍 Latest deploy log https://app.netlify.com/projects/cerulean-figolla-1f9435/deploys/69c3c73693374c00084eaa64

@lextiz lextiz force-pushed the disable-forwarded-for branch 6 times, most recently from b5eb4b4 to 54a782c Compare March 23, 2026 14:55
@zirain zirain force-pushed the disable-forwarded-for branch from 54a782c to 0eb05e9 Compare March 24, 2026 01:04
@lextiz lextiz force-pushed the disable-forwarded-for branch from 0eb05e9 to 2856c19 Compare March 24, 2026 08:48
Comment on lines +380 to +381
UseRemoteAddress: &wrapperspb.BoolValue{Value: useRemoteAddress},
SkipXffAppend: ptr.Deref(irListener.Headers, ir.HeaderSettings{}).DisableXForwardedFor,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When use_remote_address is true, XFF is already skipped.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if you are setting it to false for using client ip detection then it should be set in the extension not in HCM

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xffHeaderConfigAny, _ = proto.ToAnyWithValidation(&xffv3.XffConfig{
XffTrustedCidrs: &xffv3.XffTrustedCidrs{
Cidrs: trustedCidrs,
},
SkipXffAppend: wrapperspb.Bool(false),
})

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review! I have removed the HCM-level setting entirely and keep SkipXffAppend only in the XFF original IP detection extension config.

@lextiz lextiz force-pushed the disable-forwarded-for branch from 2856c19 to e4673e9 Compare March 24, 2026 13:17
@codecov
Copy link

codecov bot commented Mar 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.33%. Comparing base (9cac348) to head (1e26506).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8576      +/-   ##
==========================================
- Coverage   74.35%   74.33%   -0.03%     
==========================================
  Files         242      243       +1     
  Lines       37811    38144     +333     
==========================================
+ Hits        28114    28353     +239     
- Misses       7748     7803      +55     
- Partials     1949     1988      +39     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lextiz lextiz force-pushed the disable-forwarded-for branch from e4673e9 to 1e26506 Compare March 24, 2026 15:20
@lextiz
Copy link
Author

lextiz commented Mar 25, 2026

@rudrakhp Is there a chance that this change would make it to v1.8?


// DisableXForwardedFor controls if Envoy should stop appending the downstream address to
// the X-Forwarded-For header. The default is to keep appending the downstream address.
DisableXForwardedFor bool `json:"disableXForwardedFor,omitempty" yaml:"disableXForwardedFor,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
DisableXForwardedFor bool `json:"disableXForwardedFor,omitempty" yaml:"disableXForwardedFor,omitempty"`
DisableXForwardedForAppend bool `json:"disableXForwardedForAppend,omitempty" yaml:"disableXForwardedFor,omitempty"`

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

})
} else if clientIPDetection.XForwardedFor.NumTrustedHops != nil {
xffHeaderConfigAny, _ = proto.ToAnyWithValidation(&xffv3.XffConfig{
XffNumTrustedHops: xffNumTrustedHops(clientIPDetection),
Copy link
Member

@rudrakhp rudrakhp Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if this logic in xffNumTrustedHops() is affected by change in appending behavior. For this we can write a E2E test with XFF append disabled and using num trusted hops.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@lextiz lextiz force-pushed the disable-forwarded-for branch 2 times, most recently from c80bcde to 81c6c5c Compare March 25, 2026 11:17
Signed-off-by: Alexander Bolshakov <lextiz@gmail.com>
@lextiz lextiz force-pushed the disable-forwarded-for branch from 64a8de7 to 8634dde Compare March 25, 2026 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants