From 265cca4003e9fcaaeb44a867eb9e4e0c6daf9f05 Mon Sep 17 00:00:00 2001 From: Shrikant Sharat Kandula Date: Wed, 15 Jun 2022 14:01:46 +0530 Subject: [PATCH] Proxy arguments so that they are not set when empty (#14508) --- deploy/docker/scripts/run-java.sh | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/deploy/docker/scripts/run-java.sh b/deploy/docker/scripts/run-java.sh index 11e8dabddc..60f986ff53 100755 --- a/deploy/docker/scripts/run-java.sh +++ b/deploy/docker/scripts/run-java.sh @@ -3,20 +3,19 @@ set -o errexit set -o pipefail set -o nounset +set -o noglob -http_proxy_host="" -http_proxy_port="" -https_proxy_host="" -https_proxy_port="" +declare -a proxy_args +proxy_configured=0 -if [[ ${HTTP_PROXY-} =~ ^http://(.*):(.*)$ ]]; then - http_proxy_host="${BASH_REMATCH[1]}" - http_proxy_port="${BASH_REMATCH[2]}" +if [[ ${HTTP_PROXY-} =~ ^http://(.*):(.*)$ && ${BASH_REMATCH[2]} != 0 ]]; then + proxy_args+=(-Dhttp.proxyHost="${BASH_REMATCH[1]}" -Dhttp.proxyPort="${BASH_REMATCH[2]}") + proxy_configured=1 fi -if [[ ${HTTPS_PROXY-} =~ ^http://(.*):(.*)$ ]]; then - https_proxy_host="${BASH_REMATCH[1]}" - https_proxy_port="${BASH_REMATCH[2]}" +if [[ ${HTTPS_PROXY-} =~ ^https?://(.*):(.*)$ && ${BASH_REMATCH[2]} != 0 ]]; then + proxy_args+=(-Dhttps.proxyHost="${BASH_REMATCH[1]}" -Dhttps.proxyPort="${BASH_REMATCH[2]}") + proxy_configured=1 fi if ! isset NO_PROXY; then @@ -24,15 +23,14 @@ if ! isset NO_PROXY; then NO_PROXY="" fi +if [[ $proxy_configured == 1 ]]; then + proxy_args+=(-Djava.net.useSystemProxies=true -Dhttp.nonProxyHosts="${NO_PROXY/,/|}") +fi + # Ref -Dlog4j2.formatMsgNoLookups=true https://spring.io/blog/2021/12/10/log4j2-vulnerability-and-spring-boot exec java ${APPSMITH_JAVA_ARGS:-} ${APPSMITH_JAVA_HEAP_ARG:-} \ -Dserver.port=8080 \ -Djava.security.egd=file:/dev/./urandom \ -Dlog4j2.formatMsgNoLookups=true \ - -Djava.net.useSystemProxies=true \ - -Dhttp.proxyHost="$http_proxy_host" \ - -Dhttp.proxyPort="$http_proxy_port" \ - -Dhttps.proxyHost="$https_proxy_host" \ - -Dhttps.proxyPort="$https_proxy_port" \ - -Dhttp.nonProxyHosts="${NO_PROXY/,/|}" \ + "${proxy_args[@]}" \ -jar server.jar