@@ -19,6 +19,9 @@ package remote
1919import (
2020 "path/filepath"
2121 "testing"
22+
23+ spec "github.com/opencontainers/image-spec/specs-go/v1"
24+ "gotest.tools/v3/assert"
2225)
2326
2427func TestValidatePathInBase (t * testing.T ) {
@@ -84,11 +87,6 @@ func TestValidatePathInBase(t *testing.T) {
8487 unsafePath : ".." ,
8588 wantErr : true ,
8689 },
87- {
88- name : "current directory reference" ,
89- unsafePath : "./file.yaml" ,
90- wantErr : false , // ./ resolves to base dir
91- },
9290 {
9391 name : "mixed separators" ,
9492 unsafePath : "config/sub\\ file.yaml" ,
@@ -104,11 +102,6 @@ func TestValidatePathInBase(t *testing.T) {
104102 unsafePath : "file-name_v1.2.3.yaml" ,
105103 wantErr : false ,
106104 },
107- {
108- name : "single parent then back" ,
109- unsafePath : "../compose/file.yaml" ,
110- wantErr : false , // Resolves back to base dir, which is fine
111- },
112105 }
113106
114107 for _ , tt := range tests {
@@ -123,3 +116,24 @@ func TestValidatePathInBase(t *testing.T) {
123116 })
124117 }
125118}
119+
120+ func TestWriteComposeFileWithExtendsPathTraversal (t * testing.T ) {
121+ tmpDir := t .TempDir ()
122+
123+ // Create a layer with com.docker.compose.extends=true and a path traversal attempt
124+ layer := spec.Descriptor {
125+ MediaType : "application/vnd.docker.compose.file.v1+yaml" ,
126+ Digest : "sha256:test123" ,
127+ Size : 100 ,
128+ Annotations : map [string ]string {
129+ "com.docker.compose.extends" : "true" ,
130+ "com.docker.compose.file" : "../other" ,
131+ },
132+ }
133+
134+ content := []byte ("services:\n test:\n image: nginx\n " )
135+
136+ // writeComposeFile should return an error due to path traversal
137+ err := writeComposeFile (layer , 0 , tmpDir , content )
138+ assert .Error (t , err , "invalid OCI artifact" )
139+ }
0 commit comments