From 479d72ac975fd34f43d76c0ab20f869cb07fb6fc Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Mon, 17 Jan 2011 11:37:39 -0800 Subject: Account for some component along the way lower-casing the HTTP header keys. (XFF header issue) --- .../Server/Handlers/Hypergrid/HomeAgentHandlers.cs | 21 ++++++++++++-------- .../Server/Handlers/Simulation/AgentHandlers.cs | 23 ++++++++++------------ 2 files changed, 23 insertions(+), 21 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs b/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs index 814a8d9..968c1e6 100644 --- a/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs +++ b/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs @@ -215,16 +215,21 @@ namespace OpenSim.Server.Handlers.Hypergrid // We're behind a proxy Hashtable headers = (Hashtable)request["headers"]; - if (headers.ContainsKey("X-Forwarded-For") && headers["X-Forwarded-For"] != null) - { - m_log.DebugFormat("[HOME AGENT HANDLER]: XFF is {0}", headers["X-Forwarded-For"]); + string xff = "X-Forwarded-For"; + if (headers.ContainsKey(xff.ToLower())) + xff = xff.ToLower(); - IPEndPoint ep = Util.GetClientIPFromXFF((string)headers["X-Forwarded-For"]); - if (ep != null) - return ep.Address.ToString(); + if (!headers.ContainsKey(xff) || headers[xff] == null) + { + m_log.WarnFormat("[AGENT HANDLER]: No XFF header"); + return Util.GetCallerIP(request); } - else - m_log.WarnFormat("[HOME AGENT HANDLER]: No XFF header"); + + m_log.DebugFormat("[AGENT HANDLER]: XFF is {0}", headers[xff]); + + IPEndPoint ep = Util.GetClientIPFromXFF((string)headers[xff]); + if (ep != null) + return ep.Address.ToString(); // Oops return Util.GetCallerIP(request); diff --git a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs index 96821ec..57672a8 100644 --- a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs +++ b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs @@ -200,24 +200,21 @@ namespace OpenSim.Server.Handlers.Simulation // We're behind a proxy Hashtable headers = (Hashtable)request["headers"]; + string xff = "X-Forwarded-For"; + if (headers.ContainsKey(xff.ToLower())) + xff = xff.ToLower(); - foreach (object o in headers.Keys) + if (!headers.ContainsKey(xff) || headers[xff] == null) { - if (o != null) - m_log.DebugFormat("[XXX] {0}", o.ToString()); + m_log.WarnFormat("[AGENT HANDLER]: No XFF header"); + return Util.GetCallerIP(request); } - if (headers.ContainsKey("X-Forwarded-For") && headers["X-Forwarded-For"] != null) - { - m_log.DebugFormat("[AGENT HANDLER]: XFF is {0}", headers["X-Forwarded-For"]); - - IPEndPoint ep = Util.GetClientIPFromXFF((string)headers["X-Forwarded-For"]); - if (ep != null) - return ep.Address.ToString(); - } - else - m_log.WarnFormat("[AGENT HANDLER]: No XFF header"); + m_log.DebugFormat("[AGENT HANDLER]: XFF is {0}", headers[xff]); + IPEndPoint ep = Util.GetClientIPFromXFF((string)headers[xff]); + if (ep != null) + return ep.Address.ToString(); // Oops return Util.GetCallerIP(request); -- cgit v1.1