CVE-2022-24823: Exposure of Resource to Wrong Sphere (CWE-668)
value: Netty is an open-source, asynchronous event-driven network application framework. The package `io.netty:netty-codec-http` prior to version 4.1.77.Final contains an insufficient fix for CVE-2021-21290. When Netty's multipart decoders are used local information disclosure can occur via the local system temporary directory if temporary storing uploads on the disk is enabled. This only impacts applications running on Java version 6 and lower. Additionally, this vulnerability impacts code running on Unix-like systems, and very old versions of Mac OSX and Windows as they all share the system temporary directory between all users. Version 4.1.77.Final contains a patch for this vulnerability. As a workaround, specify one's own `java.io.tmpdir` when starting the JVM or use DefaultHttpDataFactory.setBaseDir(...) to set the directory to something that is only readable by the current user.
CWE description: The product exposes a resource to the wrong control sphere, providing unintended actors with inappropriate access to the resource.
CVSS v3 base score: 5.5
Published: 2022-05-06T12:15Z
Repository: https://github.com/netty/netty
Language: Java
Files changed: common/src/main/java/io/netty/util/internal/PlatformDependent.java
Commit date: 2022-05-06 08:57:43 +0200
Commit message: Merge pull request from GHSA-269q-hmxg-m83q

* Correctly modify permission for temporary files when using Java 6 in all cases

Motivation:

[GHSA-5mcr-gq6c-3hq2](https://github.com/netty/netty/security/advisories/GHSA-5mcr-gq6c-3hq2) did not correctly fix all cases for temprory files when running on java 6.

Modifications:

- Add correctly adjust perms in all cases
- Add logging if adjusting of permissions fails

Result:

Fixes https://github.com/netty/netty/security/advisories/GHSA-269q-hmxg-m83q

* Throw on failure
Diff: diff --git a/common/src/main/java/io/netty/util/internal/PlatformDependent.java b/common/src/main/java/io/netty/util/internal/PlatformDependent.java
index 8532046366..00310e585e 100644
--- a/common/src/main/java/io/netty/util/internal/PlatformDependent.java
+++ b/common/src/main/java/io/netty/util/internal/PlatformDependent.java
@@ -1445,17 +1445,24 @@ public final class PlatformDependent {
             if (directory == null) {
                 return Files.createTempFile(prefix, suffix).toFile();
             }
             return Files.createTempFile(directory.toPath(), prefix, suffix).toFile();
         }
+        final File file;
         if (directory == null) {
-            return File.createTempFile(prefix, suffix);
+            file = File.createTempFile(prefix, suffix);
+        } else {
+            file = File.createTempFile(prefix, suffix, directory);
         }
-        File file = File.createTempFile(prefix, suffix, directory);
+
         // Try to adjust the perms, if this fails there is not much else we can do...
-        file.setReadable(false, false);
-        file.setReadable(true, true);
+        if (!file.setReadable(false, false)) {
+            throw new IOException("Failed to set permissions on temporary file " + file);
+        }
+        if (!file.setReadable(true, true)) {
+            throw new IOException("Failed to set permissions on temporary file " + file);
+        }
         return file;
     }
 
     /**
      * Adds only those classifier strings to <tt>dest</tt> which are present in <tt>allowed</tt>.

Vulnerable code:             return File.createTempFile(prefix, suffix);
        File file = File.createTempFile(prefix, suffix, directory);
        file.setReadable(false, false);
        file.setReadable(true, true);
Fixed code:         final File file;
            file = File.createTempFile(prefix, suffix);
        } else {
            file = File.createTempFile(prefix, suffix, directory);

        if (!file.setReadable(false, false)) {
            throw new IOException("Failed to set permissions on temporary file " + file);
        }
        if (!file.setReadable(true, true)) {
            throw new IOException("Failed to set permissions on temporary file " + file);
        }