(command string, workspaceRoot string)
| 315 | } |
| 316 | |
| 317 | func ValidatePaths(command string, workspaceRoot string) (bool, []string) { |
| 318 | paths := ExtractPaths(command) |
| 319 | invalid := []string{} |
| 320 | |
| 321 | root, err := resolvePath(workspaceRoot) |
| 322 | if err != nil { |
| 323 | return false, paths |
| 324 | } |
| 325 | |
| 326 | for _, p := range paths { |
| 327 | if strings.HasPrefix(p, "/dev/") || strings.HasPrefix(p, "/proc/") || strings.HasPrefix(p, "/sys/") { |
| 328 | continue |
| 329 | } |
| 330 | |
| 331 | if isSpecialSafePath(p) { |
| 332 | continue |
| 333 | } |
| 334 | |
| 335 | if IsPathWithinWorkspace(p, root) { |
| 336 | continue |
| 337 | } |
| 338 | |
| 339 | full := p |
| 340 | if !filepath.IsAbs(p) { |
| 341 | full = filepath.Join(root, p) |
| 342 | } |
| 343 | resolvedFull, err := resolvePath(full) |
| 344 | if err != nil { |
| 345 | invalid = append(invalid, p) |
| 346 | continue |
| 347 | } |
| 348 | |
| 349 | rel, err := filepath.Rel(root, resolvedFull) |
| 350 | if err != nil || rel == ".." || strings.HasPrefix(rel, ".."+string(filepath.Separator)) { |
| 351 | invalid = append(invalid, p) |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | return len(invalid) == 0, invalid |
| 356 | } |
| 357 | |
| 358 | func isSpecialSafePath(p string) bool { |
| 359 | switch p { |
nothing calls this directly
no test coverage detected