@@ -143,6 +143,54 @@ func TestDockerBindWorkspaceCreator_Create(t *testing.T) {
143143 })
144144}
145145
146+ func TestUnzipRejectsUnsafeArchivePaths (t * testing.T ) {
147+ tests := []string {
148+ `.git\config` ,
149+ `hooks\pre-commit` ,
150+ }
151+
152+ for _ , name := range tests {
153+ t .Run (name , func (t * testing.T ) {
154+ archivePath := zipUpFiles (t , t .TempDir (), map [string ]string {name : "malicious" })
155+ dest := t .TempDir ()
156+
157+ if err := unzip (context .Background (), archivePath , dest ); err == nil {
158+ t .Fatal ("expected unsafe archive path to be rejected" )
159+ }
160+
161+ entries , err := os .ReadDir (dest )
162+ if err != nil {
163+ t .Fatal (err )
164+ }
165+ if len (entries ) != 0 {
166+ t .Fatalf ("archive was partially extracted: %v" , entries )
167+ }
168+ })
169+ }
170+ }
171+
172+ func TestUnzipAllowsSafeControlPaths (t * testing.T ) {
173+ files := map [string ]string {
174+ ".git_config" : "config" ,
175+ "hooks_pre-commit" : "hook" ,
176+ }
177+ archivePath := zipUpFiles (t , t .TempDir (), files )
178+ dest := t .TempDir ()
179+
180+ if err := unzip (context .Background (), archivePath , dest ); err != nil {
181+ t .Fatal (err )
182+ }
183+ for name , want := range files {
184+ have , err := os .ReadFile (filepath .Join (dest , name ))
185+ if err != nil {
186+ t .Fatal (err )
187+ }
188+ if string (have ) != want {
189+ t .Errorf ("%s: got %q, want %q" , name , have , want )
190+ }
191+ }
192+ }
193+
146194func TestDockerBindWorkspace_ApplyDiff (t * testing.T ) {
147195 // Create a zip file for all the other tests to use.
148196 fakeFilesTmpDir := t .TempDir ()
0 commit comments