Robert Metzger created FLINK-41695:
--------------------------------------
Summary: Keep symlinks inside the target directory when extracting
archives in CompressionUtils
Key: FLINK-41695
URL: https://issues.apache.org/jira/browse/FLINK-41695
Project: Flink
Issue Type: Bug
Reporter: Robert Metzger
CompressionUtils.extractZipFileWithPermissions() is used to extract
python.archives and python.files. It has two problems with symlink entries:
1. Symlink targets are not checked. The link target is read from the entry data
and passed to Files.createSymbolicLink() as-is. The existing canonical-path
check covers only the entry's own path, not where the link points. A target
such as ../../some/file creates a link that points outside the extraction
directory.
2. Permissions are applied through symlinks. After extraction, the entry's Unix
mode is applied with Files.setPosixFilePermissions(outputPath, ...), which
follows links. For a symlink entry, this changes the permissions of the link
target, even when the target is outside the extraction directory. The code
already has a TODO for this: "support setting the permission without following
links".
unpackEntry() (the Java tar path, used when not on Unix) has the same first
problem: it creates symlinks from entry.getLinkName() without checking the
target.
Proposed changes:
1. In extractZipFileWithPermissions(), do not apply the Unix mode to symlink
entries. On Linux the permissions of a symlink itself are not used, so skipping
them is enough. This removes the TODO.
2. Before creating a symlink, resolve its target against the link's parent
directory, normalize it, and check that it stays inside the canonical
extraction directory. If not, fail with an IOException, as the existing path
check does. Do the same in unpackEntry() for tar archives.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)