(more!) evaluation of XRealIP from nginx reverse proxy

pull/149/head
Michael Peter Christen 7 years ago
parent 30d71c6359
commit 4355de0f3c

@ -208,8 +208,12 @@ public class yacysearchitem {
prop.putXML("content_image_url", faviconURL.toNormalform(true)); prop.putXML("content_image_url", faviconURL.toNormalform(true));
} }
} else { } else {
prop.put("content_image", 1); try {
prop.putXML("content_image_url", result.imageURL()); prop.putXML("content_image_url", result.imageURL());
prop.put("content_image", 1);
} catch (UnsupportedOperationException e) {
prop.put("content_image", 0);
}
} }
prop.put("content_urlhash", urlhash); prop.put("content_urlhash", urlhash);

@ -725,11 +725,20 @@ public class RequestHeader extends HeaderFramework implements HttpServletRequest
@Override @Override
public String getRemoteHost() { public String getRemoteHost() {
if (_request != null) { if (_request != null) {
return _request.getRemoteHost(); return host(_request);
} }
throw new UnsupportedOperationException("Not supported yet."); throw new UnsupportedOperationException("Not supported yet.");
} }
public static String host(final ServletRequest request) {
String clientHost = request.getRemoteHost();
if (request instanceof HttpServletRequest) {
String XRealIP = ((HttpServletRequest) request).getHeader(X_Real_IP);
if (XRealIP != null && XRealIP.length() > 0) clientHost = XRealIP; // get IP through nginx config "proxy_set_header X-Real-IP $remote_addr;"
}
return clientHost;
}
@Override @Override
public void setAttribute(String name, Object o) { public void setAttribute(String name, Object o) {
if (_request != null) { if (_request != null) {

@ -64,7 +64,7 @@ public class Jetty9YaCySecurityHandler extends ConstraintSecurityHandler {
String refererHost; String refererHost;
// update AccessTracker // update AccessTracker
final String remoteip = request.getRemoteAddr(); final String remoteip = RequestHeader.client(request);
serverAccessTracker.track(remoteip, pathInContext); serverAccessTracker.track(remoteip, pathInContext);
try { try {

@ -32,6 +32,7 @@ import javax.servlet.http.HttpServletResponse;
import net.yacy.cora.protocol.ConnectionInfo; import net.yacy.cora.protocol.ConnectionInfo;
import net.yacy.cora.protocol.Domains; import net.yacy.cora.protocol.Domains;
import net.yacy.cora.protocol.RequestHeader;
import org.eclipse.jetty.io.Connection; import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Request;
@ -58,7 +59,7 @@ public class MonitorHandler extends AbstractHandler {
final Connection connection = baseRequest.getHttpChannel().getEndPoint().getConnection(); final Connection connection = baseRequest.getHttpChannel().getEndPoint().getConnection();
final ConnectionInfo info = new ConnectionInfo( final ConnectionInfo info = new ConnectionInfo(
baseRequest.getScheme(), baseRequest.getScheme(),
baseRequest.getRemoteAddr() + ":" + baseRequest.getRemotePort(), RequestHeader.client(baseRequest) + ":" + baseRequest.getRemotePort(),
baseRequest.getMethod() + " " + baseRequest.getHttpURI().getPathQuery(), baseRequest.getMethod() + " " + baseRequest.getHttpURI().getPathQuery(),
connection.hashCode(), connection.hashCode(),
baseRequest.getTimeStamp(), baseRequest.getTimeStamp(),

@ -42,6 +42,7 @@ import net.yacy.cora.federate.solr.Ranking;
import net.yacy.cora.federate.solr.connector.EmbeddedSolrConnector; import net.yacy.cora.federate.solr.connector.EmbeddedSolrConnector;
import net.yacy.cora.federate.solr.responsewriter.GSAResponseWriter; import net.yacy.cora.federate.solr.responsewriter.GSAResponseWriter;
import net.yacy.cora.protocol.HeaderFramework; import net.yacy.cora.protocol.HeaderFramework;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.cora.util.ConcurrentLog; import net.yacy.cora.util.ConcurrentLog;
import net.yacy.data.UserDB; import net.yacy.data.UserDB;
import net.yacy.search.Switchboard; import net.yacy.search.Switchboard;
@ -102,7 +103,7 @@ public class GSAsearchServlet extends HttpServlet {
private void respond(final HttpServletRequest header, final Switchboard sb, final OutputStream out) { private void respond(final HttpServletRequest header, final Switchboard sb, final OutputStream out) {
// remember the peer contact for peer statistics // remember the peer contact for peer statistics
String clientip = header.getRemoteAddr(); String clientip = RequestHeader.client(header);
if (clientip == null) clientip = "<unknown>"; // read an artificial header addendum if (clientip == null) clientip = "<unknown>"; // read an artificial header addendum
String userAgent = header.getHeader(HeaderFramework.USER_AGENT); String userAgent = header.getHeader(HeaderFramework.USER_AGENT);
if (userAgent == null) userAgent = "<unknown>"; if (userAgent == null) userAgent = "<unknown>";

@ -102,7 +102,7 @@ public class UrlProxyServlet extends HttpServlet implements Servlet {
return; return;
} }
final String remoteHost = req.getRemoteHost(); final String remoteHost = req.getRemoteAddr();
if (!Domains.isThisHostIP(remoteHost)) { if (!Domains.isThisHostIP(remoteHost)) {
if (!proxyippatternmatch(remoteHost)) { if (!proxyippatternmatch(remoteHost)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN, response.sendError(HttpServletResponse.SC_FORBIDDEN,

@ -40,7 +40,7 @@ public class YaCyQoSFilter extends QoSFilter {
protected int getPriority(ServletRequest request) { protected int getPriority(ServletRequest request) {
if (request.getServerName().equalsIgnoreCase(Domains.LOCALHOST)) { if (request.getServerName().equalsIgnoreCase(Domains.LOCALHOST)) {
return 10; // highest priority for "localhost" return 10; // highest priority for "localhost"
} else if (Domains.isLocalhost(request.getRemoteHost())) { } else if (Domains.isLocalhost(request.getRemoteAddr())) {
return 9; return 9;
} else { } else {
return super.getPriority(request); // standard: authenticated = 2, other = 1 or 0 return super.getPriority(request); // standard: authenticated = 2, other = 1 or 0

Loading…
Cancel
Save