Add support for using X-Forwarded-From for better proxy IP handling on

webchat
This commit is contained in:
Mike Primm 2011-06-12 18:50:41 -07:00
parent 397f97800c
commit 40ee132277

View File

@ -41,7 +41,13 @@ public class SendMessageHandler implements HttpHandler {
JSONObject o = (JSONObject)parser.parse(reader); JSONObject o = (JSONObject)parser.parse(reader);
final Message message = new Message(); final Message message = new Message();
//message.name = String.valueOf(o.get("name")); //Can't trust client....we don't need to on internal web server /* If proxied client address, get original */
if(request.fields.containsKey("X-Forwarded-For"))
message.name = request.fields.get("X-Forwarded-For");
/* If from loopback, we're probably getting from proxy - need to trust client */
else if(request.rmtaddr.getAddress().isLoopbackAddress())
message.name = String.valueOf(o.get("name"));
else
message.name = request.rmtaddr.getAddress().getHostAddress(); message.name = request.rmtaddr.getAddress().getHostAddress();
message.message = String.valueOf(o.get("message")); message.message = String.valueOf(o.get("message"));