类 UnixCommandValidator
java.lang.Object
io.agentscope.core.tool.coding.UnixCommandValidator
- 所有已实现的接口:
CommandValidator
Command validator for Unix-like systems (Linux, macOS).
Validation Order:
- Extract executable from command (remove quotes, extract first token, remove extensions)
- If no whitelist configured → allow (backward compatible)
- Check for multiple command separators → reject if found
- Check relative path safety (commands starting with
./) → reject if escapes current directory - Check whitelist → reject if not in whitelist
Multiple Command Detection: Detects Unix-specific separators:
&, &&, |, ||, ;, newline
(ignores separators within quotes or after escape \)
Executable Extraction:
- Handles quoted commands (single or double quotes)
- Extracts first token before space/tab
- Removes script extensions:
.sh,.py,.rb,.pl,.bash,.zsh
-
嵌套类概要
从接口继承的嵌套类/接口 io.agentscope.core.tool.coding.CommandValidator
CommandValidator.ValidationResult -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明booleancontainsMultipleCommands(String command) Check if the command contains multiple command separators outside of quotes.extractExecutable(String command) Extract the executable name from a command string.Validate if a command is allowed to execute.从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait从接口继承的方法 io.agentscope.core.tool.coding.CommandValidator
isPathWithinCurrentDirectory
-
构造器详细资料
-
UnixCommandValidator
public UnixCommandValidator()
-
-
方法详细资料
-
validate
从接口复制的说明:CommandValidatorValidate if a command is allowed to execute.Validation checks (in order):
- Extract executable name
- If whitelist is null/empty → allow (backward compatible)
- Check for multiple command separators → reject if found
- Check relative path safety → reject if escapes current directory
- Check whitelist → reject if not in whitelist
- 指定者:
validate在接口中CommandValidator- 参数:
command- The command string to validateallowedCommands- Set of allowed command executables (null or empty means allow all)- 返回:
- ValidationResult containing the validation outcome
-
extractExecutable
从接口复制的说明:CommandValidatorExtract the executable name from a command string.Extraction process:
- Remove surrounding quotes (if present)
- Extract first token (before space/tab)
- Remove directory path (platform-specific)
- Remove file extensions (platform-specific)
- 指定者:
extractExecutable在接口中CommandValidator- 参数:
command- The command string- 返回:
- The executable name, or empty string if extraction fails
-
containsMultipleCommands
Check if the command contains multiple command separators outside of quotes.Detects: &, |, ;, newline (ignores separators within quotes or after escape \)
- 指定者:
containsMultipleCommands在接口中CommandValidator- 参数:
command- The command to check- 返回:
- true if multiple commands are detected, false otherwise
-