← 返回首页
Java: CWE-200: Temp directory local information disclosure vulnerability by JLLeitschuh · Pull Request #4388 · github/codeql · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

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

Provide feedback

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

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

Java: CWE-200: Temp directory local information disclosure vulnerability#4388

Merged
smowton merged 39 commits into
github:mainfrom
JLLeitschuh:feat/JLL/java/CWE-200_temp_directory_local_information_disclosure
Feb 14, 2022
Merged

Java: CWE-200: Temp directory local information disclosure vulnerability#4388
smowton merged 39 commits into
github:mainfrom
JLLeitschuh:feat/JLL/java/CWE-200_temp_directory_local_information_disclosure

Conversation

Copy link
Copy Markdown
Contributor

JLLeitschuh commented Oct 2, 2020
edited
Loading

This vulnerability detects the use of the local temporary directory in ways that potentially expose sensitive information to other users.

Some examples

public class TempDirUsageVulnerable { void exampleVulnerable() { File temp1 = File.createTempFile("random", ".txt"); // BAD: File has permissions `-rw-r--r--` File temp2 = File.createTempFile("random", "file", null); // BAD: File has permissions `-rw-r--r--` File systemTempDir = new File(System.getProperty("java.io.tmpdir")); File temp3 = File.createTempFile("random", "file", systemTempDir); // BAD: File has permissions `-rw-r--r--` File tempDir = com.google.common.io.Files.createTempDir(); // BAD: CVE-2020-8908: Directory has permissions `drwxr-xr-x` new File(System.getProperty("java.io.tmpdir"), "/child").mkdir(); // BAD: Directory has permissions `-rw-r--r--` File tempDirChildFile = new File(System.getProperty("java.io.tmpdir"), "/child-create-file.txt"); Files.createFile(tempDirChildFile.toPath()); // BAD: File has permissions `-rw-r--r--` } }

* @kind problem
* @problem.severity warning
* @precision very-high
* @id java/local-information-disclosure
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

This id is rather generic. Could you make it a bit more specific to this query?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

Fixed, I think

Comment thread java/ql/src/Security/CWE/CWE-200/TempDirLocalInformationDisclosure2.ql Outdated Show resolved Hide resolved
Copy link
Copy Markdown
Contributor

aibaars commented Oct 8, 2020

For reference I think Apache Ant had a similar vulnerability CVE-2020-1945. I think this was addressed by

You might want to check your query on databases built from those commits and their parents.

Copy link
Copy Markdown
Contributor Author

JLLeitschuh commented Oct 12, 2020
edited
Loading

Here's one that I found that was just disclosed.
GHSA-269g-pwp5-87pp

Copy link
Copy Markdown

@JLLeitschuh So if Junit 4.13.1 can patch this fix why can't Guava?

Copy link
Copy Markdown
Contributor Author

@melloware 🤷‍♂️ bring it up with the Guava & Google team. There's only so much I can do.

Copy link
Copy Markdown

melloware commented Oct 12, 2020
edited
Loading

Can we submit a PR against that ticket for review making the same fix Junit did?

Copy link
Copy Markdown
Contributor Author

You can always submit a PR, I don't know if the Google team will accept it thought. I'd advise that you ask them if they'd consider accepting a PR on the existing issue:

google/guava#4011

It's probably not that useful to have this discussion here, on this unrelated issue.

Comment thread java/ql/src/Security/CWE/CWE-200/TempDirLocalInformationDisclosure2.ql Outdated Show resolved Hide resolved
Comment on lines +36 to +32
exists(MethodAccess ma |
ma.getMethod() instanceof MethodFileSystemFileCreation and
ma.getQualifier() = this.asExpr()
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

You could write:

Suggested change
exists(MethodAccess ma |
ma.getMethod() instanceof MethodFileSystemFileCreation and
ma.getQualifier() = this.asExpr()
)
exists(MethodFileSystemFileCreation ma |
ma.getQualifier() = this.asExpr()
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

This is not quite right. MethodFileSystemFileCreation is a Method not a MethodAccess

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

Yea, I don't think I can change this to be simpler at all.

Comment thread java/ql/src/Security/CWE/CWE-200/TempDirLocalInformationDisclosure2.ql Outdated Show resolved Hide resolved
Copy link
Copy Markdown
Contributor Author

There are some outstanding disclosures and CVES from this query. Hence why development is kinda frozen. I'm still leveraging it to report vulns.

JLLeitschuh force-pushed the feat/JLL/java/CWE-200_temp_directory_local_information_disclosure branch from 1b216f8 to b1aeb99 Compare December 8, 2020 20:42
smowton self-assigned this Jan 4, 2021
JLLeitschuh force-pushed the feat/JLL/java/CWE-200_temp_directory_local_information_disclosure branch from e53cfd8 to 6deb3d8 Compare January 23, 2021 17:49
Copy link
Copy Markdown
Contributor Author

JLLeitschuh commented Jan 23, 2021
edited
Loading

Test run of this query:

Copy link
Copy Markdown
Contributor Author

This PR is now in a "I think I'm happy with it, please review" state. 😃

Copy link
Copy Markdown
Contributor

aibaars commented Jan 25, 2021
edited
Loading

This PR is now in a "I think I'm happy with it, please review" state.

In that case you might want to hit the Ready for review button to change from Draft to Review state ;-)

Copy link
Copy Markdown
Contributor Author

Good point 😂

JLLeitschuh marked this pull request as ready for review January 25, 2021 14:56
JLLeitschuh requested review from a team and felicitymay as code owners January 25, 2021 14:56
smowton assigned aibaars and unassigned smowton Jan 27, 2021
Copy link
Copy Markdown
Contributor

smowton commented Jan 27, 2021

Assigned @aibaars since he has been reviewing this and moved to In Progress state

120 hidden items Load more…
smowton previously approved these changes Feb 8, 2022
aschackmull previously approved these changes Feb 8, 2022
smowton dismissed stale reviews from aschackmull and themself via a6596ea February 8, 2022 12:02
Copy link
Copy Markdown
Contributor Author

JLLeitschuh commented Feb 8, 2022
edited
Loading

False positives this is finding (the first path). However, other paths are valid.

To simplify, the vulnerability being identified here is because of the following:

new File(System.getProperty("java.io.tmpdir")).mkdirs(); // Not really a vulnerability technically

This doesn't seem like a vulnerability.

However, the following is information disclosure of the file's name:

File tempDir = new File(System.getProperty("java.io.tmpdir")); tempDir.mkdirs(); File tempFile = new File (tempDir, [USER_INPUT]); // vulnerability tempFile.createFile(); // vulnerability

Copy link
Copy Markdown
Contributor

smowton commented Feb 9, 2022

Looks like you're still tweaking this; let me know when you're done?

Comment thread java/ql/src/Security/CWE/CWE-200/TempDirLocalInformationDisclosure.ql Outdated Show resolved Hide resolved
Copy link
Copy Markdown
Contributor Author

Looks like you're still tweaking this; let me know when you're done?

I'm wondering if you have any insights into how to fix the problem I described here:

#4388 (comment)

Copy link
Copy Markdown
Contributor Author

I think I have a fix here that I'm happy with:
49a7367

JLLeitschuh requested a review from smowton February 9, 2022 17:34
Comment thread java/ql/src/Security/CWE/CWE-200/TempDirLocalInformationDisclosure.ql Outdated Show resolved Hide resolved
Comment thread java/ql/src/Security/CWE/CWE-200/TempDirUtils.qll Outdated Show resolved Hide resolved
Co-authored-by: Chris Smowton <smowton@github.com>
Copy link
Copy Markdown
Contributor Author

@smowton I'm happy with this PR as-is

Copy link
Copy Markdown
Contributor

smowton commented Feb 10, 2022

There's a real test failure to fix

felicitymay added the ready-for-doc-review This PR requires and is ready for review from the GitHub docs team. label Feb 10, 2022
Copy link
Copy Markdown
Contributor Author

@smowton indeed! Fixed that. Thanks!

Copy link
Copy Markdown
Contributor

felicitymay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

Thanks for writing help for your query. A few minor comments, but generally looking good 🙂

Comment thread java/ql/src/Security/CWE/CWE-200/TempDirLocalInformationDisclosure.ql Outdated Show resolved Hide resolved
@@ -0,0 +1,258 @@
/**
* @name Temporary Directory Local information disclosure
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

I'm wondering if this might be clearer. The query name should be in sentence case.

Suggested change
* @name Temporary Directory Local information disclosure
* @name Local information disclosure in a temporary directory

---
category: newQuery
---
* A new query titled "Temporary directory Local information disclosure" (`java/local-temp-file-or-directory-information-disclosure`) has been added.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

If we change the name of the query, we'd also need to update it here.

Comment thread java/ql/src/Security/CWE/CWE-200/TempDirLocalInformationDisclosure.qhelp Outdated Show resolved Hide resolved
JLLeitschuh and others added 4 commits February 14, 2022 11:00
smowton merged commit 0bf6c83 into github:main Feb 14, 2022
Copy link
Copy Markdown
Contributor Author

Amazing! Very happy this is finally merged. Only took me ~1.3 years to get it finished 😆

Follow-up that adds OS specific guards: #8032

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Java ready-for-doc-review This PR requires and is ready for review from the GitHub docs team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants

Footer

© 2026 GitHub, Inc.