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

[SECURITY] Fix Temporary File Information Disclosure Vulnerability #150

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
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: JLLeitschuh/security-research#18


Co-authored-by: Moderne <team@moderne.io>
  • Loading branch information
JLLeitschuh and TeamModerne committed Nov 18, 2022
commit 56b27e2738c90ae85b69a2c4ec69916973dc9710
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.io.File;
import java.io.FileWriter;
import java.nio.file.Files;

import org.junit.Before;
import org.junit.Test;
Expand All @@ -42,7 +43,7 @@ public class ResourceContentProviderTest {

@Before
public void setup() throws Exception {
tmpFile = File.createTempFile("rcpt", ".txt");
tmpFile = Files.createTempFile("rcpt", ".txt").toFile();
tmpFile.deleteOnExit();
try (FileWriter writer = new FileWriter(tmpFile)) {
writer.write("test");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Field;
import java.nio.file.Files;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
Expand Down Expand Up @@ -306,7 +307,7 @@ private Injector createInjectorForJsonValue(final String jsonValue) throws IOExc

private Injector createInjectorForJsonValue(final String jsonValue,
final LegacyCapabilitiesProvisioning.LegacyProvisioningPropertiesHolder provisioningProperties) throws IOException {
final File tmpFile = File.createTempFile("capprovtest", "json");
final File tmpFile = Files.createTempFile("capprovtest", "json").toFile();
logger.trace("Writing serialized JSON {} to file {}", jsonValue, tmpFile);
tmpFile.deleteOnExit();
try (FileWriter writer = new FileWriter(tmpFile)) {
Expand Down