Skip to content

🔒 Restrict System storage path permissions to 0700#278

Open
segin wants to merge 1 commit intomasterfrom
fix/secure-mkdir-permissions-15930402972452581726
Open

🔒 Restrict System storage path permissions to 0700#278
segin wants to merge 1 commit intomasterfrom
fix/secure-mkdir-permissions-15930402972452581726

Conversation

@segin
Copy link
Copy Markdown
Owner

@segin segin commented Apr 8, 2026

🎯 What: The vulnerability fixed is that System::createStoragePath() was invoking mkdir with 0755 permissions for user configuration and storage directories.
⚠️ Risk: By setting permissions to 0755, other users on the system could potentially read the contents of the configuration directories, putting sensitive user data or configuration at risk of unauthorized access.
🛡️ Solution: The permissions argument passed to mkdir has been restricted to 0700, ensuring the directory is only readable, writable, and executable by the owner.


PR created automatically by Jules for task 15930402972452581726 started by @segin

The `System::createStoragePath()` was using `0755` to create user-specific
configuration directories via `mkdir`. This is changed to `0700` so only
the owner has access.

Co-authored-by: segin <480709+segin@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings April 8, 2026 23:38
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR tightens POSIX filesystem permissions for the application’s user storage/config directory created by System::createStoragePath(), addressing potential exposure of sensitive user data in multi-user environments.

Changes:

  • Change POSIX mkdir permissions for the storage directory from 0755 to 0700.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/system.cpp
Comment on lines 519 to 521
// mkdir returns 0 on success.
return mkdir(path.toCString(true), 0755) == 0 || (errno == EEXIST);
return mkdir(path.toCString(true), 0700) == 0 || (errno == EEXIST);
#endif
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On POSIX, treating errno == EEXIST as success can mask cases where the path already exists but is not a directory (mkdir returns EEXIST for any existing path). Also, if the directory already exists with overly permissive mode (e.g., 0755 from previous versions), this code returns true without tightening permissions, so the reported vulnerability remains for existing installs. Consider stat() to confirm S_ISDIR, and on success/exists ensure permissions are restricted (e.g., chmod(path, 0700) or equivalent) while handling errors explicitly.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the directory creation permissions in src/system.cpp from 0755 to 0700 to enhance security. The review feedback correctly identifies that this change only affects new directories and suggests using chmod to ensure consistent permissions for existing directories, while also pointing out a potential logic error if the path already exists as a file.

Comment thread src/system.cpp
#else
// mkdir returns 0 on success.
return mkdir(path.toCString(true), 0755) == 0 || (errno == EEXIST);
return mkdir(path.toCString(true), 0700) == 0 || (errno == EEXIST);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-medium medium

While restricting permissions to 0700 is a significant security improvement, this change only affects newly created directories. If the storage directory already exists (e.g., from a previous version of the application), its permissions will remain unchanged (likely 0755), leaving the vulnerability unaddressed for existing users. Additionally, if the path exists but is a regular file, mkdir will fail with EEXIST and the function will incorrectly return true. Consider explicitly setting the permissions using chmod if the directory already exists to ensure the security fix is applied consistently.

  return mkdir(path.toCString(true), 0700) == 0 || (errno == EEXIST && chmod(path.toCString(true), 0700) == 0);

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants