类 WindowsCommandValidator
java.lang.Object
io.agentscope.core.tool.coding.WindowsCommandValidator
- 所有已实现的接口:
CommandValidator
Command validator for Windows systems.
Validation Order:
- Extract executable from command (remove quotes, handle paths with spaces, remove path, remove extensions, convert to lowercase)
- If no whitelist configured → allow (backward compatible)
- Check for multiple command separators → reject if found
- Check relative path safety (commands starting with
.\or./) → reject if escapes current directory - Check whitelist (case-insensitive) → reject if not in whitelist
Multiple Command Detection: Detects Windows-specific separators:
&, &&, |, ||, newline
(ignores separators within quotes or after escape ^)
Note: Semicolon (;) is NOT a separator in Windows cmd.exe
Executable Extraction:
- Handles quoted commands (double quotes)
- Handles paths with spaces (e.g.,
C:\Program Files\app.exe) - Extracts command name without path (handles both
\and/) - Removes extensions:
.exe,.bat,.cmd(case-insensitive) - Converts result to lowercase for consistent matching
-
嵌套类概要
从接口继承的嵌套类/接口 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
-
构造器详细资料
-
WindowsCommandValidator
public WindowsCommandValidator()
-
-
方法详细资料
-
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 ^)
Note: Semicolon is NOT a separator in Windows cmd.exe
- 指定者:
containsMultipleCommands在接口中CommandValidator- 参数:
command- The command to check- 返回:
- true if multiple commands are detected, false otherwise
-