Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
web::ProxyIpResolver Class Reference

Resolves the client's IP address, considering proxy servers. More...

#include <ProxyIpResolver.hpp>

Public Types

using HttpHeaders = boost::beast::http::request<boost::beast::http::string_body>::header_type
 

Public Member Functions

 ProxyIpResolver (std::unordered_set< std::string > proxyIps, std::unordered_set< std::string > proxyTokens)
 Constructs a ProxyIpResolver.
 
std::string resolveClientIp (std::string const &connectionIp, HttpHeaders const &headers) const
 Resolves the client's IP address from the connection IP and HTTP headers.
 

Static Public Member Functions

static ProxyIpResolver fromConfig (util::config::ClioConfigDefinition const &config)
 Creates a ProxyIpResolver from a configuration.
 

Static Public Attributes

static constexpr std::string_view kPROXY_TOKEN_HEADER = "X-Proxy-Token"
 

Detailed Description

Resolves the client's IP address, considering proxy servers.

This class is designed to determine the original IP address of a client when the connection is forwarded through a proxy server. It uses a configurable list of trusted proxy IPs and proxy tokens to decide whether to trust the Forwarded HTTP header.

Constructor & Destructor Documentation

◆ ProxyIpResolver()

web::ProxyIpResolver::ProxyIpResolver ( std::unordered_set< std::string > proxyIps,
std::unordered_set< std::string > proxyTokens )

Constructs a ProxyIpResolver.

Parameters
proxyIpsA set of trusted proxy IP addresses.
proxyTokensA set of trusted proxy tokens. The tokens will be hashed with SHA-256.

Member Function Documentation

◆ fromConfig()

ProxyIpResolver web::ProxyIpResolver::fromConfig ( util::config::ClioConfigDefinition const & config)
static

Creates a ProxyIpResolver from a configuration.

The configuration should contain server.proxy.ips and server.proxy.tokens arrays.

Parameters
configThe Clio configuration.
Returns
A new ProxyIpResolver instance.

◆ resolveClientIp()

std::string web::ProxyIpResolver::resolveClientIp ( std::string const & connectionIp,
HttpHeaders const & headers ) const

Resolves the client's IP address from the connection IP and HTTP headers.

If the connection IP is in the trusted proxy list, or if a valid proxy token is provided in the headers, this method will attempt to extract the client's IP from the Forwarded header. Otherwise, it returns the connection IP.

Parameters
connectionIpThe IP address of the direct connection.
headersThe HTTP request headers.
Returns
The resolved client IP address as a string.

The documentation for this class was generated from the following files: