Crate client_ip

Source
Expand description

§client-ip

License Crates.io Docs.rs

Secure extraction of a client IP from http::HeaderMap. The code was initially extracted from the axum-client-ip crate for non-axum use.

If you’re maintaining client IP extraction in other frameworks based on http, consider using this crate, so we can handle security-sensitive code in one place. Look at the axum-client-ip integration for reference.

§Supported extractors

Open an issue if there’s an uncovered header or send a PR straight away.

ExtractorHeader UsedTypical Proxy / Service
cf_connecting_ipCF-Connecting-IPCloudflare
cloudfront_viewer_addressCloudFront-Viewer-AddressAWS CloudFront
fly_client_ipFly-Client-IPFly.io
rightmost_forwardedForwardedProxies supporting RFC 7239 (extracts rightmost for=)
rightmost_x_forwarded_forX-Forwarded-ForNginx, Apache, HAProxy, CDNs, LBs
true_client_ipTrue-Client-IPCloudflare, Akamai
x_real_ipX-Real-IpNginx

§Contributing

  • please run .pre-commit.sh before sending a PR, it will check everything

§License

This project is licensed under the MIT license.

Enums§

Error
Errors that can occur during IP extraction

Functions§

cf_connecting_ip
Extracts client IP from CF-Connecting-IP (Cloudflare) header
cloudfront_viewer_address
Extracts client IP from CloudFront-Viewer-Address (AWS CloudFront) header
fly_client_ip
Extracts client IP from Fly-Client-IP (Fly.io) header
rightmost_forwardedforwarded-header
Extracts the rightmost IP from Forwarded header
rightmost_x_forwarded_for
Extracts the rightmost IP address from the comma-separated list in the value of the last X-Forwarded-For header.
true_client_ip
Extracts client IP from True-Client-IP (Akamai, Cloudflare) header
x_real_ip
Extracts client IP from X-Real-Ip (Nginx) header