Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/formatter/shortcut_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ package formatter
func handleCtrlZ() {
// Windows doesn't support SIGSTOP/SIGCONT signals
// Ctrl+Z behavior is handled differently by the Windows terminal
}
}
4 changes: 2 additions & 2 deletions pkg/compose/publish_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ services:
MediaType: "application/vnd.docker.compose.file+yaml",
Annotations: map[string]string{
"com.docker.compose.file": "compose.yaml",
"com.docker.compose.version": internal.Version},
"com.docker.compose.version": internal.Version,
},
},
{
MediaType: "application/vnd.docker.compose.file+yaml",
Expand All @@ -98,5 +99,4 @@ services:
assert.DeepEqual(t, expectedLayers, layers, cmp.FilterPath(func(path cmp.Path) bool {
return !slices.Contains([]string{".Data", ".Digest", ".Size"}, path.String())
}, cmp.Ignore()))

}
1 change: 0 additions & 1 deletion pkg/compose/transform/replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ func ReplaceEnvFile(in []byte, service string, i int, value string) ([]byte, err
} else {
return replace(in, envFile.Line, envFile.Column, value), nil
}

}

func getMapping(root *yaml.Node, key string) (*yaml.Node, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/remote/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (g ociRemoteLoader) Dir(path string) string {
return g.known[path]
}

func (g ociRemoteLoader) pullComposeFiles(ctx context.Context, local string, manifest spec.Manifest, ref reference.Named, resolver remotes.Resolver) error { //nolint:gocyclo
func (g ociRemoteLoader) pullComposeFiles(ctx context.Context, local string, manifest spec.Manifest, ref reference.Named, resolver remotes.Resolver) error {
err := os.MkdirAll(local, 0o700)
if err != nil {
return err
Expand Down
34 changes: 24 additions & 10 deletions pkg/remote/oci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ package remote
import (
"path/filepath"
"testing"

spec "github.com/opencontainers/image-spec/specs-go/v1"
"gotest.tools/v3/assert"
)

func TestValidatePathInBase(t *testing.T) {
Expand Down Expand Up @@ -84,11 +87,6 @@ func TestValidatePathInBase(t *testing.T) {
unsafePath: "..",
wantErr: true,
},
{
name: "current directory reference",
unsafePath: "./file.yaml",
wantErr: false, // ./ resolves to base dir
},
{
name: "mixed separators",
unsafePath: "config/sub\\file.yaml",
Expand All @@ -104,11 +102,6 @@ func TestValidatePathInBase(t *testing.T) {
unsafePath: "file-name_v1.2.3.yaml",
wantErr: false,
},
{
name: "single parent then back",
unsafePath: "../compose/file.yaml",
wantErr: false, // Resolves back to base dir, which is fine
},
}

for _, tt := range tests {
Expand All @@ -123,3 +116,24 @@ func TestValidatePathInBase(t *testing.T) {
})
}
}

func TestWriteComposeFileWithExtendsPathTraversal(t *testing.T) {
tmpDir := t.TempDir()

// Create a layer with com.docker.compose.extends=true and a path traversal attempt
layer := spec.Descriptor{
MediaType: "application/vnd.docker.compose.file.v1+yaml",
Digest: "sha256:test123",
Size: 100,
Annotations: map[string]string{
"com.docker.compose.extends": "true",
"com.docker.compose.file": "../other",
},
}

content := []byte("services:\n test:\n image: nginx\n")

// writeComposeFile should return an error due to path traversal
err := writeComposeFile(layer, 0, tmpDir, content)
assert.Error(t, err, "invalid OCI artifact")
}