Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

fix: Preserve protocol in url proxy to connect to http/https. Display warning if https target is viewed over http

reger206883f80d81
diff --git a/source/net/yacy/cora/protocol/HeaderFramework.java b/source/net/yacy/cora/protocol/HeaderFramework.java
index 9329c74a2..d4f56850a 100644
--- a/source/net/yacy/cora/protocol/HeaderFramework.java
+++ b/source/net/yacy/cora/protocol/HeaderFramework.java
@@ -195,6 +195,7 @@ public class HeaderFramework extends TreeMap<String, String> implements Map<Stri
/* PROPERTIES: General properties */
public static final String CONNECTION_PROP_HTTP_VER = "HTTP";
+ public static final String CONNECTION_PROP_PROTOCOL = "PROTOCOL";
public static final String CONNECTION_PROP_HOST = "HOST";
public static final String CONNECTION_PROP_USER = "USER";
public static final String CONNECTION_PROP_METHOD = "METHOD";
@@ -567,21 +568,29 @@ public class HeaderFramework extends TreeMap<String, String> implements Map<Stri
theHeader.append("\r\n");
}
+ /**
+ * Generate a url from Header properties
+ * @param conProp containing host, path, query and protocol (defaults to http if missing)
+ * @return url
+ * @throws MalformedURLException
+ */
public static DigestURL getRequestURL(final HashMap<String, Object> conProp) throws MalformedURLException {
String host = (String) conProp.get(HeaderFramework.CONNECTION_PROP_HOST);
final String path = (String) conProp.get(HeaderFramework.CONNECTION_PROP_PATH); // always starts with leading '/'
final String args = (String) conProp.get(HeaderFramework.CONNECTION_PROP_ARGS); // may be null if no args were given
+ String protocol = (String) conProp.get(HeaderFramework.CONNECTION_PROP_PROTOCOL);
+ if (protocol == null) protocol = "http";
//String ip = conProp.getProperty(httpHeader.CONNECTION_PROP_CLIENTIP); // the ip from the connecting peer
int port, pos;
if ((pos = host.lastIndexOf(':')) < 0 || host.charAt(pos - 1) != ']') {
- port = 80;
+ port = Domains.stripToPort(protocol + "://" + host); // use stripToPort to get default ports
} else {
port = NumberTools.parseIntDecSubstring(host, pos + 1);
host = host.substring(0, pos);
}
- final DigestURL url = new DigestURL("http", host, port, (args == null) ? path : path + "?" + args);
+ final DigestURL url = new DigestURL(protocol, host, port, (args == null) ? path : path + "?" + args);
return url;
}
diff --git a/source/net/yacy/http/servlets/UrlProxyServlet.java b/source/net/yacy/http/servlets/UrlProxyServlet.java
index 6556aeac8..ad4c8cd17 100644
--- a/source/net/yacy/http/servlets/UrlProxyServlet.java
+++ b/source/net/yacy/http/servlets/UrlProxyServlet.java
@@ -154,6 +154,7 @@ public class UrlProxyServlet extends ProxyServlet implements Servlet {
final HashMap<String, Object> prop = new HashMap<String, Object>();
prop.put(HeaderFramework.CONNECTION_PROP_HTTP_VER, HeaderFramework.HTTP_VERSION_1_1);
+ prop.put(HeaderFramework.CONNECTION_PROP_PROTOCOL, proxyurl.getProtocol());
prop.put(HeaderFramework.CONNECTION_PROP_HOST, hostwithport);
prop.put(HeaderFramework.CONNECTION_PROP_PATH, proxyurl.getPath().replaceAll(" ", "%20"));
prop.put(HeaderFramework.CONNECTION_PROP_METHOD, request.getMethod()); // only needed for HTTPDeamon errormsg in case of blacklisted url
@@ -253,8 +254,11 @@ public class UrlProxyServlet extends ProxyServlet implements Servlet {
// 8 - add interaction elements (e.g. proxy exit button to switch back to original url)
// TODO: use a template file for
if (_stopProxyText != null) {
+ String httpsAllertMsg = "";
+ if (proxyurl.getProtocol().equalsIgnoreCase("https") && !request.getScheme().equalsIgnoreCase("https")) httpsAllertMsg = " &nbsp; - <span style='color:red'>(Warning: secure target viewed over normal http)</span>";
bde.prepend("<div width='100%' style='padding:5px; background:white; border-bottom: medium solid lightgrey;'>"
- + "<div align='center' style='font-size:11px; color:darkgrey;'><a href='" + proxyurl + "'>" + _stopProxyText + "</a></div></div>");
+ + "<div align='center' style='font-size:11px; color:darkgrey;'><a href='" + proxyurl + "'>" + _stopProxyText + "</a> "
+ + httpsAllertMsg + "</div></div>");
}
// 9 - deliver to client
diff --git a/source/net/yacy/http/servlets/YaCyProxyServlet.java b/source/net/yacy/http/servlets/YaCyProxyServlet.java
index d13b96798..fed2e3da5 100644
--- a/source/net/yacy/http/servlets/YaCyProxyServlet.java
+++ b/source/net/yacy/http/servlets/YaCyProxyServlet.java
@@ -122,6 +122,7 @@ public class YaCyProxyServlet extends ProxyServlet implements Servlet {
final HashMap<String, Object> prop = new HashMap<String, Object>();
prop.put(HeaderFramework.CONNECTION_PROP_HTTP_VER, HeaderFramework.HTTP_VERSION_1_1);
+ prop.put(HeaderFramework.CONNECTION_PROP_PROTOCOL, proxyurl.getProtocol());
prop.put(HeaderFramework.CONNECTION_PROP_HOST, hostwithport);
prop.put(HeaderFramework.CONNECTION_PROP_PATH, proxyurl.getPath().replaceAll(" ", "%20"));
prop.put(HeaderFramework.CONNECTION_PROP_CLIENTIP, Domains.LOCALHOST);
diff --git a/source/net/yacy/server/http/HTTPDProxyHandler.java b/source/net/yacy/server/http/HTTPDProxyHandler.java
index 026eb9183..fe46a700e 100644
--- a/source/net/yacy/server/http/HTTPDProxyHandler.java
+++ b/source/net/yacy/server/http/HTTPDProxyHandler.java
@@ -408,14 +408,12 @@ public final class HTTPDProxyHandler {
try {
final int reqID = requestHeader.hashCode();
- String host = (String) conProp.get(HeaderFramework.CONNECTION_PROP_HOST);
- String path = (String) conProp.get(HeaderFramework.CONNECTION_PROP_PATH); // always starts with leading '/'
- final String args = (String) conProp.get(HeaderFramework.CONNECTION_PROP_ARGS); // may be null if no args were given
+ final String host = url.getHost(); // conProp.get(HeaderFramework.CONNECTION_PROP_HOST);
+ final String path = url.getPath(); // conProp.get(HeaderFramework.CONNECTION_PROP_PATH); // always starts with leading '/'
+ final String args = url.getSearchpart(); // conProp.get(HeaderFramework.CONNECTION_PROP_ARGS); // may be null if no args were given
final String ip = (String) conProp.get(HeaderFramework.CONNECTION_PROP_CLIENTIP); // the ip from the connecting peer
final String httpVer = (String) conProp.get(HeaderFramework.CONNECTION_PROP_HTTP_VER); // the ip from the connecting peer
-
- int port = Domains.stripToPort(host);
- host = Domains.stripToHostName(host);
+ final int port = url.getPort();
// resolve yacy and yacyh domains
String yAddress = resolveYacyDomains(host);
@@ -432,7 +430,7 @@ public final class HTTPDProxyHandler {
modifyProxyHeaders(requestHeader, httpVer);
final String connectHost = hostPart(host, port, yAddress);
- final String getUrl = "http://"+ connectHost + remotePath;
+ final String getUrl = url.getProtocol() +"://"+ connectHost + remotePath;
requestHeader.remove(HeaderFramework.HOST);