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;
|
|
|
|
|
2019-01-08 16:36:05 +03:00
|
|
|
public final class EnvHelper {
|
2018-12-02 17:02:13 +03:00
|
|
|
public static final String[] toTest = {"_JAVA_OPTIONS", "_JAVA_OPTS", "JAVA_OPTS", "JAVA_OPTIONS"};
|
2018-09-17 10:07:32 +03:00
|
|
|
|
2018-11-08 15:30:16 +03:00
|
|
|
public static void addEnv(ProcessBuilder builder) {
|
|
|
|
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-09-17 10:07:32 +03:00
|
|
|
|
2018-11-08 15:30:16 +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"))
|
|
|
|
throw new SecurityException("JavaAgent in global options not allow");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-17 10:07:32 +03:00
|
|
|
}
|