Skip to content

Commit 7152db7

Browse files
vuln-fix: Zip Slip Vulnerability
This fixes a Zip-Slip vulnerability. This change does one of two things. This change either 1. Inserts a guard to protect against Zip Slip. OR 2. Replaces `dir.getCanonicalPath().startsWith(parent.getCanonicalPath())`, which is vulnerable to partial path traversal attacks, with the more secure `dir.getCanonicalFile().toPath().startsWith(parent.getCanonicalFile().toPath())`. For number 2, consider `"/usr/outnot".startsWith("/usr/out")`. The check is bypassed although `/outnot` is not under the `/out` directory. It's important to understand that the terminating slash may be removed when using various `String` representations of the `File` object. For example, on Linux, `println(new File("/var"))` will print `/var`, but `println(new File("/var", "/")` will print `/var/`; however, `println(new File("/var", "/").getCanonicalPath())` will print `/var`. Weakness: CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') Severity: High CVSSS: 7.4 Detection: CodeQL (https://codeql.github.com/codeql-query-help/java/java-zipslip/) & OpenRewrite (https://public.moderne.io/recipes/org.openrewrite.java.security.ZipSlip) Reported-by: Jonathan Leitschuh <Jonathan.Leitschuh@gmail.com> Signed-off-by: Jonathan Leitschuh <Jonathan.Leitschuh@gmail.com> Bug-tracker: JLLeitschuh/security-research#16 Co-authored-by: Moderne <team@moderne.io>
1 parent fbdcdc7 commit 7152db7

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

xmppserver/src/main/java/org/jivesoftware/openfire/container/PluginMonitor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,10 @@ private boolean unzipPlugin( String pluginName, Path file, Path dir )
479479
for ( Enumeration e = zipFile.entries(); e.hasMoreElements(); )
480480
{
481481
JarEntry entry = (JarEntry) e.nextElement();
482-
Path entryFile = dir.resolve( entry.getName() ); // ignore possibility for zipslip as this is sanitized for if property is enabled lgtm [java/zipslip]
482+
Path entryFile = dir.resolve( entry.getName() );
483+
if (!entryFile.normalize().startsWith(dir.normalize())) {
484+
throw new IOException("Bad zip entry");
485+
} // ignore possibility for zipslip as this is sanitized for if property is enabled lgtm [java/zipslip]
483486
// Ignore any manifest.mf entries.
484487
if ( entry.getName().toLowerCase().endsWith( "manifest.mf" ) )
485488
{

0 commit comments

Comments
 (0)