evaluate X-Forwarded-For header upon replica registration so as to obtain the true replica client IP address

This commit is contained in:
Axel Uhl committed 2020-03-05 15:45:44 +01:00
1 parent de2842e259
commit 2aa0848226
1 file changed
+6 -3
@@ -340,9 +340,12 @@ public class ReplicationServlet extends AbstractHttpServlet {
}
private ReplicaDescriptor getReplicaDescriptor(HttpServletRequest req) throws UnknownHostException {
InetAddress ipAddress = InetAddress.getByName(req.getRemoteAddr());
UUID uuid = UUID.fromString(req.getParameter(SERVER_UUID));
String additional = req.getParameter(ADDITIONAL_INFORMATION);
final String forwardedFor = req.getHeader("X-Forwarded-For"); // could have come through a load balancer / reverse proxy
final InetAddress ipAddress = forwardedFor != null && !forwardedFor.trim().isEmpty()
? InetAddress.getByName(forwardedFor)
: InetAddress.getByName(req.getRemoteAddr());
final UUID uuid = UUID.fromString(req.getParameter(SERVER_UUID));
final String additional = req.getParameter(ADDITIONAL_INFORMATION);
final String[] replicableIdsAsStrings = req.getParameter(REPLICABLES_IDS_AS_STRINGS_COMMA_SEPARATED).split(",");
return new ReplicaDescriptorImpl(ipAddress, uuid, additional, replicableIdsAsStrings);
}