sanitizePath converts a file path to a safe filename by using filepath.Clean and replacing directory separators with underscores
(path string)
| 22 | // sanitizePath converts a file path to a safe filename by using filepath.Clean |
| 23 | // and replacing directory separators with underscores |
| 24 | func sanitizePath(path string) string { |
| 25 | // Clean the path to remove any ".." or other suspicious elements |
| 26 | cleaned := filepath.Clean(path) |
| 27 | // Replace directory separators with underscores to create a flat filename |
| 28 | // This prevents directory traversal while preserving path uniqueness |
| 29 | sanitized := strings.ReplaceAll(cleaned, string(filepath.Separator), "_") |
| 30 | return sanitized |
| 31 | } |
| 32 | |
| 33 | // validatePathComponents validates that path components don't contain malicious sequences |
| 34 | func validatePathComponents(owner, repo, path, sha string) error { |
no outgoing calls