GHSL-2023-120: Arbitrary File Read/Write during TAR extraction in Gradle
Gradle 8.1.1 does not validate paths from TAR archive entries, allowing an attacker who can manipulate a TAR file to write arbitrary files when unpacked or read arbitrary files when read by a Gradle script.
Originally disclosed on GitHub Security Lab
Gradle 8.1.1 does not ensure that paths constructed from TAR archive entries are validated. This allows attackers who are able to manipulate a TAR file which is unpacked by a Gradle script to overwrite arbitrary files.
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 method safeEntryName returns the entry name without checking for path traversal sequences, and this unvalidated name is used to construct file paths for both writing and reading.
Impact
This may lead to arbitrary file write when TAR entries are unpacked or to information disclosure through an arbitrary file read when TAR entries are read; exploitation is limited to directories where file permissions can be set.
What the attacker needed
Attacker can supply a malicious TAR file; victim runs a Gradle script that extracts or reads the TAR
How it was found
- Create a TAR file with an entry name containing path traversal sequences.
- Use a Gradle script to extract the TAR file using tarTree.
- The file is written outside the intended directory.
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 names inside it are used to decide where files go. If those names contain '../', the files can end up outside the intended folder. This means someone who can give you a malicious TAR file could overwrite important files or read sensitive ones.
What is Path traversal?
Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.