From aaf8fff57e85a8f164c4ab27c5e126e91a81027f Mon Sep 17 00:00:00 2001 From: Dr Scofield Date: Mon, 7 Jul 2008 11:25:09 +0000 Subject: [PATCH] adding support for IP EndPoint whitelisting in HttpServer code. --- OpenSim/Framework/Servers/OSHttpRequest.cs | 23 ++++++++++++++----- .../Framework/Servers/OSHttpRequestPump.cs | 11 +++++---- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/OpenSim/Framework/Servers/OSHttpRequest.cs b/OpenSim/Framework/Servers/OSHttpRequest.cs index f8f542bcb2..c5231431ab 100644 --- a/OpenSim/Framework/Servers/OSHttpRequest.cs +++ b/OpenSim/Framework/Servers/OSHttpRequest.cs @@ -56,6 +56,7 @@ namespace OpenSim.Framework.Servers private Uri _url; private NameValueCollection _queryString; private string _userAgent; + private IPEndPoint _ipEndPoint; private HttpRequest _request; // private HttpClientContext _context; @@ -146,6 +147,11 @@ namespace OpenSim.Framework.Servers get { return _queryString; } } + public IPEndPoint RemoteIPEndPoint + { + get { return _ipEndPoint; } + } + public HttpRequest HttpRequest { get { return _request; } @@ -161,18 +167,20 @@ namespace OpenSim.Framework.Servers _contentEncoding = req.ContentEncoding; _contentLength64 = req.ContentLength64; _contentType = req.ContentType; - // _cookies = req.Cookies; _headers = req.Headers; _httpMethod = req.HttpMethod; _hasbody = req.HasEntityBody; _inputStream = req.InputStream; - // _isSecureConnection = req.IsSecureConnection; - // _isAuthenticated = req.IsAuthenticated; _keepAlive = req.KeepAlive; _rawUrl = req.RawUrl; _url = req.Url; _queryString = req.QueryString; _userAgent = req.UserAgent; + _ipEndPoint = req.RemoteEndPoint; + + // _cookies = req.Cookies; + // _isSecureConnection = req.IsSecureConnection; + // _isAuthenticated = req.IsAuthenticated; } public OSHttpRequest(HttpClientContext context, HttpRequest req) @@ -186,13 +194,10 @@ namespace OpenSim.Framework.Servers _contentLength64 = req.ContentLength; if (null != req.Headers["content-type"]) _contentType = _request.Headers["content-type"]; - // _cookies = req.Cookies; _headers = req.Headers; _httpMethod = req.Method; _hasbody = req.ContentLength != 0; _inputStream = req.Body; - // _isSecureConnection = req.IsSecureConnection; - // _isAuthenticated = req.IsAuthenticated; _keepAlive = ConnectionType.KeepAlive == req.Connection; _rawUrl = req.Uri.AbsolutePath; _url = req.Uri; @@ -203,6 +208,12 @@ namespace OpenSim.Framework.Servers { _queryString.Add(q.Key, q.Value.Value); } + // TODO: requires change to HttpServer.HttpRequest + _ipEndPoint = null; + + // _cookies = req.Cookies; + // _isSecureConnection = req.IsSecureConnection; + // _isAuthenticated = req.IsAuthenticated; } } } diff --git a/OpenSim/Framework/Servers/OSHttpRequestPump.cs b/OpenSim/Framework/Servers/OSHttpRequestPump.cs index b76fadc7d0..4218be582c 100644 --- a/OpenSim/Framework/Servers/OSHttpRequestPump.cs +++ b/OpenSim/Framework/Servers/OSHttpRequestPump.cs @@ -165,11 +165,14 @@ namespace OpenSim.Framework.Servers if (null != endPointsRegex) { // TODO: following code requires code changes to - // HttpServer.HttpRequest + // HttpServer.HttpRequest to become functional - // IPEndPoint remote = HttpServer.HttpRequest.RemoteIPEndPoint; - // Match epm = endPointsRegex.Match(remote.ToString()); - // if (!epm.Success) continue; + IPEndPoint remote = req.RemoteIPEndPoint; + if (null != remote) + { + Match epm = endPointsRegex.Match(remote.ToString()); + if (!epm.Success) continue; + } } // whitelist ok, now check path