(command string)
| 137 | } |
| 138 | |
| 139 | func analyzeSingleCommand(command string) PermissionResult { |
| 140 | cleaned := strings.TrimSpace(command) |
| 141 | if cleaned == "" { |
| 142 | return PermissionResult{ |
| 143 | Allowed: true, Risk: RiskSafe, Reason: "Empty command", |
| 144 | NeedsUserDecision: false, ParseResult: ParseSimple, |
| 145 | } |
| 146 | } |
| 147 | if appsecurity.IsDangerous(cleaned) { |
| 148 | return PermissionResult{ |
| 149 | Allowed: false, Risk: RiskHigh, Reason: "Command matches dangerous pattern", |
| 150 | NeedsUserDecision: true, ParseResult: ParseSimple, |
| 151 | } |
| 152 | } |
| 153 | semantic := CheckSemantics(cleaned) |
| 154 | if semantic == "dangerous" { |
| 155 | return PermissionResult{ |
| 156 | Allowed: false, Risk: RiskHigh, |
| 157 | Reason: "Command contains dangerous patterns (AST)", |
| 158 | NeedsUserDecision: true, ParseResult: ParseSimple, |
| 159 | } |
| 160 | } |
| 161 | if semantic == "too-complex" { |
| 162 | return PermissionResult{ |
| 163 | Allowed: false, Risk: RiskHigh, |
| 164 | Reason: "Command is too complex for automated analysis", |
| 165 | NeedsUserDecision: true, ParseResult: ParseTooComplex, |
| 166 | } |
| 167 | } |
| 168 | secResult := RunAllSecurityChecks(cleaned) |
| 169 | if IsBlocking(secResult) { |
| 170 | return PermissionResult{ |
| 171 | Allowed: false, Risk: RiskCritical, |
| 172 | Reason: "Security check failed: " + joinFindingDescriptions(secResult.Findings, 3), |
| 173 | NeedsUserDecision: true, ParseResult: ParseSimple, |
| 174 | } |
| 175 | } |
| 176 | if len(secResult.Findings) > 0 { |
| 177 | return PermissionResult{ |
| 178 | Allowed: false, Risk: RiskNormal, |
| 179 | Reason: "Security warnings: " + joinFindingDescriptions(secResult.Findings, 3), |
| 180 | NeedsUserDecision: true, ParseResult: ParseSimple, |
| 181 | } |
| 182 | } |
| 183 | return PermissionResult{ |
| 184 | Allowed: true, Risk: RiskSafe, Reason: "All checks passed", |
| 185 | NeedsUserDecision: false, ParseResult: ParseSimple, |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | func generateRuleSuggestions(subcommands []string) []string { |
| 190 | var suggestions []string |
no test coverage detected