Skip to content

Conversation

@UnknownHero
Copy link
Contributor

No description provided.

@UnknownHero UnknownHero marked this pull request as draft December 16, 2025 16:24
@UnknownHero UnknownHero marked this pull request as ready for review December 16, 2025 16:25
@kimdre
Copy link
Owner

kimdre commented Dec 16, 2025

Please explain what this PR does and what use cases it is intended for

@kimdre kimdre added question Further information is requested and removed question Further information is requested labels Dec 16, 2025
@UnknownHero
Copy link
Contributor Author

Please explain what this PR does and what use cases it is intended for

I need something like this:

name: staging-gateway-traefik
reference: refs/heads/main
working_dir: ./
compose_files:
  - base/traefik/docker-compose.yml
  - servers/staging/docker-compose.yaml
---
name: prod-gateway-traefik
reference: refs/heads/main
working_dir: ./
compose_files:
  - base/traefik/docker-compose.yml
  - servers/prod/docker-compose.yaml

But your sanitize don't allow me to do that -

// Sanitize the compose file path

Also "docker compose -f path/one/compose.yml -f path/two/compose.yml up" is valid command so i don't understand why you cut paths

@UnknownHero
Copy link
Contributor Author

my update comment:

for _, file := range c.ComposeFiles {
    cleaned := filepath.Clean(file)

    // Reject absolute paths (Unix + Windows)
    if filepath.IsAbs(cleaned) {
        return fmt.Errorf("%w: %s", ErrInvalidFilePath, file)
    }

    // Optionally reject paths that start with ".." (fast precheck)
    if cleaned == ".." || strings.HasPrefix(cleaned, ".."+string(os.PathSeparator)) {
        return fmt.Errorf("%w: %s", ErrInvalidFilePath, file)
    }

    // Resolve the path relative to working dir
    full := filepath.Join(workingDirOnDisk, cleaned)

    // Ensure full is still under workingDirOnDisk
    rel, err := filepath.Rel(workingDirOnDisk, full)
    if err != nil {
        return fmt.Errorf("%w: %s", ErrInvalidFilePath, file)
    }
    if rel == ".." || strings.HasPrefix(rel, ".."+string(os.PathSeparator)) {
        return fmt.Errorf("%w: %s", ErrInvalidFilePath, file)
    }

    // (Optional but recommended) ensure the file exists and is a regular file
    st, err := os.Stat(full)
    if err != nil || !st.Mode().IsRegular() {
        return fmt.Errorf("%w: %s", ErrInvalidFilePath, file)
    }

    cleanComposeFiles = append(cleanComposeFiles, cleaned)
}

@UnknownHero
Copy link
Contributor Author

remove this section

    // (Optional but recommended) ensure the file exists and is a regular file
    st, err := os.Stat(full)
    if err != nil || !st.Mode().IsRegular() {
        return fmt.Errorf("%w: %s", ErrInvalidFilePath, file)
    }

@kimdre
Copy link
Owner

kimdre commented Dec 16, 2025

Thanks, looks good to me!

@kimdre kimdre changed the title feat(config): support subfolders for docker-composes feat(config): support subfolders for compose files Dec 16, 2025
@kimdre kimdre changed the title feat(config): support subfolders for compose files fix(config): support subfolders for compose files Dec 16, 2025
@kimdre kimdre added the enhancement Improvements or additions to code label Dec 16, 2025
@kimdre kimdre changed the title fix(config): support subfolders for compose files fix(config): support paths for compose files Dec 16, 2025
@kimdre kimdre merged commit 30e4dc8 into kimdre:main Dec 16, 2025
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improvements or additions to code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants