Skip to content

Remove X-Real-Ip header #7364

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 3 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 0 additions & 146 deletions config/nginx.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,148 +16,6 @@ events {
}

http {
# Use the `X-Forwarded-For` to replace the client address (`$remote_addr`).
real_ip_header X-Forwarded-For;
# Ignore "trusted addresses" (see `set_real_ip_from` below) when determining the real user IP
real_ip_recursive on;

set_real_ip_from 10.0.0.0/8;
set_real_ip_from 127.0.0.0/24;

# CloudFront IP addresses from http://d7uri8nf7uskq.cloudfront.net/tools/list-cloudfront-ips
# Last updated: 2022-03-26
set_real_ip_from 3.10.17.128/25;
set_real_ip_from 3.11.53.0/24;
set_real_ip_from 3.35.130.128/25;
set_real_ip_from 3.101.158.0/23;
set_real_ip_from 3.128.93.0/24;
set_real_ip_from 3.134.215.0/24;
set_real_ip_from 3.231.2.0/25;
set_real_ip_from 3.234.232.224/27;
set_real_ip_from 3.236.48.0/23;
set_real_ip_from 3.236.169.192/26;
set_real_ip_from 13.32.0.0/15;
set_real_ip_from 13.35.0.0/16;
set_real_ip_from 13.48.32.0/24;
set_real_ip_from 13.54.63.128/26;
set_real_ip_from 13.59.250.0/26;
set_real_ip_from 13.113.196.64/26;
set_real_ip_from 13.113.203.0/24;
set_real_ip_from 13.124.199.0/24;
set_real_ip_from 13.210.67.128/26;
set_real_ip_from 13.224.0.0/14;
set_real_ip_from 13.228.69.0/24;
set_real_ip_from 13.233.177.192/26;
set_real_ip_from 13.249.0.0/16;
set_real_ip_from 15.158.0.0/16;
set_real_ip_from 15.188.184.0/24;
set_real_ip_from 15.207.13.128/25;
set_real_ip_from 15.207.213.128/25;
set_real_ip_from 18.64.0.0/14;
set_real_ip_from 18.154.0.0/15;
set_real_ip_from 18.160.0.0/15;
set_real_ip_from 18.164.0.0/15;
set_real_ip_from 18.172.0.0/15;
set_real_ip_from 18.192.142.0/23;
set_real_ip_from 18.200.212.0/23;
set_real_ip_from 18.216.170.128/25;
set_real_ip_from 18.229.220.192/26;
set_real_ip_from 18.238.0.0/15;
set_real_ip_from 18.244.0.0/15;
set_real_ip_from 34.195.252.0/24;
set_real_ip_from 34.216.51.0/25;
set_real_ip_from 34.223.12.224/27;
set_real_ip_from 34.223.80.192/26;
set_real_ip_from 34.226.14.0/24;
set_real_ip_from 35.158.136.0/24;
set_real_ip_from 35.162.63.192/26;
set_real_ip_from 35.167.191.128/26;
set_real_ip_from 36.103.232.0/25;
set_real_ip_from 36.103.232.128/26;
set_real_ip_from 44.227.178.0/24;
set_real_ip_from 44.234.90.252/30;
set_real_ip_from 44.234.108.128/25;
set_real_ip_from 52.15.127.128/26;
set_real_ip_from 52.46.0.0/18;
set_real_ip_from 52.47.139.0/24;
set_real_ip_from 52.52.191.128/26;
set_real_ip_from 52.56.127.0/25;
set_real_ip_from 52.57.254.0/24;
set_real_ip_from 52.66.194.128/26;
set_real_ip_from 52.78.247.128/26;
set_real_ip_from 52.82.128.0/19;
set_real_ip_from 52.84.0.0/15;
set_real_ip_from 52.124.128.0/17;
set_real_ip_from 52.199.127.192/26;
set_real_ip_from 52.212.248.0/26;
set_real_ip_from 52.220.191.0/26;
set_real_ip_from 52.222.128.0/17;
set_real_ip_from 54.182.0.0/16;
set_real_ip_from 54.192.0.0/16;
set_real_ip_from 54.230.0.0/17;
set_real_ip_from 54.230.128.0/18;
set_real_ip_from 54.230.200.0/21;
set_real_ip_from 54.230.208.0/20;
set_real_ip_from 54.230.224.0/19;
set_real_ip_from 54.233.255.128/26;
set_real_ip_from 54.239.128.0/18;
set_real_ip_from 54.239.192.0/19;
set_real_ip_from 54.240.128.0/18;
set_real_ip_from 58.254.138.0/25;
set_real_ip_from 58.254.138.128/26;
set_real_ip_from 64.252.64.0/18;
set_real_ip_from 64.252.128.0/18;
set_real_ip_from 65.8.0.0/16;
set_real_ip_from 65.9.0.0/17;
set_real_ip_from 65.9.128.0/18;
set_real_ip_from 70.132.0.0/18;
set_real_ip_from 71.152.0.0/17;
set_real_ip_from 99.79.169.0/24;
set_real_ip_from 99.84.0.0/16;
set_real_ip_from 99.86.0.0/16;
set_real_ip_from 108.138.0.0/15;
set_real_ip_from 108.156.0.0/14;
set_real_ip_from 116.129.226.0/25;
set_real_ip_from 116.129.226.128/26;
set_real_ip_from 118.193.97.64/26;
set_real_ip_from 118.193.97.128/25;
set_real_ip_from 119.147.182.0/25;
set_real_ip_from 119.147.182.128/26;
set_real_ip_from 120.52.12.64/26;
set_real_ip_from 120.52.22.96/27;
set_real_ip_from 120.52.39.128/27;
set_real_ip_from 120.52.153.192/26;
set_real_ip_from 120.232.236.0/25;
set_real_ip_from 120.232.236.128/26;
set_real_ip_from 120.253.240.192/26;
set_real_ip_from 120.253.241.160/27;
set_real_ip_from 120.253.245.128/26;
set_real_ip_from 120.253.245.192/27;
set_real_ip_from 130.176.0.0/17;
set_real_ip_from 130.176.128.0/18;
set_real_ip_from 130.176.192.0/19;
set_real_ip_from 130.176.224.0/20;
set_real_ip_from 143.204.0.0/16;
set_real_ip_from 144.220.0.0/16;
set_real_ip_from 180.163.57.0/25;
set_real_ip_from 180.163.57.128/26;
set_real_ip_from 204.246.164.0/22;
set_real_ip_from 204.246.168.0/22;
set_real_ip_from 204.246.172.0/24;
set_real_ip_from 204.246.173.0/24;
set_real_ip_from 204.246.174.0/23;
set_real_ip_from 204.246.176.0/20;
set_real_ip_from 205.251.200.0/21;
set_real_ip_from 205.251.208.0/20;
set_real_ip_from 205.251.249.0/24;
set_real_ip_from 205.251.250.0/23;
set_real_ip_from 205.251.252.0/23;
set_real_ip_from 205.251.254.0/24;
set_real_ip_from 216.137.32.0/19;
set_real_ip_from 223.71.11.0/27;
set_real_ip_from 223.71.71.96/27;
set_real_ip_from 223.71.71.128/25;

# Disable emitting nginx version on error pages and in the “Server” response header field
server_tokens off;

Expand Down Expand Up @@ -193,10 +51,6 @@ http {
# Use the passed-in `Host` header for proxied requests instead of changing it to the `proxy_pass` value
proxy_set_header Host $http_host;

# Add a `X-Real-Ip` header to proxied requests containing the client address
# (after being changed by the `realip` module)
proxy_set_header X-Real-Ip $remote_addr;

# Disable `Location` and `Refresh` header rewriting for proxied responses
proxy_redirect off;

Expand Down
35 changes: 0 additions & 35 deletions src/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,38 +35,3 @@ impl Header for XRequestId {
values.extend(std::iter::once(value));
}
}

static X_REAL_IP: HeaderName = HeaderName::from_static("x-real-ip");

pub struct XRealIp(String);

impl XRealIp {
pub fn as_str(&self) -> &str {
self.0.as_str()
}
}

impl Header for XRealIp {
fn name() -> &'static HeaderName {
&X_REAL_IP
}

fn decode<'i, I>(values: &mut I) -> Result<Self, Error>
where
I: Iterator<Item = &'i HeaderValue>,
{
values
.next()
.and_then(|value| value.to_str().ok())
.map(|value| Self(value.to_string()))
.ok_or_else(Error::invalid)
}

fn encode<E>(&self, values: &mut E)
where
E: Extend<HeaderValue>,
{
let value = HeaderValue::from_str(&self.0).unwrap();
values.extend(std::iter::once(value));
}
}
14 changes: 1 addition & 13 deletions src/middleware/log_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! information that we care about like User-Agent

use crate::controllers::util::RequestPartsExt;
use crate::headers::{XRealIp, XRequestId};
use crate::headers::XRequestId;
use crate::middleware::normalize_path::OriginalPath;
use crate::real_ip::process_xff_headers;
use axum::headers::UserAgent;
Expand Down Expand Up @@ -32,7 +32,6 @@ pub struct RequestMetadata {
original_path: Option<Extension<OriginalPath>>,
user_agent: TypedHeader<UserAgent>,
request_id: Option<TypedHeader<XRequestId>>,
real_ip: Option<TypedHeader<XRealIp>>,
}

pub struct Metadata<'a> {
Expand Down Expand Up @@ -77,17 +76,6 @@ impl Display for Metadata<'_> {
let real_ip = self.real_ip.map(|ip| ip.to_string()).unwrap_or_default();
line.add_quoted_field("ip", &real_ip)?;

let x_real_ip = self.request.real_ip.as_ref();
let x_real_ip = x_real_ip
.map(|ip| ip.as_str().to_string())
.unwrap_or_default();
line.add_quoted_field("fwd", &x_real_ip)?;

// TODO: Remove this once production traffic has shown that `ip == fwd`
if real_ip != x_real_ip {
line.add_marker("ip!=fwd")?;
}

let response_time_in_ms = self.duration.as_millis();
if !is_download_redirect || response_time_in_ms > 0 {
line.add_field("service", format!("{response_time_in_ms}ms"))?;
Expand Down