Launcher/libLauncher/src/main/java/ru/gravit/utils/helper/EnvHelper.java

36 lines
961 B
Java
Raw Normal View History

2018-09-17 10:20:34 +03:00
package ru.gravit.utils.helper;
2018-09-17 10:07:32 +03:00
import java.util.Locale;
import java.util.Map;
public class EnvHelper {
2018-10-22 08:13:23 +03:00
public static final String[] toTest;
static {
toTest = new String[] { "_JAVA_OPTIONS", "_JAVA_OPTS", "JAVA_OPTS", "JAVA_OPTIONS" };
}
2018-09-17 10:07:32 +03:00
2018-10-22 08:13:23 +03:00
public static void addEnv(ProcessBuilder builder) {
2018-10-26 17:42:20 +03:00
Map<String, String> map = builder.environment();
for (String env : toTest) {
if(map.containsKey(env))
map.put(env, "");
String lower_env = env.toLowerCase(Locale.US);
if(map.containsKey(lower_env))
map.put(lower_env, "");
2018-10-22 08:13:23 +03:00
}
}
2018-09-17 10:07:32 +03:00
2018-10-26 17:42:20 +03:00
public static void checkDangerousParams() {
for (String t : toTest) {
String env = System.getenv(t);
if (env != null) {
env = env.toLowerCase(Locale.US);
if (env.contains("-cp") || env.contains("-classpath") || env.contains("-javaagent")
|| env.contains("-agentpath") || env.contains("-agentlib"))
2018-10-26 17:42:20 +03:00
throw new SecurityException("JavaAgent in global options not allow");
}
2018-10-26 17:42:20 +03:00
}
2018-10-22 08:13:23 +03:00
}
2018-09-17 10:07:32 +03:00
}