Package org.machanism.machai.ai.tools
Class CommandSecurityChecker
java.lang.Object
org.machanism.machai.ai.tools.CommandSecurityChecker
Loads and evaluates command deny-list rules used by host-side command execution tools.
The checker reads one or more rule resources and evaluates an input command line against those rules. Each non-empty, non-comment line of a deny-list file must use one of the following formats:
REGEX:...– a Java regular expression; a match anywhere in the command is considered dangerousKEYWORD:...– a case-insensitive substring match
This class provides a best-effort heuristic check. It should be used in addition to an allow-list and other host security controls.
-
Constructor Summary
ConstructorsConstructorDescriptionCommandSecurityChecker(Configurator configurator) Creates a new checker and loads deny-list rules from an operating-system specific classpath resource. -
Method Summary
-
Constructor Details
-
CommandSecurityChecker
Creates a new checker and loads deny-list rules from an operating-system specific classpath resource.The following resources are expected to exist on the classpath:
denylist/windows.txtwhen running on Windowsdenylist/unix.txtwhen running on a Unix-like OS
In addition, the host may provide
DENYLIST_PROP_NAMEto extend or override the default deny-list.- Parameters:
configurator- configurator used to optionally extend the deny-list- Throws:
IOException- if the selected resource cannot be found or readIllegalArgumentException- if no deny-list is defined for the current operating system
-
-
Method Details
-
denyCheck
Checks whether the supplied command matches any deny-list rule.If the command matches a rule, a
DenyExceptionis thrown containing a message identifying the matched rule.- Parameters:
command- shell command to check- Throws:
DenyException- if the command matches a deny-list rule
-