GHSL-2020-257: The unsafe handling of symbolic links in an unpacking routine in oras - CVE-2021-21272
The tar extraction routine in oras did not properly prevent symbolic links from pointing outside the target directory. An attacker could craft a malicious tarball that, when extracted, creates symlinks allowing arbitrary file read or write outside the intended folder.
Originally disclosed on GitHub Security Lab
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.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The extraction routine checked each symlink target against the archive root but did not account for symlinks created earlier in the same archive that could redirect later paths outside the root.
Impact
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.
What the attacker needed
Attacker controls the tar archive; victim extracts the archive
The fix
The issue was fixed by the maintainers.
How it was found
- Create a tar archive containing a directory entry.
- Add a symlink entry that points to the parent directory, which is allowed because it stays within the archive root.
- Add another symlink entry that uses the previously created symlink to escape the root.
- Extract the archive using the vulnerable routine, causing files to be written outside the target folder.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When you extract a tar file, the program should keep all files inside the folder you choose. Here, a specially crafted tar file could create shortcuts (symbolic links) that point to places outside that folder, letting an attacker read or overwrite files on your system.
What is Path traversal?
Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.