Skip to content

Commit

Permalink
vuln-fix: Temporary Directory Hijacking or Information Disclosure
Browse files Browse the repository at this point in the history
This fixes either Temporary Directory Hijacking, or Temporary Directory Local Information Disclosure.

Weakness: CWE-379: Creation of Temporary File in Directory with Insecure Permissions
Severity: High
CVSSS: 7.3
Detection: CodeQL & OpenRewrite (https://public.moderne.io/recipes/org.openrewrite.java.security.UseFilesCreateTempDirectory)

Reported-by: Jonathan Leitschuh <[email protected]>
Signed-off-by: Jonathan Leitschuh <[email protected]>

Bug-tracker: JLLeitschuh/security-research#10


Co-authored-by: Moderne <[email protected]>
  • Loading branch information
JLLeitschuh and TeamModerne committed Oct 4, 2022
1 parent 3ee64d0 commit 6911b1b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.text.BreakIterator;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -494,10 +495,8 @@ public File exportCasToFile(CAS aCas, SourceDocument aDocument, String aFileName
updateCasWithTagSet(exportCas, feature.getLayer().getName(), tagSet.getName());
}

File exportTempDir = createTempFile("webanno", "export");
File exportTempDir = Files.createTempDirectory("webanno" + "export").toFile();
try {
exportTempDir.delete();
exportTempDir.mkdirs();

AnalysisEngineDescription writer = aFormat
.getWriterDescription(aDocument.getProject(), exportTypeSystem, exportCas);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.List;

import org.apache.commons.io.FileUtils;
Expand Down Expand Up @@ -66,9 +67,7 @@ public File export(ProjectExportRequest aRequest, ProjectExportTaskMonitor aMoni
File exportFile = null;
File exportTempDir = null;
try {
exportTempDir = File.createTempFile("webanno", "export");
exportTempDir.delete();
exportTempDir.mkdirs();
exportTempDir = Files.createTempDirectory("webanno" + "export").toFile();

boolean curationDocumentExist = documentService.existsCurationDocument(project);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -158,9 +159,7 @@ public File exportProject(ProjectExportRequest aRequest, ProjectExportTaskMonito
File exportTempDir = null;
try {
// Directory to store source documents and annotation documents
exportTempDir = File.createTempFile("webanno-project", "export");
exportTempDir.delete();
exportTempDir.mkdirs();
exportTempDir = Files.createTempDirectory("webanno-project" + "export").toFile();

// Target file
File projectZipFile = new File(exportTempDir.getAbsolutePath() + ".zip");
Expand Down

0 comments on commit 6911b1b

Please sign in to comment.