- java.lang.Object
-
- io.github.pixee.security.SystemCommand
-
public final class SystemCommand extends java.lang.ObjectThis type offers utility methods to run system commands more safely.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.Set<SystemCommandRestrictions>defaultRestrictions()The default restrictions if none are specified.static java.lang.ProcessrunCommand(java.lang.Runtime runtime, java.lang.String command)Delegates torunCommand(Runtime, String, Set)with default restrictions.static java.lang.ProcessrunCommand(java.lang.Runtime runtime, java.lang.String[] command)Delegates torunCommand(Runtime, String[], Set)with default restrictions.static java.lang.ProcessrunCommand(java.lang.Runtime runtime, java.lang.String[] command, java.lang.String[] envp)Delegates torunCommand(Runtime, String[], String[], Set)with default restrictions.static java.lang.ProcessrunCommand(java.lang.Runtime runtime, java.lang.String[] command, java.lang.String[] envp, java.io.File dir)Delegates torunCommand(Runtime, String[], String[], File, Set)with default restrictions.static java.lang.ProcessrunCommand(java.lang.Runtime runtime, java.lang.String[] command, java.lang.String[] envp, java.io.File dir, java.util.Set<SystemCommandRestrictions> restrictions)Same asrunCommand(Runtime, String[], Set)but also include more data to pass intoRuntime.exec(String[], String[], File).static java.lang.ProcessrunCommand(java.lang.Runtime runtime, java.lang.String[] command, java.lang.String[] envp, java.util.Set<SystemCommandRestrictions> restrictions)Same asrunCommand(Runtime, String[], Set)but also include more data to pass intoRuntime.exec(String[], String[]).static java.lang.ProcessrunCommand(java.lang.Runtime runtime, java.lang.String[] command, java.util.Set<SystemCommandRestrictions> restrictions)Does the same asRuntime.exec(String[]), but adds restrictions on what types of commands will be allowed.static java.lang.ProcessrunCommand(java.lang.Runtime runtime, java.lang.String command, java.lang.String[] envp)Delegates torunCommand(Runtime, String, String[], Set)with default restrictions.static java.lang.ProcessrunCommand(java.lang.Runtime runtime, java.lang.String command, java.lang.String[] envp, java.io.File dir)Delegates torunCommand(Runtime, String, String[], File, Set)with default restrictions.static java.lang.ProcessrunCommand(java.lang.Runtime runtime, java.lang.String command, java.lang.String[] envp, java.io.File dir, java.util.Set<SystemCommandRestrictions> restrictions)Same asrunCommand(Runtime, String, Set)but also include more data to pass intoRuntime.exec(String, String[], File).static java.lang.ProcessrunCommand(java.lang.Runtime runtime, java.lang.String command, java.lang.String[] envp, java.util.Set<SystemCommandRestrictions> restrictions)Same asrunCommand(Runtime, String, Set)but also include more data to pass intoRuntime.exec(String, String[]).static java.lang.ProcessrunCommand(java.lang.Runtime runtime, java.lang.String command, java.util.Set<SystemCommandRestrictions> restrictions)Does the same asRuntime.exec(String), but adds restrictions on what types of commands will be allowed.
-
-
-
Method Detail
-
defaultRestrictions
public static java.util.Set<SystemCommandRestrictions> defaultRestrictions()
The default restrictions if none are specified.- Returns:
- a set of restrictions suitable for general use
-
runCommand
public static java.lang.Process runCommand(java.lang.Runtime runtime, java.lang.String command, java.util.Set<SystemCommandRestrictions> restrictions) throws java.io.IOExceptionDoes the same asRuntime.exec(String), but adds restrictions on what types of commands will be allowed. Will throw aSecurityExceptionif any of the restrictions may be violated by the command found. Note that the method of detecting violations is based on semantic analysis of the command, and so is vulnerable to impedance mismatches between the analysis we perform and whatever shell is interpreting the command. Either way, it's a lot safer.- Parameters:
command- the system command about to be runruntime- the runtime to run withrestrictions- the set of restrictions to run with- Returns:
- the
Processthat results from the hardenedRuntime.exec(String)call - Throws:
java.lang.SecurityException- if multiple commands are foundjava.lang.IllegalArgumentException- if restriction is nulljava.io.IOException- from the wrapped system process invocation call
-
runCommand
public static java.lang.Process runCommand(java.lang.Runtime runtime, java.lang.String command) throws java.io.IOExceptionDelegates torunCommand(Runtime, String, Set)with default restrictions.- Parameters:
runtime- the runtime to run withcommand- the system command about to be run- Returns:
- the
Processthat results from the hardenedRuntime.exec(String)call - Throws:
java.io.IOException- from the wrapped system process invocation call
-
runCommand
public static java.lang.Process runCommand(java.lang.Runtime runtime, java.lang.String[] command, java.util.Set<SystemCommandRestrictions> restrictions) throws java.io.IOExceptionDoes the same asRuntime.exec(String[]), but adds restrictions on what types of commands will be allowed. Will throw aSecurityExceptionif any of the restrictions may be violated by the command found. Note that the method of detecting violations is based on semantic analysis of the command, and so is vulnerable to impedance mismatches between the analysis we perform and whatever shell is interpreting the command. Either way, it's a lot safer.- Parameters:
command- the system command about to be runruntime- the runtime to run withrestrictions- the set of restrictions to run with- Returns:
- the
Processthat results from the hardenedRuntime.exec(String[])call - Throws:
java.lang.SecurityException- if multiple commands are foundjava.lang.IllegalArgumentException- if restriction is nulljava.io.IOException- from the wrapped system process invocation call
-
runCommand
public static java.lang.Process runCommand(java.lang.Runtime runtime, java.lang.String[] command) throws java.io.IOExceptionDelegates torunCommand(Runtime, String[], Set)with default restrictions.- Parameters:
runtime- the runtime to run withcommand- the system command about to be run- Returns:
- the
Processthat results from the hardenedRuntime.exec(String[])call - Throws:
java.io.IOException- from the wrapped system process invocation call
-
runCommand
public static java.lang.Process runCommand(java.lang.Runtime runtime, java.lang.String[] command, java.lang.String[] envp, java.util.Set<SystemCommandRestrictions> restrictions) throws java.io.IOExceptionSame asrunCommand(Runtime, String[], Set)but also include more data to pass intoRuntime.exec(String[], String[]).- Parameters:
runtime- the runtime to run withcommand- the system command about to be runenvp- the environment variablesrestrictions- the set of restrictions to run with- Returns:
- the
Processthat results from the hardenedRuntime.exec(String[])call - Throws:
java.lang.SecurityException- if multiple commands are foundjava.lang.IllegalArgumentException- if restriction is nulljava.io.IOException- from the wrapped system process invocation call
-
runCommand
public static java.lang.Process runCommand(java.lang.Runtime runtime, java.lang.String[] command, java.lang.String[] envp) throws java.io.IOExceptionDelegates torunCommand(Runtime, String[], String[], Set)with default restrictions.- Parameters:
runtime- the runtime to run withcommand- the system command about to be runenvp- the environment variables- Returns:
- the
Processthat results from the hardenedRuntime.exec(String[], String[])call - Throws:
java.io.IOException- from the wrapped system process invocation call
-
runCommand
public static java.lang.Process runCommand(java.lang.Runtime runtime, java.lang.String[] command, java.lang.String[] envp, java.io.File dir, java.util.Set<SystemCommandRestrictions> restrictions) throws java.io.IOExceptionSame asrunCommand(Runtime, String[], Set)but also include more data to pass intoRuntime.exec(String[], String[], File).- Parameters:
runtime- the runtime to run withcommand- the system command about to be runenvp- the environment variablesdir- the working directory to run the system command inrestrictions- the set of restrictions to run with- Returns:
- the
Processthat results from the hardenedRuntime.exec(String[], String[], File)call - Throws:
java.io.IOException- from the wrapped system process invocation call
-
runCommand
public static java.lang.Process runCommand(java.lang.Runtime runtime, java.lang.String command, java.lang.String[] envp, java.util.Set<SystemCommandRestrictions> restrictions) throws java.io.IOExceptionSame asrunCommand(Runtime, String, Set)but also include more data to pass intoRuntime.exec(String, String[]).- Parameters:
runtime- the runtime to run withcommand- the system command about to be runenvp- the environment variablesrestrictions- the set of restrictions to run with- Returns:
- the
Processthat results from the hardenedRuntime.exec(String, String[])call - Throws:
java.io.IOException- from the wrapped system process invocation call
-
runCommand
public static java.lang.Process runCommand(java.lang.Runtime runtime, java.lang.String command, java.lang.String[] envp) throws java.io.IOExceptionDelegates torunCommand(Runtime, String, String[], Set)with default restrictions.- Parameters:
runtime- the runtime to run withcommand- the system command about to be runenvp- the environment variables- Returns:
- the
Processthat results from the hardenedRuntime.exec(String, String[])call - Throws:
java.io.IOException- from the wrapped system process invocation call
-
runCommand
public static java.lang.Process runCommand(java.lang.Runtime runtime, java.lang.String command, java.lang.String[] envp, java.io.File dir, java.util.Set<SystemCommandRestrictions> restrictions) throws java.io.IOExceptionSame asrunCommand(Runtime, String, Set)but also include more data to pass intoRuntime.exec(String, String[], File).- Parameters:
runtime- the runtime to run withcommand- the system command about to be runenvp- the environment variablesdir- the working directory to run the system command inrestrictions- the set of restrictions to run with- Returns:
- the
Processthat results from the hardenedRuntime.exec(String, String[], File)call - Throws:
java.io.IOException- from the wrapped system process invocation call
-
runCommand
public static java.lang.Process runCommand(java.lang.Runtime runtime, java.lang.String command, java.lang.String[] envp, java.io.File dir) throws java.io.IOExceptionDelegates torunCommand(Runtime, String, String[], File, Set)with default restrictions.- Parameters:
runtime- the runtime to run withcommand- the system command about to be runenvp- the environment variablesdir- the working directory to run the system command in- Returns:
- the
Processthat results from the hardenedRuntime.exec(String, String[], File)call - Throws:
java.io.IOException- from the wrapped system process invocation call
-
runCommand
public static java.lang.Process runCommand(java.lang.Runtime runtime, java.lang.String[] command, java.lang.String[] envp, java.io.File dir) throws java.io.IOExceptionDelegates torunCommand(Runtime, String[], String[], File, Set)with default restrictions.- Parameters:
runtime- the runtime to run withcommand- the system command about to be runenvp- the environment variablesdir- the working directory to run the system command in- Returns:
- the
Processthat results from the hardenedRuntime.exec(String[], String[], File)call - Throws:
java.io.IOException- from the wrapped system process invocation call
-
-