| 117 | } |
| 118 | |
| 119 | func AnalyzeCommandPermissions(command string) PermissionResult { |
| 120 | subcommands := SplitPipeline(command) |
| 121 | if len(subcommands) > MaxSubcommandsForSecurityCheck { |
| 122 | return PermissionResult{ |
| 123 | Allowed: false, Risk: RiskHigh, |
| 124 | Reason: fmt.Sprintf("Too many subcommands (%d > %d)", len(subcommands), MaxSubcommandsForSecurityCheck), |
| 125 | NeedsUserDecision: true, ParseResult: ParseTooComplex, |
| 126 | } |
| 127 | } |
| 128 | results := make([]PermissionResult, 0, len(subcommands)) |
| 129 | for _, sub := range subcommands { |
| 130 | results = append(results, analyzeSingleCommand(sub)) |
| 131 | } |
| 132 | result := AggregateCompoundPermissions(results) |
| 133 | if result.NeedsUserDecision { |
| 134 | result.SuggestedRules = generateRuleSuggestions(subcommands) |
| 135 | } |
| 136 | return result |
| 137 | } |
| 138 | |
| 139 | func analyzeSingleCommand(command string) PermissionResult { |
| 140 | cleaned := strings.TrimSpace(command) |