(command string)
| 245 | } |
| 246 | |
| 247 | func CheckSemantics(command string) string { |
| 248 | extraction := ExtractQuotedContent(command) |
| 249 | target := extraction.FullyUnquoted |
| 250 | for _, pattern := range commandSubstitutionPatterns[:3] { |
| 251 | if pattern.re.MatchString(target) { |
| 252 | return "dangerous" |
| 253 | } |
| 254 | } |
| 255 | indicators := []*regexp.Regexp{ |
| 256 | regexp.MustCompile("`[^`]+`"), |
| 257 | regexp.MustCompile(`\$\([^)]+\)`), |
| 258 | regexp.MustCompile(`\|.*\|`), |
| 259 | regexp.MustCompile(`&&.*&&`), |
| 260 | regexp.MustCompile(`\|\|.*\|\|`), |
| 261 | } |
| 262 | score := 0 |
| 263 | for _, indicator := range indicators { |
| 264 | if indicator.MatchString(target) { |
| 265 | score++ |
| 266 | } |
| 267 | } |
| 268 | if score >= 3 { |
| 269 | return "too-complex" |
| 270 | } |
| 271 | if score >= 1 { |
| 272 | return "dangerous" |
| 273 | } |
| 274 | return "safe" |
| 275 | } |
| 276 | |
| 277 | func checkCommandSubstitution(command string) []SecurityFinding { |
| 278 | target := ExtractQuotedContent(command).WithDoubleQuotes |
no test coverage detected