-
Notifications
You must be signed in to change notification settings - Fork 379
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
[SECURITY] Fix Temporary Directory Hijacking or Information Disclosure Vulnerability #389
Conversation
dd96013
to
84b4178
Compare
This fixes either Temporary Directory Hijacking, or Temporary Directory Local Information Disclosure. Weakness: CWE-379: Creation of Temporary File in Directory with Insecure Permissions Severity: High CVSSS: 7.3 Detection: CodeQL & OpenRewrite (https://public.moderne.io/recipes/org.openrewrite.java.security.UseFilesCreateTempDirectory) Reported-by: Jonathan Leitschuh <[email protected]> Signed-off-by: Jonathan Leitschuh <[email protected]> Bug-tracker: JLLeitschuh/security-research#10 Co-authored-by: Moderne <[email protected]>
84b4178
to
ea9fbe3
Compare
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.
Looking closely at the identified problem, I don't think this is actually a security issue, as the original code does check the return code of directory.delete()
and directory.mkdirs()
. I suspect the vulnerability scanning code failed to handle the assertTrue
statements in the original code.
Having said that, I'm going to approve this change, as I think the new code is cleaner, and we can delete the assertTrue
lines after the creation of the temp path. I'm assuming after 2 years that no-one will be expecting a request to change the PR, so I'm going to accept this PR and put in a new commit to clean up.
@tumbarumba I agree that this is not a security issue. The asserts already fixed the first of the two mentioned vulnerabilities. On the other hand, the Information Disclosure still was in action. But from the users of the Hamcrest library point of view, this code is not part of the Hamcrest and so could not cause any security vulnerability. Finally, the fix secures only the test execution of the Hamcrest itself. In the case of an open-source project sounds weird that the unit test put sensitive information into the temporary directory. Everything can be read from the source code of the test. |
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [org.hamcrest:hamcrest-library](http://hamcrest.org/JavaHamcrest/) ([source](https://github.com/hamcrest/JavaHamcrest)) | test | major | `2.2` -> `3.0` | --- ### Release Notes <details> <summary>hamcrest/JavaHamcrest (org.hamcrest:hamcrest-library)</summary> ### [`v3.0`](https://github.com/hamcrest/JavaHamcrest/blob/HEAD/CHANGES.md#Version-30-1st-August-2024) [Compare Source](hamcrest/JavaHamcrest@v2.2...v3.0) ##### Breaking Changes - From version 3.0, the jar distributed to Maven Central is now compiled to Java 1.8 bytecode, and is not compatible with previous versions of Java. See [Issue #​331](hamcrest/JavaHamcrest#331) and [PR #​411](hamcrest/JavaHamcrest#411) for details. Developers who use Java 1.7 earlier can still depend upon `hamcrest-2.2.jar`. ##### Improvements - FileMatchersTest simplification ([PR #​389](hamcrest/JavaHamcrest#389)) - License cleanup ([PR #​414](hamcrest/JavaHamcrest#414), [PR #​415](hamcrest/JavaHamcrest#415), see also [#​264](hamcrest/JavaHamcrest#264), [#​355](hamcrest/JavaHamcrest#355), [#​396](hamcrest/JavaHamcrest#396 [#​399](hamcrest/JavaHamcrest#399)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or rename PR to start with "rebase!". 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
Security Vulnerability Fix
This pull request fixes either 1.) Temporary Directory Hijacking Vulnerability, or 2.) Temporary Directory Information Disclosure Vulnerability, which existed in this project.
Preamble
The system temporary directory is shared between all users on most unix-like systems (not MacOS, or Windows). Thus, code interacting with the system temporary directory must be careful about file interactions in this directory, and must ensure that the correct file permissions are set.
This PR was generated because the following chain of calls was detected in this repository in a way that leaves this project vulnerable.
File.createTempFile(..)
->file.delete()
-> eitherfile.mkdir()
orfile.mkdirs()
.Impact
This vulnerability can have one of two impacts depending upon which vulnerability it is.
Temporary Directory Hijacking
This vulnerability exists because the return value from
file.mkdir()
orfile.mkdirs()
is not checked to determine if the call succeeded. Say, for example, because another local user created the directory before this process.Other Examples
Temporary Directory Information Disclosure
This vulnerability exists because, although the return values of
file.mkdir()
orfile.mkdirs()
are correctly checked, the permissions of the directory that is created follows the default systemuname
settings. Thus, the directory is created with everyone-readable permissions. As such, any files/directories written into this directory are viewable by all other local users on the system.Other Examples
The Fix
The fix has been to convert the logic above to use the following API that was introduced in Java 1.7.
The API both created the directory securely, ie with a random, non-conflicting name, with directory permissions that only allow the currently executing user to read or write the contents of this directory.
➡️ Vulnerability Disclosure ⬅️
👋 Vulnerability disclosure is a super important part of the vulnerability handling process and should not be skipped! This may be completely new to you, and that's okay, I'm here to assist!
First question, do we need to perform vulnerability disclosure? It depends!
Vulnerability Disclosure How-To
You have a few options options to perform vulnerability disclosure. However, I'd like to suggest the following 2 options:
Detecting this and Future Vulnerabilities
This vulnerability was automatically detected by GitHub's LGTM.com using this CodeQL Query.
You can automatically detect future vulnerabilities like this by enabling the free (for open-source) GitHub Action.
I'm not an employee of GitHub, I'm simply an open-source security researcher.
Source
This contribution was automatically generated with an OpenRewrite refactoring recipe, which was lovingly hand crafted to bring this security fix to your repository.
The source code that generated this PR can be found here:
UseFilesCreateTempDirectory
Opting-Out
If you'd like to opt-out of future automated security vulnerability fixes like this, please consider adding a file called
.github/GH-ROBOTS.txt
to your repository with the line:This bot will respect the ROBOTS.txt format for future contributions.
Alternatively, if this project is no longer actively maintained, consider archiving the repository.
CLA Requirements
This section is only relevant if your project requires contributors to sign a Contributor License Agreement (CLA) for external contributions.
It is unlikely that I'll be able to directly sign CLAs. However, all contributed commits are already automatically signed-off.
If signing your organization's CLA is a strict-requirement for merging this contribution, please feel free to close this PR.
Sponsorship & Support
This contribution is sponsored by HUMAN Security Inc. and the new Dan Kaminsky Fellowship, a fellowship created to celebrate Dan's memory and legacy by funding open-source work that makes the world a better (and more secure) place.
This PR was generated by Moderne, a free-for-open source SaaS offering that uses format-preserving AST transformations to fix bugs, standardize code style, apply best practices, migrate library versions, and fix common security vulnerabilities at scale.
Tracking
All PR's generated as part of this fix are tracked here: JLLeitschuh/security-research#10