CVE-2022-41954 (published 2022-11-25T19:15Z)

MPXJ is an open source library to read and write project plans from a variety of file formats and databases. On Unix-like operating systems (not Windows or macos), MPXJ's use of `File.createTempFile(..)` results in temporary files being created with the permissions `-rw-r--r--`. This means that any other user on the system can read the contents of this file. When MPXJ is reading a schedule file which requires the creation of a temporary file or directory, a knowledgeable local user could locate these transient files while they are in use and would then be able to read the schedule being processed by MPXJ. The problem has been patched, MPXJ version 10.14.1 and later includes the necessary changes. Users unable to upgrade may set `java.io.tmpdir` to a directory to which only the user running the application has access will prevent other users from accessing these temporary files.

CVSS v3 base score: 3.3, LOW (CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:L/I:N/A:N)

Weakness information:
cwe_id: CWE-200
cwe_name: Exposure of Sensitive Information to an Unauthorized Actor
description: The product exposes sensitive information to an actor that is not explicitly authorized to have access to that information.
extended_description: 
	   There are many different kinds of mistakes that introduce information exposures. The severity of the error can range widely, depending on the context in which the product operates, the type of sensitive information that is revealed, and the benefits it may provide to an attacker.  Some kinds of sensitive information include:
       
         private, personal information, such as personal messages, financial data, health records, geographic location, or contact details
         system status and environment, such as the operating system and installed packages
		 business secrets and intellectual property
		 network status and configuration
		 the product's own code or internal state
         metadata, e.g. logging of connections or message headers
		 indirect information, such as a discrepancy between two internal operations that can be observed by an outsider
       
	    Information might be sensitive to different parties, each of which may have their own expectations for whether the information should be protected.  These parties include:
               
                  the product's own users
                  people or organizations whose information is created or used by the product, even if they are not direct product users
		  the product's administrators, including the admins of the system(s) and/or networks on which the product operates
                  the developer
               
	    Information exposures can occur in different ways:
               
                  the code explicitly inserts sensitive information into resources or messages that are intentionally made accessible to unauthorized actors, but should not contain the information - i.e., the information should have been "scrubbed" or "sanitized"
                  a different weakness or mistake indirectly inserts the sensitive information into resources, such as a web script error revealing the full system path of the program.
                  the code manages resources that intentionally contain sensitive information, but the resources are unintentionally made accessible to unauthorized actors. In this case, the information exposure is resultant - i.e., a different weakness enabled the access to the information in the first place.
               
	    It is common practice to describe any loss of confidentiality as an "information exposure," but this can lead to overuse of CWE-200 in CWE mapping. From the CWE perspective, loss of confidentiality is a technical impact that can arise from dozens of different weaknesses, such as insecure file permissions or out-of-bounds read.  CWE-200 and its lower-level descendants are intended to cover the mistakes that occur in behaviors that explicitly manage, store, transfer, or cleanse sensitive information.
         
         
cwe_id: CWE-377
cwe_name: Insecure Temporary File
description: Creating and using insecure temporary files can leave application and system data vulnerable to attack.
extended_description: 
            
         
         

Fix information:
repo_url: https://github.com/joniles/mpxj
commit_details: repo_url: https://github.com/joniles/mpxj
author: Jonathan Leitschuh
author_date: 2022-11-19 21:19:58+00:00
msg: vuln-fix: Temporary File Information Disclosure



This fixes temporary file information disclosure vulnerability due to the use
of the vulnerable `File.createTempFile()` method. The vulnerability is fixed by
using the `Files.createTempFile()` method which sets the correct posix permissions.

Weakness: CWE-377: Insecure Temporary File
Severity: Medium
CVSSS: 5.5
Detection: CodeQL & OpenRewrite (https://public.moderne.io/recipes/org.openrewrite.java.security.SecureTempFileCreation)

Reported-by: Jonathan Leitschuh <Jonathan.Leitschuh@gmail.com>
Signed-off-by: Jonathan Leitschuh <Jonathan.Leitschuh@gmail.com>

Bug-tracker: https://github.com/JLLeitschuh/security-research/issues/18


Co-authored-by: Moderne <team@moderne.io>
repository: repo_url: https://github.com/joniles/mpxj
repo_name: joniles/mpxj
description: Primary repository for MPXJ library
repo_language: Java
owner: joniles
file_changes: filename: FileHelper.java
change_type: ModificationType.MODIFY
diff: @@ -25,6 +25,7 @@ package net.sf.mpxj.common;
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.file.Files;
 
 /**
  * Common helper methods for working with files.
@@ -110,7 +111,7 @@ public final class FileHelper
     */
    public static final File createTempDir() throws IOException
    {
-      File dir = File.createTempFile("mpxj", "tmp");
+      File dir = Files.createTempFile("mpxj", "tmp").toFile();
       delete(dir);
       mkdirs(dir);
       return dir;

programming_language: Java
filename: InputStreamHelper.java
change_type: ModificationType.MODIFY
diff: @@ -27,6 +27,7 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.file.Files;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipException;
 import java.util.zip.ZipInputStream;
@@ -49,7 +50,7 @@ public class InputStreamHelper
 
       try
       {
-         File file = File.createTempFile("mpxj", tempFileSuffix);
+         File file = Files.createTempFile("mpxj", tempFileSuffix).toFile();
          outputStream = new FileOutputStream(file);
          byte[] buffer = new byte[1024];
          while (true)

programming_language: Java
filename: CustomerDataTest.java
change_type: ModificationType.MODIFY
diff: @@ -174,7 +174,7 @@ public class CustomerDataTest
 
       // Accessing the database directly from (new) Google Drive is too slow.
       // Make a temporary local copy instead.
-      File file = File.createTempFile("primavera", "db");
+      File file = Files.createTempFile("primavera", "db").toFile();
       file.deleteOnExit();
       Files.copy(new File(m_primaveraFile).toPath(), file.toPath(), StandardCopyOption.REPLACE_EXISTING);
 
@@ -616,7 +616,7 @@ public class CustomerDataTest
 
       if (baselineFile.exists())
       {
-         File out = File.createTempFile("junit", suffix);
+         File out = Files.createTempFile("junit", suffix).toFile();
          writer.write(project, out);
          success = FileUtility.equals(baselineFile, out);
 

programming_language: Java
filename: LocaleTest.java
change_type: ModificationType.MODIFY
diff: @@ -26,6 +26,7 @@ package net.sf.mpxj.junit;
 import static net.sf.mpxj.junit.MpxjAssert.*;
 
 import java.io.File;
+import java.nio.file.Files;
 import java.util.Locale;
 
 import org.junit.Test;
@@ -64,7 +65,7 @@ public class LocaleTest
 
       File in = new File(MpxjTestData.filePath("legacy/sample.mpx"));
       ProjectFile mpx = reader.read(in);
-      File out = File.createTempFile("junit-" + locale.getLanguage(), ".mpx");
+      File out = Files.createTempFile("junit-" + locale.getLanguage(), ".mpx").toFile();
       writer.setLocale(locale);
       writer.write(mpx, out);
 

programming_language: Java
filename: BasicTest.java
change_type: ModificationType.MODIFY
diff: @@ -26,6 +26,7 @@ package net.sf.mpxj.junit.legacy;
 import static org.junit.Assert.*;
 
 import java.io.File;
+import java.nio.file.Files;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.Iterator;
@@ -74,7 +75,7 @@ public class BasicTest
    {
       File in = new File(MpxjTestData.filePath("legacy/sample.mpx"));
       ProjectFile mpx = new MPXReader().read(in);
-      File out = File.createTempFile("junit", ".mpx");
+      File out = Files.createTempFile("junit", ".mpx").toFile();
       MPXWriter writer = new MPXWriter();
       writer.setUseLocaleDefaults(false);
       writer.write(mpx, out);
@@ -93,7 +94,7 @@ public class BasicTest
    {
       File in = new File(MpxjTestData.filePath("legacy/sample1.xml"));
       ProjectFile xml = new MSPDIReader().read(in);
-      File out = File.createTempFile("junit", ".xml");
+      File out = Files.createTempFile("junit", ".xml").toFile();
       new MSPDIWriter().write(xml, out);
       boolean success = FileUtility.equals(in, out);
       assertTrue("Files are not identical", success);
@@ -110,7 +111,7 @@ public class BasicTest
    {
       File in = new File(MpxjTestData.filePath("legacy/sample1.mpx"));
       ProjectFile mpx = new MPXReader().read(in);
-      File out = File.createTempFile("junit", ".mpx");
+      File out = Files.createTempFile("junit", ".mpx").toFile();
       MPXWriter writer = new MPXWriter();
       writer.setUseLocaleDefaults(false);
       writer.write(mpx, out);
@@ -128,7 +129,7 @@ public class BasicTest
       File in = new File(MpxjTestData.filePath("legacy/empty.mpp"));
       ProjectFile mpx = new MPPReader().read(in);
       mpx.getProjectProperties().setCurrentDate(new SimpleDateFormat("dd/MM/yyyy").parse("01/03/2006"));
-      File out = File.createTempFile("junit", ".mpx");
+      File out = Files.createTempFile("junit", ".mpx").toFile();
       MPXWriter writer = new MPXWriter();
       writer.setUseLocaleDefaults(false);
       writer.write(mpx, out);
@@ -144,7 +145,7 @@ public class BasicTest
    {
       File in = new File(MpxjTestData.filePath("legacy/sample.mpx"));
       ProjectFile mpx = new MPXReader().read(in);
-      File out = File.createTempFile("junit", ".planner");
+      File out = Files.createTempFile("junit", ".planner").toFile();
       new PlannerWriter().write(mpx, out);
       //success = FileUtility.equals (in, out);
       //assertTrue ("Files are not identical", success);
@@ -267,7 +268,7 @@ public class BasicTest
    {
       File in = new File(MpxjTestData.filePath("legacy/sample98.mpp"));
       ProjectFile mpp = new MPPReader().read(in);
-      File out = File.createTempFile("junit", ".mpx");
+      File out = Files.createTempFile("junit", ".mpx").toFile();
       new MPXWriter().write(mpp, out);
       commonTests(mpp);
       out.deleteOnExit();
@@ -280,7 +281,7 @@ public class BasicTest
    {
       File in = new File(MpxjTestData.filePath("legacy/sample.mpp"));
       ProjectFile mpp = new MPPReader().read(in);
-      File out = File.createTempFile("junit", ".mpx");
+      File out = Files.createTempFile("junit", ".mpx").toFile();
       new MPXWriter().write(mpp, out);
       commonTests(mpp);
       out.deleteOnExit();
@@ -293,7 +294,7 @@ public class BasicTest
    {
       File in = new File(MpxjTestData.filePath("legacy/sample.xml"));
       ProjectFile xml = new MSPDIReader().read(in);
-      File out = File.createTempFile("junit", ".mpx");
+      File out = Files.createTempFile("junit", ".mpx").toFile();
       new MPXWriter().write(xml, out);
       commonTests(xml);
       out.deleteOnExit();
@@ -353,12 +354,12 @@ public class BasicTest
    {
       File in = new File(MpxjTestData.filePath("legacy/sample.mpp"));
       ProjectFile mpp = new MPPReader().read(in);
-      File out = File.createTempFile("junit", ".mpx");
+      File out = Files.createTempFile("junit", ".mpx").toFile();
       new MPXWriter().write(mpp, out);
 
       ProjectFile mpx = new MPXReader().read(out);
       out.deleteOnExit();
-      out = File.createTempFile("junit", ".xml");
+      out = Files.createTempFile("junit", ".xml").toFile();
       new MSPDIWriter().write(mpx, out);
       out.deleteOnExit();
    }
@@ -428,7 +429,7 @@ public class BasicTest
       task5.setStart(new Date());
       task5.setNotes(notes5);
 
-      File out = File.createTempFile("junit", ".mpx");
+      File out = Files.createTempFile("junit", ".mpx").toFile();
       new MPXWriter().write(file1, out);
 
       ProjectFile file2 = new MPXReader().read(out);
@@ -490,7 +491,7 @@ public class BasicTest
       resource5.setName("Test Resource 5");
       resource5.setNotes(notes5);
 
-      File out = File.createTempFile("junit", ".mpx");
+      File out = Files.createTempFile("junit", ".mpx").toFile();
       new MPXWriter().write(file1, out);
 
       ProjectFile file2 = new MPXReader().read(out);
@@ -524,7 +525,7 @@ public class BasicTest
    {
       File in = new File(MpxjTestData.filePath("legacy/bug1.mpp"));
       ProjectFile mpp = new MPPReader().read(in);
-      File out = File.createTempFile("junit", ".mpx");
+      File out = Files.createTempFile("junit", ".mpx").toFile();
       new MPXWriter().write(mpp, out);
       out.deleteOnExit();
    }
@@ -536,7 +537,7 @@ public class BasicTest
    {
       File in = new File(MpxjTestData.filePath("legacy/bug2.mpp"));
       ProjectFile mpp = new MPPReader().read(in);
-      File out = File.createTempFile("junit", ".mpx");
+      File out = Files.createTempFile("junit", ".mpx").toFile();
       new MPXWriter().write(mpp, out);
       out.deleteOnExit();
    }
@@ -563,7 +564,7 @@ public class BasicTest
    {
       File in = new File(MpxjTestData.filePath("legacy/bug4.mpp"));
       ProjectFile mpp = new MPPReader().read(in);
-      File out = File.createTempFile("junit", ".mpx");
+      File out = Files.createTempFile("junit", ".mpx").toFile();
       new MPXWriter().write(mpp, out.getAbsolutePath());
       out.deleteOnExit();
    }
@@ -896,7 +897,7 @@ public class BasicTest
       //
       // Write this out as an MSPDI file
       //
-      File out = File.createTempFile("junit", ".xml");
+      File out = Files.createTempFile("junit", ".xml").toFile();
       new MSPDIWriter().write(mpp, out);
 
       //
@@ -927,7 +928,7 @@ public class BasicTest
       ProjectFile xml = reader.read(in);
       validateAliases(xml);
 
-      File out = File.createTempFile("junit", ".xml");
+      File out = Files.createTempFile("junit", ".xml").toFile();
       writer.write(xml, out);
 
       xml = reader.read(out);
@@ -1247,7 +1248,7 @@ public class BasicTest
       //
       // Write the file
       //
-      File out = File.createTempFile("junit", ".mpx");
+      File out = Files.createTempFile("junit", ".mpx").toFile();
       new MPXWriter().write(file, out);
 
       //
@@ -1338,7 +1339,7 @@ public class BasicTest
       ProjectFile xml = reader.read(MpxjTestData.filePath("legacy/mspextattr.xml"));
       commonMspdiExtendedAttributeTests(xml);
 
-      File out = File.createTempFile("junit", ".xml");
+      File out = Files.createTempFile("junit", ".xml").toFile();
       writer.write(xml, out);
 
       xml = reader.read(out);
@@ -1404,7 +1405,7 @@ public class BasicTest
       // Write the file, re-read it and test to ensure that
       // the project properties have the expected values
       //
-      File out = File.createTempFile("junit", ".mpx");
+      File out = Files.createTempFile("junit", ".mpx").toFile();
       writer.write(mpx, out);
       mpx = reader.read(out);
       testProperties(mpx);
@@ -1435,7 +1436,7 @@ public class BasicTest
       // Write the file, re-read it and test to ensure that
       // the project properties have the expected values
       //
-      out = File.createTempFile("junit", ".xml");
+      out = Files.createTempFile("junit", ".xml").toFile();
       new MSPDIWriter().write(mpx, out);
 
       mpx = new MSPDIReader().read(out);
@@ -1512,13 +1513,13 @@ public class BasicTest
       ProjectFile xml = new MSPDIReader().read(MpxjTestData.filePath("legacy/mspdipriority.xml"));
       validatePriority(xml);
 
-      File out = File.createTempFile("junit", ".mpx");
+      File out = Files.createTempFile("junit", ".mpx").toFile();
       new MPXWriter().write(mpx, out);
       ProjectFile mpx2 = new MPXReader().read(out);
       validatePriority(mpx2);
       out.deleteOnExit();
 
-      out = File.createTempFile("junit", ".xml");
+      out = Files.createTempFile("junit", ".xml").toFile();
       new MSPDIWriter().write(mpx, out);
       ProjectFile xml3 = new MSPDIReader().read(out);
       validatePriority(xml3);
@@ -1720,7 +1721,7 @@ public class BasicTest
       //
       // Write the file and re-read it to ensure we get consistent results.
       //
-      File out = File.createTempFile("junit", ".mpx");
+      File out = Files.createTempFile("junit", ".mpx").toFile();
       new MPXWriter().write(mpp, out);
 
       ProjectFile mpx = new MPXReader().read(out);
@@ -1737,7 +1738,7 @@ public class BasicTest
    {
       File in = new File(MpxjTestData.filePath("legacy/calendarExceptions.mpx"));
       ProjectFile mpx = new MPXReader().read(in);
-      File out = File.createTempFile("junit", ".mpx");
+      File out = Files.createTempFile("junit", ".mpx").toFile();
       MPXWriter writer = new MPXWriter();
       writer.setUseLocaleDefaults(false);
       writer.write(mpx, out);

programming_language: Java