pub struct Config { /* private fields */ }Expand description
Config for trusted proxies extractor
By default, it trusts the following:
- IPV4 Loopback
- IPV4 Private Networks
- IPV6 Loopback
- IPV6 Private Networks
It also trusts the Forwarded and X-Forwarded-For header by default.
§Example
use trusted_proxies::Config;
let mut config = Config::new_local();
config.add_trusted_ip("168.10.0.0/16").unwrap();
config.trust_x_forwarded_host();
Implementations§
Source§impl Config
impl Config
Sourcepub fn new_local() -> Self
pub fn new_local() -> Self
Create a new TrustedProxies instance with local and private networks ip trusted and FORWARDED / X-Forwarded-For headers trusted
Sourcepub fn add_trusted_ip(&mut self, proxy: &str) -> Result<(), AddrParseError>
pub fn add_trusted_ip(&mut self, proxy: &str) -> Result<(), AddrParseError>
Add a trusted proxy to the list of trusted proxies
proxy can be an IP address or a CIDR
Sourcepub fn is_ip_trusted(&self, remote_addr: &IpAddr) -> bool
pub fn is_ip_trusted(&self, remote_addr: &IpAddr) -> bool
Check if a remote address is trusted given the list of trusted proxies
Sourcepub fn trust_forwarded(&mut self)
pub fn trust_forwarded(&mut self)
Trust the Forwarded header
Sourcepub fn trust_x_forwarded_for(&mut self)
pub fn trust_x_forwarded_for(&mut self)
Trust the X-Forwarded-For header
Sourcepub fn trust_x_forwarded_host(&mut self)
pub fn trust_x_forwarded_host(&mut self)
Trust the X-Forwarded-Host header to fetch the host and optionally the port
It is not recommended to trust this header as it can be easily spoofed, however you can trust it if you are behind a reverse proxy that always sets this header.
If there is multiple values in the header, the last one is used, even if there is multiple proxies in the chain.
If you need to get the original value with multiple proxies in the chain, you can use the
Forwarded header that allows to do that in a secure way.
See RFC7239 for more information.
Sourcepub fn trust_x_forwarded_proto(&mut self)
pub fn trust_x_forwarded_proto(&mut self)
Trust the X-Forwarded-Proto header to fetch the scheme
It is not recommended to trust this header as it can be easily spoofed, however you can trust it if you are behind a reverse proxy that always sets this header.
If there is multiple values in the header, the last one is used, even if there is multiple proxies in the chain.
If you need to get the original value with multiple proxies in the chain, you can use the
Forwarded header that allows to do that in a secure way.
See RFC7239 for more information.
Sourcepub fn trust_x_forwarded_by(&mut self)
pub fn trust_x_forwarded_by(&mut self)
Trust the X-Forwarded-By header to identify the proxy that sent the request
It is not recommended to trust this header as it can be easily spoofed, however you can trust it if you are behind a reverse proxy that always sets this header.
If there is multiple values in the header, the last one is used, even if there is multiple proxies in the chain.
If you need to get the original value with multiple proxies in the chain, you can use the
Forwarded header that allows to do that in a secure way.
See RFC7239 for more information.