Skip to content

feature: allow absolute path for macos seatbelt profiles (sandbox)#25013

Closed
flexponsive wants to merge 11 commits intogoogle-gemini:mainfrom
flexponsive:fix-absolute-seatbelt-profile
Closed

feature: allow absolute path for macos seatbelt profiles (sandbox)#25013
flexponsive wants to merge 11 commits intogoogle-gemini:mainfrom
flexponsive:fix-absolute-seatbelt-profile

Conversation

@flexponsive
Copy link
Copy Markdown

Summary

Enhance macOS Seatbelt configuration flexibility by allowing the SEATBELT_PROFILE environment variable to accept absolute paths. This enables developers to maintain centralized sandbox policies across multiple repositories without duplicating configuration into every project's .gemini folder.

Details

Updated the sandbox utility to check if the SEATBELT_PROFILE value is an absolute path.

  • If absolute: Uses the path directly.
  • If relative/name: Continues with existing logic (checking built-in profiles or the project .gemini folder).

This change is non-breaking and preserves all existing workflows.

Related Issues

Closes #24991

How to Validate

GEMINI_SANDBOX=sandbox-exec SEATBELT_PROFILE=$(pwd)/bundle/sandbox-macos-permissive-open.sb node bundle/gemini.js -s

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@flexponsive flexponsive requested a review from a team as a code owner April 9, 2026 08:56
@google-cla
Copy link
Copy Markdown

google-cla Bot commented Apr 9, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 significantly enhances the flexibility of macOS Seatbelt configurations by allowing the SEATBELT_PROFILE environment variable to accept absolute paths. This change streamlines the management of sandbox policies, enabling developers to centralize configurations and avoid redundant duplication across various projects. The update is non-breaking and maintains compatibility with existing workflows.

Highlights

  • Absolute Paths for Seatbelt Profiles: Enabled the SEATBELT_PROFILE environment variable to accept absolute file paths, allowing for centralized sandbox policy management.
  • Enhanced Configuration Flexibility: Developers can now maintain sandbox policies across multiple repositories without duplicating configuration into every project's .gemini folder.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize 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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. 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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@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 adds support for absolute paths in the SEATBELT_PROFILE environment variable within the macOS sandbox utility, along with a corresponding test case. The review feedback suggests enhancing security by trimming and sanitizing the profile path to prevent potential path traversal vulnerabilities. Additionally, it notes a violation of the repository's testing style guide, recommending the use of vi.stubEnv() for environment variable manipulation in tests to avoid state leakage.

Comment on lines +68 to 79
let profileFile;
if (path.isAbsolute(profile)) {
profileFile = profile;
} else {
profileFile = fileURLToPath(
new URL(`sandbox-macos-${profile}.sb`, import.meta.url),
);
// if profile name is not recognized, then look for file under project settings directory
if (!BUILTIN_SEATBELT_PROFILES.includes(profile)) {
profileFile = path.join(GEMINI_DIR, `sandbox-macos-${profile}.sb`);
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

security-high high

The SEATBELT_PROFILE value should be trimmed to ensure that absolute paths with leading or trailing whitespace are correctly identified by path.isAbsolute(). Additionally, when a relative path or name is provided, it must be sanitized to prevent path traversal (e.g., by checking for .. or null bytes), as per the repository's security guidelines for handling untrusted input.

      const trimmedProfile = profile.trim();
      let profileFile;
      if (path.isAbsolute(trimmedProfile)) {
        profileFile = trimmedProfile;
      } else {
        if (trimmedProfile.includes('..') || trimmedProfile.includes('\\0')) {
          throw new FatalSandboxError('Invalid seatbelt profile name: ' + trimmedProfile);
        }
        profileFile = fileURLToPath(
          new URL('sandbox-macos-' + trimmedProfile + '.sb', import.meta.url),
        );
        if (!BUILTIN_SEATBELT_PROFILES.includes(trimmedProfile)) {
          profileFile = path.join(GEMINI_DIR, 'sandbox-macos-' + trimmedProfile + '.sb');
        }
      }
References
  1. Sanitize file paths extracted from untrusted sources, such as command output, to prevent path traversal (..), null byte injection (\0), and other vulnerabilities.
  2. When validating string parameters from tools, trim the string first and then check for emptiness to prevent whitespace-only values from being accepted.


it('should handle absolute path for SEATBELT_PROFILE', async () => {
vi.mocked(os.platform).mockReturnValue('darwin');
process.env['SEATBELT_PROFILE'] = '/absolute/path/to/profile.sb';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Direct modification of process.env is discouraged in tests as it can lead to state leakage between test cases. Use vi.stubEnv() instead, as specified in the repository style guide. Note that vi.unstubAllEnvs() should also be called in afterEach to ensure proper cleanup.

Suggested change
process.env['SEATBELT_PROFILE'] = '/absolute/path/to/profile.sb';
vi.stubEnv('SEATBELT_PROFILE', '/absolute/path/to/profile.sb');
References
  1. When testing code that depends on environment variables, use vi.stubEnv('NAME', 'value') in beforeEach and vi.unstubAllEnvs() in afterEach. Avoid modifying process.env directly as it can lead to test leakage and is less reliable. (link)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thank you for the feedback. I've noted that sandbox.test.ts currently uses direct process.env modification across 10 or so existing test cases. To avoid introducing inconsistent patterns within the same file, I followed the local convention for the new test.

Please advise on your preferred path:

  1. Holistic Refactor: Update the entire file to use vi.stubEnv() and vi.unstubAllEnvs within this PR. (risk of losing focus)
  2. Surgical Update: Only update the newly added test case (accepting local inconsistency).
  3. Follow-up PR: Keep this PR focused on the feature and address the test debt in a dedicated cleanup task.

@gemini-cli gemini-cli Bot added the area/core Issues related to User Interface, OS Support, Core Functionality label Apr 9, 2026
@flexponsive flexponsive force-pushed the fix-absolute-seatbelt-profile branch from ac65a94 to 40499fb Compare April 9, 2026 12:50
@flexponsive flexponsive requested review from a team as code owners April 9, 2026 12:50
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 9, 2026

🛑 Action Required: Evaluation Approval

Steering changes have been detected in this PR. To prevent regressions, a maintainer must approve the evaluation run before this PR can be merged.

Maintainers:

  1. Go to the Workflow Run Summary.
  2. Click the yellow 'Review deployments' button.
  3. Select the 'eval-gate' environment and click 'Approve'.

Once approved, the evaluation results will be posted here automatically.

@flexponsive flexponsive force-pushed the fix-absolute-seatbelt-profile branch from 40499fb to b256f1a Compare April 9, 2026 12:54
@flexponsive flexponsive closed this Apr 9, 2026
@flexponsive flexponsive deleted the fix-absolute-seatbelt-profile branch April 9, 2026 13:06
@flexponsive
Copy link
Copy Markdown
Author

closed due to problem with email verification for CLA bot, created new clean PR

@The-SMG
Copy link
Copy Markdown

The-SMG commented Apr 9, 2026 via email

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

Labels

area/core Issues related to User Interface, OS Support, Core Functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support custom seatbelt profiles in ~/.gemini

10 participants