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

Modernize and secure temp file creation #188

Merged

Conversation

pixeebot[bot]
Copy link
Contributor

@pixeebot pixeebot bot commented Oct 2, 2023

This change replaces the usage of java.io.File#createTempFile with java.nio.file.Files#createTempFile which has more secure attributes.

The java.io.File#createTempFile() method creates a file that is world-readable and world-writeable, which is almost never necessary. Also, the file created is placed in a predictable directory (e.g., /tmp). Having predictable file names, locations, and will lead to many types of vulnerabilities. History has shown that this insecure pattern can lead to information leakage, privilege escalation and even code execution.

Our changes look something like this:

+  import java.nio.file.Files;
   ...
-  File txtFile = File.createTempFile("acme", ".txt");
+  File txtFile = Files.createTempFile("acme", ".txt").toFile();
More reading

Powered by: pixeebot (codemod ID: pixee:java/upgrade-tempfile-to-nio)

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@nahsra nahsra self-requested a review October 3, 2023 13:38
@nahsra nahsra merged commit a9d1a35 into main Oct 3, 2023
3 of 4 checks passed
@nahsra nahsra deleted the pixeebot/drip-2023-10-02-pixee-java/upgrade-tempfile-to-nio branch October 3, 2023 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants