Skip to content

core/gateway: set x-forwarded headers #1927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 27, 2025
Merged

core/gateway: set x-forwarded headers #1927

merged 5 commits into from
May 27, 2025

Conversation

fredr
Copy link
Member

@fredr fredr commented May 22, 2025

related to #1926

@fredr fredr self-assigned this May 22, 2025
@encore-cla
Copy link

encore-cla bot commented May 22, 2025

All committers have signed the CLA.

@fredr fredr requested a review from Copilot May 22, 2025 13:19
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds X-Forwarded-* header propagation to the HTTP proxy so upstream services see original client IP, host, and protocol.

  • Set X-Forwarded-For by appending client IP to any existing header
  • Propagate incoming Host as X-Forwarded-Host
  • Insert X-Forwarded-Proto based on request scheme
Comments suppressed due to low confidence (2)

runtimes/core/src/api/gateway/mod.rs:327

  • Add unit/integration tests to verify that X-Forwarded-For, X-Forwarded-Host, and X-Forwarded-Proto headers are correctly inserted, appended, or removed under various session conditions.
// Set X-Forwarded-* headers, based on https://cs.opensource.google/go/go/+/refs/tags/go1.24.3:src/net/http/httputil/reverseproxy.go;l=78

runtimes/core/src/api/gateway/mod.rs:340

  • [nitpick] Ensure insert_header replaces existing values rather than appending; if it appends, explicitly remove the old x-forwarded-for header first to avoid duplicate entries.
upstream_request.insert_header("x-forwarded-for", combined)?;

@fredr fredr requested a review from ekerfelt May 22, 2025 14:01
@fredr fredr force-pushed the fredr/forwared-for branch 2 times, most recently from eccb136 to a5fa960 Compare May 23, 2025 09:05
@fredr fredr force-pushed the fredr/forwared-for branch from a5fa960 to 1bf1988 Compare May 26, 2025 07:29
@fredr fredr requested a review from eandre May 26, 2025 07:30
@fredr fredr merged commit a0fd97f into main May 27, 2025
4 checks passed
@fredr fredr deleted the fredr/forwared-for branch May 27, 2025 09:58
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