Commit e06d98d6 authored by Luca Morandini's avatar Luca Morandini Committed by Andrea Aime
Browse files

[GEOS-8933] Requesting workspaces triggers an NPE when proxy headers

            are used for the proxy URL

- Added a guard to avoid proxying an URL when it does not come from the
  OWS Dispatcher.
parent 4fa408a1
......@@ -123,6 +123,11 @@ public class ProxifyingURLMangler implements URLMangler {
*/
private StringBuilder mangleURLHeaders(StringBuilder baseURL, String proxyBase) {
// If the request is not an OWS request, does not proxy the URL
if (Dispatcher.REQUEST.get() == null) {
return baseURL;
}
// If the proxy base URL does not contain templates, fall back to
// the fixed URL cse
if (!proxyBase.contains(TEMPLATE_PREFIX)) {
......
......@@ -13,6 +13,8 @@ import java.util.Collections;
import org.geoserver.catalog.Catalog;
import org.geoserver.catalog.LayerGroupInfo;
import org.geoserver.catalog.StyleInfo;
import org.geoserver.config.GeoServerInfo;
import org.geoserver.config.SettingsInfo;
import org.geoserver.data.test.SystemTestData;
import org.geoserver.rest.RestBaseController;
import org.geoserver.security.AccessMode;
......@@ -112,6 +114,36 @@ public class AdminRequestTest extends CatalogRESTTestSupport {
assertEquals(1, dom.getElementsByTagName("workspace").getLength());
}
@Test
public void testWorkspacesWithProxyHeaders() throws Exception {
GeoServerInfo ginfo = getGeoServer().getGlobal();
SettingsInfo settings = getGeoServer().getGlobal().getSettings();
ginfo.setUseHeadersProxyURL(true);
settings.setProxyBaseUrl(
"${X-Forwarded-Proto}://${X-Forwarded-Host}/${X-Forwarded-Path} ${X-Forwarded-Proto}://${X-Forwarded-Host}");
ginfo.setSettings(settings);
getGeoServer().save(ginfo);
assertEquals(
200,
getAsServletResponse(RestBaseController.ROOT_PATH + "/workspaces.xml").getStatus());
Document dom = getAsDOM(RestBaseController.ROOT_PATH + "/workspaces.xml");
assertEquals(0, dom.getElementsByTagName("workspace").getLength());
super.login();
dom = getAsDOM(RestBaseController.ROOT_PATH + "/workspaces.xml");
assertEquals(
getCatalog().getWorkspaces().size(),
dom.getElementsByTagName("workspace").getLength());
assertEquals(
200,
getAsServletResponse(RestBaseController.ROOT_PATH + "/workspaces.xml").getStatus());
dom = getAsDOM(RestBaseController.ROOT_PATH + "/workspaces.xml");
assertEquals(
getCatalog().getWorkspaces().size(),
dom.getElementsByTagName("workspace").getLength());
}
@Test
public void testWorkspace() throws Exception {
assertEquals(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment