-
Notifications
You must be signed in to change notification settings - Fork 2k
Java: CWE-378: Temp Directory Hijacking Race Condition Vulnerability #4473
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
ba727af
aea0170
545eb2c
253c96f
d9d5b67
1fc7629
b42ff13
20bd05b
442ef83
fbecfdd
8a7d64d
884db9e
6f4ed4b
03983f1
37b1e1d
ac8e1cc
84003c1
4b6d1a4
325d0e1
71f5fc5
140c66e
21bef99
407dd05
0f5a1e7
e7f016e
3a50253
cd3662c
a2a7c73
b412c7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -206,5 +206,21 @@ File safe15() throws IOException { | |
| throw new IOException(absolutePath); | ||
| } | ||
| } | ||
|
|
||
| File vulnerable4() throws IOException { | ||
| File temp = new File(System.getProperty("java.io.tmpdir")); | ||
| ensureDirectory(temp); | ||
| File workDir = File.createTempFile("test", "directory", temp); | ||
| if (!workDir.delete()) { | ||
| throw new IOException("Could not delete temp file: " + workDir.getAbsolutePath()); | ||
| } | ||
| ensureDirectory(workDir); | ||
| return temp; | ||
| } | ||
|
|
||
| private static void ensureDirectory(File dir) throws IOException { | ||
| if (!dir.mkdirs() && !dir.isDirectory()) { | ||
| throw new IOException("Mkdirs failed to create " + dir.toString()); | ||
| } | ||
| } | ||
|
Comment on lines
+210
to
+225
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before, when I wasn't using using |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be good to explain why check for
= 2, that is, to match the method creating a file in the default OS temp directory.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!