fix(security): set restrictive permissions (0o600) on background process log files#26913
fix(security): set restrictive permissions (0o600) on background process log files#26913Vist233 wants to merge 2 commits into
Conversation
…ess log files Background process log files were created via fs.createWriteStream without an explicit mode, causing them to inherit the process umask (typically 0o022), resulting in world-readable files (0o644). This allows other users on the system to read sensitive command output stored in background logs. While the parent directory is created with 0o700, the files themselves must also be explicitly restricted as a defense-in-depth measure. Fixes google-gemini#26779
Verify that fs.createWriteStream is called with mode 0o600 when backgrounding a process, ensuring log files are never created world-readable regardless of the process umask. Related to google-gemini#26779
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request improves the security posture of background process logging by ensuring that log files are created with restrictive owner-only permissions. By explicitly setting the file mode, the application avoids relying on potentially insecure default umask settings, ensuring sensitive output remains protected. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request enhances security by ensuring that background log files are created with restrictive permissions (0o600). It updates the ShellExecutionService to pass the mode option to fs.createWriteStream and adds a corresponding unit test to verify this behavior. I have no feedback to provide.
Summary
Background process log files were created via
fs.createWriteStreamwithout anexplicit
mode, causing them to inherit the process umask (typically0o022).On a standard Linux/macOS system this results in
0o644(rw-r--r--) —world-readable — even though the parent directory is correctly restricted to
0o700.This PR fixes the issue by explicitly passing
mode: 0o600tocreateWriteStream, ensuring log files are always created with owner-onlyread/write permissions regardless of the environment's umask.
Details
The root cause is a single missing option in
ShellExecutionService.background():Why
0o600?0o700policy: owner-only access.rw-), but no execute bit.modeprevents the permissions from depending on thecaller's umask.
Defense-in-depth: relying solely on the parent directory's
0o700isinsufficient — umask values vary across environments, and directory permissions
can be changed independently of the files inside.
A regression test is included to verify that
createWriteStreamis alwayscalled with
{ flags: 'wx', mode: 0o600 }.Related Issues
Fixes #26779
How to Validate
Unit tests (mock-based, verifies correct arguments are passed):
npm test -w @google/gemini-cli-core -- src/services/shellExecutionService.test.tsExpected: all 67 tests pass, including
should create background log file with restrictive permissions (0o600).Lint & typecheck:
Both exit with code 0.
Pre-Merge Checklist