Skip to content

Commit

Permalink
fix: improve atmos.d path validation and add support for .atmos.d dir…
Browse files Browse the repository at this point in the history
…ectory imports
  • Loading branch information
haitham911 committed Dec 13, 2024
1 parent cdafe20 commit b702884
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,24 @@ func InitCliConfig(configAndStacksInfo schema.ConfigAndStacksInfo, processStacks
atmosDPath := filepath.Join(basePath, "atmos.d")
// Ensure the joined path doesn't escape the intended directory
if !strings.HasPrefix(atmosDPath, basePath) {
u.LogWarning(cliConfig, fmt.Sprintf("Warning: invalid atmos.d path: attempted directory traversal"))
u.LogWarning(cliConfig, "invalid atmos.d path: attempted directory traversal")
}

_, err = os.Stat(atmosDPath)
if err == nil {
cliConfig.Import = []string{"atmos.d/**/*.yaml", "atmos.d/**/*.yml", ".atmos.d/**/*.yaml", ".atmos.d/**/*.yml"}
cliConfig.Import = []string{"atmos.d/**/*.yaml", "atmos.d/**/*.yml"}
} else if !os.IsNotExist(err) {
return cliConfig, err // Handle unexpected errors
}
// Check for `.atmos.d` directory if `.atmos.d` directory is not found
atmosDPath = filepath.Join(atmosDPath, ".atmos.d")
_, err = os.Stat(atmosDPath)
if err == nil {
cliImport := []string{".atmos.d/**/*.yaml", ".atmos.d/**/*.yml"}
cliConfig.Import = append(cliConfig.Import, cliImport...)
} else if !os.IsNotExist(err) {
return cliConfig, err // Handle unexpected errors
}

}
// Process imports if any
if len(cliConfig.Import) > 0 {
Expand Down

0 comments on commit b702884

Please sign in to comment.