MCPcopy Create free account
hub / github.com/github/gh-aw / validatePathComponents

Function validatePathComponents

pkg/parser/import_cache.go:34–55  ·  view source on GitHub ↗

validatePathComponents validates that path components don't contain malicious sequences

(owner, repo, path, sha string)

Source from the content-addressed store, hash-verified

32
33// validatePathComponents validates that path components don't contain malicious sequences
34func validatePathComponents(owner, repo, path, sha string) error {
35 components := []string{owner, repo, path, sha}
36 for _, comp := range components {
37 // Check for empty components
38 if comp == "" {
39 importCacheLog.Print("Path validation failed: empty component detected")
40 return errors.New("empty component in path")
41 }
42 // Check for path traversal attempts
43 if strings.Contains(comp, "..") {
44 importCacheLog.Printf("Path validation failed: path traversal attempt in component: %s", comp)
45 return fmt.Errorf("component contains '..' sequence: %s", comp)
46 }
47 // Check for absolute paths
48 if filepath.IsAbs(comp) {
49 importCacheLog.Printf("Path validation failed: absolute path in component: %s", comp)
50 return fmt.Errorf("component is absolute path: %s", comp)
51 }
52 }
53 importCacheLog.Print("Path validation successful")
54 return nil
55}
56
57// ImportCache manages cached imported workflow files
58type ImportCache struct {

Callers 2

SetMethod · 0.85

Calls 3

PrintMethod · 0.80
PrintfMethod · 0.45
ErrorfMethod · 0.45

Tested by 1