[JENKINS-51777] Don't let tar entries escape target dir

(cherry picked from commit 7438abb88f)
This commit is contained in:
Daniel Beck authored and Oliver Gondža committed 2018-08-01 09:51:06 +02:00
1 parent 4cb86a5c30
commit f42fe0fc63
1 file changed
+4
+4
View File
@@ -2447,6 +2447,10 @@ public final class FilePath implements Serializable {
TarArchiveEntry te;
while ((te = t.getNextTarEntry()) != null) {
File f = new File(baseDir, te.getName());
if (!f.toPath().normalize().startsWith(baseDir.toPath())) {
throw new IOException(
"Tar " + name + " contains illegal file name that breaks out of the target directory: " + te.getName());
}
if (te.isDirectory()) {
mkdirs(f);
} else {