Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Modernize and secure temp file creation#32

Open
pixeebot[bot] wants to merge 1 commit intomaster from
pixeebot/drip-2025年08月05日-pixee-java/upgrade-tempfile-to-nio
Open

Modernize and secure temp file creation #32
pixeebot[bot] wants to merge 1 commit intomaster from
pixeebot/drip-2025年08月05日-pixee-java/upgrade-tempfile-to-nio

Conversation

@pixeebot
Copy link

@pixeebot pixeebot bot commented Aug 5, 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

🧚🤖 Powered by Pixeebot

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

Copy link

sonarqubecloud bot commented Aug 5, 2025

Copy link
Author

pixeebot bot commented Aug 13, 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!

Copy link
Author

pixeebot bot commented Aug 14, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

0 participants

AltStyle によって変換されたページ (->オリジナル) /