Open JLLeitschuh opened 1 year ago
Thanks for the heads up, but that particular line is rarely used. Further, upon investigating the code that is actually often used to create (temporary) files, mainly FileOutputStream(), almost all of them end up creating files that have 644 permissions. For this fix to make sense, we should first take care of these other cases, or we risk giving users a false sense of security.
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 to local information disclosure. With the default uname configuration,File.createTempFile(..)
creates a file with the permissions-rw-r--r--
. This means that any other user on the system can read the contents of this file.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
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 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. By default,
Files.createTempFile("temp dir")
will create a file with the permissions-rw-------
, which only allows the user that created the file to view/write the file contents.: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!
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 CodeQL 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: SecureTempFileCreation
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: https://github.com/JLLeitschuh/security-research/issues/18