validateBlamePath rejects empty, leading-slash, traversal-laden, or control-character paths before any network call is made.
(p string)
| 2368 | // validateBlamePath rejects empty, leading-slash, traversal-laden, or |
| 2369 | // control-character paths before any network call is made. |
| 2370 | func validateBlamePath(p string) error { |
| 2371 | if strings.TrimSpace(p) == "" { |
| 2372 | return fmt.Errorf("path must not be empty") |
| 2373 | } |
| 2374 | if strings.HasPrefix(p, "/") { |
| 2375 | return fmt.Errorf("path must be relative to the repository root (no leading '/')") |
| 2376 | } |
| 2377 | if slices.Contains(strings.Split(p, "/"), "..") { |
| 2378 | return fmt.Errorf("path must not contain '..' segments") |
| 2379 | } |
| 2380 | for _, r := range p { |
| 2381 | if r < 0x20 || r == 0x7f { |
| 2382 | return fmt.Errorf("path must not contain control characters") |
| 2383 | } |
| 2384 | } |
| 2385 | return nil |
| 2386 | } |
| 2387 | |
| 2388 | func GetFileBlame(t translations.TranslationHelperFunc) inventory.ServerTool { |
| 2389 | st := NewTool( |