Skip to content

Modernize and secure temp file creation#28

Closed
pixeebot[bot] wants to merge 1 commit intomainfrom
pixeebot/drip-2025-05-10-pixee-java/upgrade-tempfile-to-nio
Closed

Modernize and secure temp file creation#28
pixeebot[bot] wants to merge 1 commit intomainfrom
pixeebot/drip-2025-05-10-pixee-java/upgrade-tempfile-to-nio

Conversation

@pixeebot
Copy link
Copy Markdown

@pixeebot pixeebot bot commented May 10, 2025

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

I have additional improvements ready for this repo! If you want to see them, leave the comment:

@pixeebot next

... and I will open a new PR right away!

🧚🤖 Powered by Pixeebot

Feedback | Community | Docs | Codemod ID: pixee:java/upgrade-tempfile-to-nio

@pixeebot
Copy link
Copy Markdown
Author

pixeebot bot commented May 18, 2025

I'm confident in this change, but I'm not a maintainer of this project. Do you see any reason not to merge it?

If this change was not helpful, or you have suggestions for improvements, please let me know!

@pixeebot
Copy link
Copy Markdown
Author

pixeebot bot commented May 19, 2025

Just a friendly ping to remind you about this change. If there are concerns about it, we'd love to hear about them!

@pixeebot
Copy link
Copy Markdown
Author

pixeebot bot commented May 25, 2025

This change may not be a priority right now, so I'll close it. If there was something I could have done better, please let me know!

You can also customize me to make sure I'm working with you in the way you want.

@pixeebot pixeebot bot closed this May 25, 2025
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.

0 participants