From 0dc7359431001c9ef1222913f8d1344093397596 Mon Sep 17 00:00:00 2001 From: Adam Cooke Date: Tue, 5 Mar 2024 22:11:59 +0000 Subject: [PATCH] fix(smtp-server): remove ::ffff: from the start of ipv4 addresses --- app/lib/smtp_server/server.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/lib/smtp_server/server.rb b/app/lib/smtp_server/server.rb index 9c865cd..da2c528 100644 --- a/app/lib/smtp_server/server.rb +++ b/app/lib/smtp_server/server.rb @@ -112,21 +112,23 @@ module SMTPServer # Accept the connection new_io = io.accept increment_prometheus_counter :postal_smtp_server_connections_total + # Get the client's IP address and strip `::ffff:` for consistency. + client_ip_address = new_io.remote_address.ip_address.sub(/\A::ffff:/, "") if Postal::Config.smtp_server.proxy_protocol? # If we are using the haproxy proxy protocol, we will be sent the # client's IP later. Delay the welcome process. client = Client.new(nil) if Postal::Config.smtp_server.log_connections? - client.logger&.debug "Connection opened from #{new_io.remote_address.ip_address}" + client.logger&.debug "Connection opened from #{client_ip_address}" end else # We're not using the proxy protocol so we already know the client's IP - client = Client.new(new_io.remote_address.ip_address) + client = Client.new(client_ip_address) if Postal::Config.smtp_server.log_connections? - client.logger&.debug "Connection opened from #{new_io.remote_address.ip_address}" + client.logger&.debug "Connection opened from #{client_ip_address}" end # We know who the client is, welcome them. - client.logger&.debug "Client identified as #{new_io.remote_address.ip_address}" + client.logger&.debug "Client identified as #{client_ip_address}" new_io.print("220 #{Postal::Config.postal.smtp_hostname} ESMTP Postal/#{client.trace_id}") end # Register the client and its socket with nio4r