GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Java: CWE-200: Temp directory local information disclosure vulnerability by JLLeitschuh · Pull Request #4388 · github/codeql

Conversation

@JLLeitschuh

@JLLeitschuh JLLeitschuh commented Oct 2, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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--`
    }
}

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

daniel-beck reacted with confused emoji
All reactions
  • 😕 1 reaction
@github-actions github-actions Bot added the Java label Oct 2, 2020
@JLLeitschuh JLLeitschuh mentioned this pull request Oct 2, 2020
CVE-2020-8908: Files::createTempDir local information disclosure vulnerability google/guava#4011
Closed
@JLLeitschuh
JLLeitschuh force-pushed the feat/JLL/java/CWE-200_temp_directory_local_information_disclosure branch from 7cdf997 to d53d77c Compare October 2, 2020 18:53
aibaars
aibaars reviewed Oct 8, 2020
View reviewed changes
Comment thread java/ql/src/Security/CWE/CWE-200/TempDirLocalInformationDisclosure1.ql Outdated
* @kind problem
* @problem.severity warning
* @precision very-high
* @id java/local-information-disclosure

@aibaars aibaars Oct 8, 2020

Copy link
Copy Markdown
Contributor

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.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@JLLeitschuh JLLeitschuh Jan 23, 2021

Copy link
Copy Markdown
Contributor Author

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.

Fixed, I think

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
aibaars
aibaars reviewed Oct 8, 2020
View reviewed changes
Comment thread java/ql/src/Security/CWE/CWE-200/TempDirLocalInformationDisclosure2.ql Resolved

Uh oh!

There was an error while loading. Please reload this page.

@aibaars

aibaars commented Oct 8, 2020

Copy link
Copy Markdown
Contributor

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

  • apache/ant@9c1f4d9
  • apache/ant@a8645a1

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JLLeitschuh JLLeitschuh mentioned this pull request Oct 12, 2020
Java: Track taint through java.io.File constructor and #toURI; URI#toURL #4457
Merged
@JLLeitschuh

JLLeitschuh commented Oct 12, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@melloware

melloware commented Oct 12, 2020

Copy link
Copy Markdown

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JLLeitschuh

JLLeitschuh commented Oct 12, 2020

Copy link
Copy Markdown
Contributor Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@melloware

melloware commented Oct 12, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JLLeitschuh

JLLeitschuh commented Oct 12, 2020

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JLLeitschuh
JLLeitschuh commented Oct 14, 2020
View reviewed changes
Comment thread java/ql/src/Security/CWE/CWE-200/TempDirLocalInformationDisclosure2.ql Resolved

Uh oh!

There was an error while loading. Please reload this page.

aibaars
aibaars reviewed Oct 14, 2020
View reviewed changes
Comment thread java/ql/src/Security/CWE/CWE-200/TempDirLocalInformationDisclosure2.ql Outdated
Comment on lines +36 to +32
exists(MethodAccess ma |
ma.getMethod() instanceof MethodFileSystemFileCreation and
ma.getQualifier() = this.asExpr()
)

@aibaars aibaars Oct 14, 2020

Copy link
Copy Markdown
Contributor

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.

You could write:

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@JLLeitschuh JLLeitschuh Jan 23, 2021

Copy link
Copy Markdown
Contributor Author

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.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@JLLeitschuh JLLeitschuh Jan 23, 2021

Copy link
Copy Markdown
Contributor Author

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.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread java/ql/src/Security/CWE/CWE-200/TempDirLocalInformationDisclosure2.ql Resolved

Uh oh!

There was an error while loading. Please reload this page.

@JLLeitschuh

JLLeitschuh commented Nov 10, 2020

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.

intrigus-lgtm reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JLLeitschuh
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
@JLLeitschuh JLLeitschuh mentioned this pull request Jan 2, 2021
Add MethodAccessSystemGetProperty predicate #4898
Merged
@smowton smowton self-assigned this Jan 4, 2021
@JLLeitschuh
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
@JLLeitschuh

JLLeitschuh commented Jan 23, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Test run of this query:

  • Method Call: https://lgtm.com/query/3077692672321886364/
  • Path: https://lgtm.com/query/5276757681085693414/
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the documentation label Jan 23, 2021
@JLLeitschuh

JLLeitschuh commented Jan 23, 2021

Copy link
Copy Markdown
Contributor Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@aibaars

aibaars commented Jan 25, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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 ;-)

JLLeitschuh reacted with laugh emoji
All reactions
  • 😄 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JLLeitschuh

JLLeitschuh commented Jan 25, 2021

Copy link
Copy Markdown
Contributor Author

Good point 😂

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

smowton commented Jan 27, 2021

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@smowton
Apply suggestions from code review
7965459
smowton
smowton previously approved these changes Feb 8, 2022
View reviewed changes
aschackmull
aschackmull previously approved these changes Feb 8, 2022
View reviewed changes
@smowton
Fix test requirements, formatting
a6596ea
@smowton
smowton dismissed stale reviews from aschackmull and themself via a6596ea February 8, 2022 12:02
@JLLeitschuh

JLLeitschuh commented Feb 8, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

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

  • https://lgtm.com/query/8810980313419129810/
    There is a vulnerability here, but it's being incorrectly identified around the reason.

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
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JLLeitschuh
Consider calls to setReadable(false, false) then setReadable(true, tr…
7f46640
…ue) to be safe
@smowton

smowton commented Feb 9, 2022

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

smowton
smowton reviewed Feb 9, 2022
View reviewed changes
Comment thread java/ql/src/Security/CWE/CWE-200/TempDirLocalInformationDisclosure.ql Resolved

Uh oh!

There was an error while loading. Please reload this page.

@JLLeitschuh

JLLeitschuh commented Feb 9, 2022

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)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JLLeitschuh and others added 2 commits February 9, 2022 10:07
@JLLeitschuh @smowton
Update java/ql/src/Security/CWE/CWE-200/TempDirLocalInformationDisclo…
787e3da
…sure.ql

Co-authored-by: Chris Smowton <[email protected]>
@JLLeitschuh
Fix FP from mkdirs call on exact temp directory
49a7367
@JLLeitschuh

JLLeitschuh commented Feb 9, 2022

Copy link
Copy Markdown
Contributor Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JLLeitschuh
JLLeitschuh requested a review from smowton February 9, 2022 17:34
smowton
smowton reviewed Feb 9, 2022
View reviewed changes
Comment thread java/ql/src/Security/CWE/CWE-200/TempDirLocalInformationDisclosure.ql Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread java/ql/src/Security/CWE/CWE-200/TempDirUtils.qll Resolved

Uh oh!

There was an error while loading. Please reload this page.

@JLLeitschuh @smowton
Apply suggestions from code review
bafcce1
Co-authored-by: Chris Smowton <[email protected]>
@JLLeitschuh

JLLeitschuh commented Feb 10, 2022

Copy link
Copy Markdown
Contributor Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@smowton

smowton commented Feb 10, 2022

Copy link
Copy Markdown
Contributor

There's a real test failure to fix

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@felicitymay felicitymay added the ready-for-doc-review This PR requires and is ready for review from the GitHub docs team. label Feb 10, 2022
@JLLeitschuh
Fix test failure for TempDirLocalInformationDisclosure
eee521e
@JLLeitschuh

JLLeitschuh commented Feb 10, 2022

Copy link
Copy Markdown
Contributor Author

@smowton indeed! Fixed that. Thanks!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

felicitymay
felicitymay reviewed Feb 10, 2022
View reviewed changes

@felicitymay felicitymay left a comment

Copy link
Copy Markdown
Contributor

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.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread java/ql/src/Security/CWE/CWE-200/TempDirLocalInformationDisclosure.qhelp Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread java/ql/src/Security/CWE/CWE-200/TempDirLocalInformationDisclosure.ql Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread java/ql/src/Security/CWE/CWE-200/TempDirLocalInformationDisclosure.ql Outdated
@@ -0,0 +1,258 @@
/**
* @name Temporary Directory Local information disclosure

@felicitymay felicitymay Feb 10, 2022

Copy link
Copy Markdown
Contributor

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.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread java/ql/src/change-notes/2022-02-04-local-temp-file-or-directory-information-disclosure.md Outdated
---
category: newQuery
---
* A new query titled "Temporary directory Local information disclosure" (`java/local-temp-file-or-directory-information-disclosure`) has been added.

@felicitymay felicitymay Feb 10, 2022

Copy link
Copy Markdown
Contributor

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.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread java/ql/src/Security/CWE/CWE-200/TempDirLocalInformationDisclosure.qhelp Resolved

Uh oh!

There was an error while loading. Please reload this page.

JLLeitschuh and others added 4 commits February 14, 2022 11:00
@JLLeitschuh
Fix implicit 'this' usage
7dee22a
@JLLeitschuh @felicitymay
Apply suggestions from code review
bb580dd
Co-authored-by: Felicity Chapman <[email protected]>
@JLLeitschuh @felicitymay
Apply suggestions from code review
76964d5
Co-authored-by: Felicity Chapman <[email protected]>
@JLLeitschuh
Review feedback and improve temp dir vulnerable/safe code sugestion
2048aed
smowton
smowton approved these changes Feb 14, 2022
View reviewed changes
@smowton
smowton merged commit 0bf6c83 into github:main Feb 14, 2022
@JLLeitschuh

JLLeitschuh commented 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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

@aschackmull aschackmull aschackmull left review comments
@aibaars aibaars Awaiting requested review from aibaars
+2 more reviewers
@felicitymay felicitymay felicitymay left review comments
@smowton smowton smowton approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@aschackmull aschackmull

Labels

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

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

7 participants

@JLLeitschuh @aibaars @melloware @smowton @aschackmull @intrigus-lgtm @felicitymay
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.