Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codeql detects zipslip vulnerability #8209

Merged
merged 1 commit into from
Apr 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,10 @@ private static void includeEmbeddedExtensionsIfFound(
File tempFile = new File(tempDirectory, name.substring(prefix.length()));
// reject extensions that would be extracted outside of temp directory
// https://security.snyk.io/research/zip-slip-vulnerability
if (name.indexOf("..") != -1
&& !tempFile
.getCanonicalFile()
.toPath()
.startsWith(tempDirectory.getCanonicalFile().toPath())) {
if (!tempFile
.getCanonicalFile()
.toPath()
breedx-splk marked this conversation as resolved.
Show resolved Hide resolved
.startsWith(tempDirectory.getCanonicalFile().toPath())) {
Copy link
Contributor

@breedx-splk breedx-splk Apr 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.startsWith(tempDirectory.getCanonicalFile().toPath())) {
.startsWith(tempDirectory.getCanonicalPath() + File.separator)) {

It looks like appending the file separator to the end of the expected path is important in order to prevent writing to a neighboring directory. That is, if the actual temp dir is /tmp and the file coming in from the zip somehow crafts ../../../../tmpOther it could possibly write to /tmpOther which should also be prevented.

throw new IllegalStateException("Invalid extension " + name);
}
if (tempFile.createNewFile()) {
Expand Down