- java.lang.Object
-
- io.github.pixee.security.SystemCommand
-
public final class SystemCommand extends java.lang.Object
This 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.Process
runCommand(java.lang.Runtime runtime, java.lang.String command)
Delegates torunCommand(Runtime, String, Set)
with default restrictions.static java.lang.Process
runCommand(java.lang.Runtime runtime, java.lang.String[] command)
Delegates torunCommand(Runtime, String[], Set)
with default restrictions.static java.lang.Process
runCommand(java.lang.Runtime runtime, java.lang.String[] command, java.lang.String[] envp)
Delegates torunCommand(Runtime, String[], String[], Set)
with default restrictions.static java.lang.Process
runCommand(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.Process
runCommand(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.Process
runCommand(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.Process
runCommand(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.Process
runCommand(java.lang.Runtime runtime, java.lang.String command, java.lang.String[] envp)
Delegates torunCommand(Runtime, String, String[], Set)
with default restrictions.static java.lang.Process
runCommand(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.Process
runCommand(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.Process
runCommand(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.Process
runCommand(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.Process
runProcessBuilder(java.lang.ProcessBuilder processBuilder)
Delegates torunProcessBuilder(ProcessBuilder, Set)
with default restrictions.static java.lang.Process
runProcessBuilder(java.lang.ProcessBuilder processBuilder, java.util.Set<SystemCommandRestrictions> restrictions)
Does the same asProcessBuilder.start()
, 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
-
runProcessBuilder
public static java.lang.Process runProcessBuilder(java.lang.ProcessBuilder processBuilder, java.util.Set<SystemCommandRestrictions> restrictions) throws java.io.IOException
Does the same asProcessBuilder.start()
, but adds restrictions on what types of commands will be allowed. Will throw aSecurityException
if 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:
processBuilder
- the system command about to be runrestrictions
- the set of restrictions to run with- Returns:
- the
Process
that results from the hardenedProcessBuilder.start()
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
-
runProcessBuilder
public static java.lang.Process runProcessBuilder(java.lang.ProcessBuilder processBuilder) throws java.io.IOException
Delegates torunProcessBuilder(ProcessBuilder, Set)
with default restrictions.- Parameters:
processBuilder
- the system command about to be run- Returns:
- the
Process
that results from the hardenedProcessBuilder.start()
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.IOException
Does the same asRuntime.exec(String)
, but adds restrictions on what types of commands will be allowed. Will throw aSecurityException
if 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
Process
that 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.IOException
Delegates torunCommand(Runtime, String, Set)
with default restrictions.- Parameters:
runtime
- the runtime to run withcommand
- the system command about to be run- Returns:
- the
Process
that 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.IOException
Does the same asRuntime.exec(String[])
, but adds restrictions on what types of commands will be allowed. Will throw aSecurityException
if 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
Process
that 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.IOException
Delegates torunCommand(Runtime, String[], Set)
with default restrictions.- Parameters:
runtime
- the runtime to run withcommand
- the system command about to be run- Returns:
- the
Process
that 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.IOException
Same 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
Process
that 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.IOException
Delegates 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
Process
that 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.IOException
Same 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
Process
that 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.IOException
Same 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
Process
that 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.IOException
Delegates 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
Process
that 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.IOException
Same 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
Process
that 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.IOException
Delegates 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
Process
that 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.IOException
Delegates 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
Process
that results from the hardenedRuntime.exec(String[], String[], File)
call - Throws:
java.io.IOException
- from the wrapped system process invocation call
-
-