isExcludedCommand 检查命令是否在排除列表中
(cmd string)
| 1031 | |
| 1032 | // isExcludedCommand 检查命令是否在排除列表中 |
| 1033 | func (ls *LocalSandbox) isExcludedCommand(cmd string) bool { |
| 1034 | if len(ls.excludedCommands) == 0 { |
| 1035 | return false |
| 1036 | } |
| 1037 | |
| 1038 | // 提取命令的第一个词(命令名) |
| 1039 | cmdParts := strings.Fields(cmd) |
| 1040 | if len(cmdParts) == 0 { |
| 1041 | return false |
| 1042 | } |
| 1043 | cmdName := cmdParts[0] |
| 1044 | |
| 1045 | for _, excluded := range ls.excludedCommands { |
| 1046 | if cmdName == excluded { |
| 1047 | return true |
| 1048 | } |
| 1049 | // 支持路径形式的命令 |
| 1050 | if strings.HasSuffix(cmdName, "/"+excluded) { |
| 1051 | return true |
| 1052 | } |
| 1053 | } |
| 1054 | |
| 1055 | return false |
| 1056 | } |
| 1057 | |
| 1058 | // execDirect 直接执行命令(排除命令,仍有基本安全检查) |
| 1059 | func (ls *LocalSandbox) execDirect(ctx context.Context, cmd string, opts *ExecOptions) (*ExecResult, error) { |
no outgoing calls