From 5edff904feef6405ee97c0bddfaa37e722e580f0 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Wed, 1 Apr 2020 15:15:45 +0200 Subject: [PATCH 1/2] Fixes #4735 - Get env variables in PHP scripts served through FastCGIProxyServlet. Introduced fastCGI.envNames to specify a comma separated list of environment variable names that are forwarded to the PHP process. Signed-off-by: Simone Bordet --- jetty-fcgi/fcgi-server/pom.xml | 7 ++---- .../server/proxy/FastCGIProxyServlet.java | 25 ++++++++++++++++++- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/jetty-fcgi/fcgi-server/pom.xml b/jetty-fcgi/fcgi-server/pom.xml index 3fea6cd08de..add0f2a11d0 100644 --- a/jetty-fcgi/fcgi-server/pom.xml +++ b/jetty-fcgi/fcgi-server/pom.xml @@ -14,10 +14,6 @@ ${project.groupId}.server - - - - javax.servlet @@ -38,6 +34,7 @@ jetty-server ${project.version} + org.eclipse.jetty jetty-servlet @@ -52,7 +49,7 @@ org.eclipse.jetty - jetty-alpn-server + jetty-alpn-java-server ${project.version} test diff --git a/jetty-fcgi/fcgi-server/src/main/java/org/eclipse/jetty/fcgi/server/proxy/FastCGIProxyServlet.java b/jetty-fcgi/fcgi-server/src/main/java/org/eclipse/jetty/fcgi/server/proxy/FastCGIProxyServlet.java index fe3c0e19171..6422245d95e 100644 --- a/jetty-fcgi/fcgi-server/src/main/java/org/eclipse/jetty/fcgi/server/proxy/FastCGIProxyServlet.java +++ b/jetty-fcgi/fcgi-server/src/main/java/org/eclipse/jetty/fcgi/server/proxy/FastCGIProxyServlet.java @@ -19,11 +19,14 @@ package org.eclipse.jetty.fcgi.server.proxy; import java.net.URI; +import java.util.Collections; import java.util.List; +import java.util.Set; import java.util.TreeMap; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; +import java.util.stream.Stream; import javax.servlet.RequestDispatcher; import javax.servlet.ServletConfig; import javax.servlet.ServletException; @@ -48,7 +51,7 @@ import org.eclipse.jetty.util.ProcessorUtils; * that is sent to the FastCGI server specified in the {@code proxyTo} * init-param. *

- * This servlet accepts two additional init-params: + * This servlet accepts these additional {@code init-param}s: *

    *
  • {@code scriptRoot}, mandatory, that must be set to the directory where * the application that must be served via FastCGI is installed and corresponds to @@ -62,6 +65,8 @@ import org.eclipse.jetty.util.ProcessorUtils; *
*
  • {@code fastCGI.HTTPS}, optional, defaults to false, that specifies whether * to force the FastCGI {@code HTTPS} parameter to the value {@code on}
  • + *
  • {@code fastCGI.envNames}, optional, a comma separated list of environment variable + * names read via {@link System#getenv(String)} that are forwarded as FastCGI parameters.
  • * * * @see TryFilesFilter @@ -73,6 +78,7 @@ public class FastCGIProxyServlet extends AsyncProxyServlet.Transparent public static final String ORIGINAL_URI_ATTRIBUTE_INIT_PARAM = "originalURIAttribute"; public static final String ORIGINAL_QUERY_ATTRIBUTE_INIT_PARAM = "originalQueryAttribute"; public static final String FASTCGI_HTTPS_INIT_PARAM = "fastCGI.HTTPS"; + public static final String FASTCGI_ENV_NAMES_INIT_PARAM = "fastCGI.envNames"; private static final String REMOTE_ADDR_ATTRIBUTE = FastCGIProxyServlet.class.getName() + ".remoteAddr"; private static final String REMOTE_PORT_ATTRIBUTE = FastCGIProxyServlet.class.getName() + ".remotePort"; @@ -87,6 +93,7 @@ public class FastCGIProxyServlet extends AsyncProxyServlet.Transparent private String originalURIAttribute; private String originalQueryAttribute; private boolean fcgiHTTPS; + private Set fcgiEnvNames; @Override public void init() throws ServletException @@ -102,6 +109,15 @@ public class FastCGIProxyServlet extends AsyncProxyServlet.Transparent originalQueryAttribute = getInitParameter(ORIGINAL_QUERY_ATTRIBUTE_INIT_PARAM); fcgiHTTPS = Boolean.parseBoolean(getInitParameter(FASTCGI_HTTPS_INIT_PARAM)); + + fcgiEnvNames = Collections.emptySet(); + String envNames = getInitParameter(FASTCGI_ENV_NAMES_INIT_PARAM); + if (envNames != null) + { + fcgiEnvNames = Stream.of(envNames.split(",")) + .map(String::trim) + .collect(Collectors.toSet()); + } } @Override @@ -195,6 +211,13 @@ public class FastCGIProxyServlet extends AsyncProxyServlet.Transparent protected void customizeFastCGIHeaders(Request proxyRequest, HttpFields fastCGIHeaders) { + for (String envName : fcgiEnvNames) + { + String envValue = System.getenv(envName); + if (envValue != null) + fastCGIHeaders.put(envName, envValue); + } + fastCGIHeaders.remove("HTTP_PROXY"); fastCGIHeaders.put(FCGI.Headers.REMOTE_ADDR, (String)proxyRequest.getAttributes().get(REMOTE_ADDR_ATTRIBUTE)); From ed675b03cd1c1b8b515d16b4e8e9e13cb165b9b1 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Wed, 1 Apr 2020 18:41:25 +0200 Subject: [PATCH 2/2] Fixes #4735 - Get env variables in PHP scripts served through FastCGIProxyServlet. Fixed test dependency on ALPN. Signed-off-by: Simone Bordet --- jetty-fcgi/fcgi-server/pom.xml | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/jetty-fcgi/fcgi-server/pom.xml b/jetty-fcgi/fcgi-server/pom.xml index add0f2a11d0..e7df5968c92 100644 --- a/jetty-fcgi/fcgi-server/pom.xml +++ b/jetty-fcgi/fcgi-server/pom.xml @@ -14,6 +14,23 @@ ${project.groupId}.server + + + jdk9 + + [9,) + + + + org.eclipse.jetty + jetty-alpn-java-server + ${project.version} + test + + + + + javax.servlet @@ -49,7 +66,7 @@ org.eclipse.jetty - jetty-alpn-java-server + jetty-alpn-openjdk8-server ${project.version} test