Skip to content

ZipSlip Arbitrary File Upload

moderate
robinshine published GHSA-2w6j-wc8c-9mq2 Jan 11, 2021

Package

No package listed

Affected versions

<4.0.2

Patched versions

4.0.3

Description

Impact

KubernetesResource REST endpoint untars user controlled data from the request body:

	@POST
	@Path("/upload-outcomes")
	@Consumes(MediaType.APPLICATION_OCTET_STREAM)	
	public Response uploadOutcomes(InputStream is) {
		JobContext context = jobManager.getJobContext(getJobToken(), true);
		TarUtils.untar(is, context.getServerWorkspace());
		return Response.ok().build();
	}

TarUtils is a custom library method leveraging Apache Commons Compress. During the untar process, there are no checks in place to prevent an untarred file from traversing the file system and overriding an existing file.

A test Tar file can be found in the snyck repo.

For a successful exploitation, the attacker requires a valid JobToken which may not be possible to get without using any of the other reported vulnerabilities. But this should be considered a vulnerability in io.onedev.commons.utils.TarUtils since it lives in a different artifact and can affect other projects using it.

To reproduce the vulnerability, we can use the following Java code:

import io.onedev.commons.utils.TarUtils;
import java.io.FileInputStream;
import java.io.File;

public class UnTarTest {
  public static void main(String[] args) {
    try {
      FileInputStream is = new FileInputStream(new File("./zip-slip.tar"));
      TarUtils.untar(is, new File("./dest"));
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

Using the Tar file mentioned above, after running the untar operation, a file called evil.txt should be extracted to /tmp

This issue may lead to arbitrary file write

Patches

This issue was addressed in 4.0.3 by validating paths in tar archive to only allow them to be in specified folder when extracted.

Credits

This issue was discovered by @pwntester

CVE ID

CVE-2021-21251