Skip to content

support real client IP behind gRPC reverse proxies - #167

Open
yunzeok wants to merge 4 commits into
VaalaCat:mainfrom
yunzeok:main
Open

yunzeok wants to merge 4 commits into
VaalaCat:mainfrom
yunzeok:main

Conversation

@yunzeok

@yunzeok yunzeok commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

This change improves client address detection for gRPC connections when frp-panel is deployed behind a reverse proxy.

Currently, ClientAddr() relies only on peer.FromContext(), which returns the direct gRPC peer address. When a reverse proxy such as Nginx, EdgeOne, or another CDN/proxy is used, the displayed client address becomes the proxy's address instead of the original client IP.

This change updates ClientAddr() to:

  • Prefer X-Real-IP from incoming gRPC metadata.
  • Fall back to the first valid IP in X-Forwarded-For.
  • Preserve the existing peer.Addr behavior when proxy headers are unavailable.

This keeps direct gRPC deployments fully compatible while allowing deployments behind trusted reverse proxies to display the actual client IP.

Example proxy configuration:

grpc_set_header X-Real-IP $remote_addr;
grpc_set_header X-Forwarded-For $remote_addr;

Security note:

X-Real-IP and X-Forwarded-For should only be trusted when requests come through a trusted reverse proxy. Deployments should restrict direct access to the gRPC origin or configure the proxy trust boundary appropriately.

This branch has not been deployed

No deployments
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.

1 participant