-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from JLLeitschuh/feat/temporary-file-local-inf…
…ormation-disclosure
- Loading branch information
Showing
5 changed files
with
122 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
1 change: 1 addition & 0 deletions
1
bulk-pr-generation/temporary-file-local-information-disclosure/branch_name.txt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1 @@ | ||
fix/JLL/temporary_file_local_information_disclosure |
15 changes: 15 additions & 0 deletions
15
bulk-pr-generation/temporary-file-local-information-disclosure/commit.txt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,15 @@ | ||
vuln-fix: Temporary File Information Disclosure | ||
|
||
This fixes temporary file information disclosure vulnerability due to the use | ||
of the vulnerable `File.createTempFile()` method. The vulnerability is fixed by | ||
using the `Files.createTempFile()` method which sets the correct posix permissions. | ||
|
||
Weakness: CWE-377: Insecure Temporary File | ||
Severity: Medium | ||
CVSSS: 5.5 | ||
Detection: CodeQL & OpenRewrite (https://public.moderne.io/recipes/org.openrewrite.java.security.SecureTempFileCreation) | ||
|
||
Reported-by: Jonathan Leitschuh <[email protected]> | ||
Signed-off-by: Jonathan Leitschuh <[email protected]> | ||
|
||
Bug-tracker: https://github.com/JLLeitschuh/security-research/issues/18 |
100 changes: 100 additions & 0 deletions
100
bulk-pr-generation/temporary-file-local-information-disclosure/pr_message.md
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,100 @@ | ||
[SECURITY] Fix Temporary File Information Disclosure Vulnerability | ||
|
||
# Security Vulnerability Fix | ||
|
||
This pull request fixes a Temporary File 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 posix permissions are set. | ||
|
||
This PR was generated because a call to `File.createTempFile(..)` was detected in this repository in a way that makes this project vulnerable. | ||
|
||
### Impact | ||
|
||
Information in this file is visible to other local users, allowing a malicious actor co-resident on the same machine to view potentially sensitive files. | ||
|
||
#### Other Examples | ||
|
||
- [CVE-2020-15250](https://github.com/advisories/GHSA-269g-pwp5-87pp) - junit-team/junit | ||
- [CVE-2021-21364](https://github.com/advisories/GHSA-hpv8-9rq5-hq7w) - swagger-api/swagger-codegen | ||
- [CVE-2022-24823](https://github.com/advisories/GHSA-5mcr-gq6c-3hq2) - netty/netty | ||
- [CVE-2022-24823](https://github.com/advisories/GHSA-269q-hmxg-m83q) - netty/netty | ||
|
||
# The Fix | ||
|
||
The fix has been to convert the logic above to use the following API that was introduced in Java 1.7. | ||
|
||
```java | ||
File tmpDir = Files.createTempFile("temp dir").toFile(); | ||
``` | ||
|
||
The API both creates the file securely, ie. with a random, non-conflicting name, with file permissions that only allow the currently executing user to read or write the contents of this file. | ||
|
||
# :arrow_right: Vulnerability Disclosure :arrow_left: | ||
|
||
:wave: 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! | ||
|
||
1. Is the vulnerable code only in tests or example code? No disclosure required! | ||
2. Is the vulnerable code in code shipped to your end users? Vulnerability disclosure is probably required! | ||
|
||
## Vulnerability Disclosure How-To | ||
|
||
You have a few options options to perform vulnerability disclosure. However, I'd like to suggest the following 2 options: | ||
|
||
1. Request a CVE number from GitHub by creating a repository-level [GitHub Security Advisory](https://docs.github.com/en/code-security/repository-security-advisories/creating-a-repository-security-advisory). This has the advantage that, if you provide sufficient information, GitHub will automatically generate Dependabot alerts for your downstream consumers, resolving this vulnerability more quickly. | ||
2. Reach out to the team at Snyk to assist with CVE issuance. They can be reached at the [Snyk's Disclosure Email](mailto:[email protected]). | ||
|
||
## Detecting this and Future Vulnerabilities | ||
|
||
This vulnerability was automatically detected by GitHub's CodeQL using this [CodeQL Query](https://codeql.github.com/codeql-query-help/java/java-local-temp-file-or-directory-information-disclosure/). | ||
|
||
You can automatically detect future vulnerabilities like this by enabling the free (for open-source) [GitHub Action](https://github.com/github/codeql-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](https://github.com/openrewrite/rewrite) [refactoring recipe](https://docs.openrewrite.org/), which was lovingly hand crafted to bring this security fix to your repository. | ||
|
||
The source code that generated this PR can be found here: | ||
[SecureTempFileCreation](https://github.com/openrewrite/rewrite-java-security/blob/main/src/main/java/org/openrewrite/java/security/SecureTempFileCreation.java) | ||
|
||
## 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: | ||
|
||
``` | ||
User-agent: JLLeitschuh/security-research | ||
Disallow: * | ||
``` | ||
|
||
This bot will respect the [ROBOTS.txt](https://moz.com/learn/seo/robotstxt) format for future contributions. | ||
|
||
Alternatively, if this project is no longer actively maintained, consider [archiving](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-archiving-repositories) 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. | ||
|
||
> The meaning of a signoff depends on the project, but it typically certifies that committer has the rights to submit this work under the same license and agrees to a Developer Certificate of Origin | ||
> (see [https://developercertificate.org/](https://developercertificate.org/) for more information). | ||
> | ||
> \- [Git Commit Signoff documentation](https://developercertificate.org/) | ||
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](https://www.moderne.io/), 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: https://github.com/JLLeitschuh/security-research/issues/18 |
1 change: 1 addition & 0 deletions
1
bulk-pr-generation/temporary-file-local-information-disclosure/recipe.txt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1 @@ | ||
org.openrewrite.java.security.SecureTempFileCreation |