feat(sandbox): resolve custom seatbelt profiles from $HOME/.gemini first#25427
Conversation
Custom (non-builtin) SEATBELT_PROFILE values now resolve from
$HOME/.gemini/sandbox-macos-${profile}.sb when present, falling back to
the existing project-level .gemini/sandbox-macos-${profile}.sb. This
lets users keep a single custom profile that works across every
workspace, as suggested by the maintainer in google-gemini#24991.
Builtin profile resolution is unchanged.
Fixes google-gemini#24991
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 enhances the 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 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 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
|
There was a problem hiding this comment.
Code Review
This pull request updates the sandbox seatbelt profile resolution logic to check the user's home directory (~/.gemini) before falling back to the project-level directory, and includes new unit tests for these scenarios. Feedback focuses on a potential path traversal vulnerability where the profile environment variable should be sanitized using path.basename() before file path construction. Additionally, the reviewer noted that the new tests violate the repository style guide by modifying process.env directly instead of using vi.stubEnv().
|
Please address all the gemini comments and mark them "resolved" when you are done. |
- Apply path.basename() to SEATBELT_PROFILE before constructing the profile filename, preventing path traversal via directory separators or .. in the env var. - Switch the two new sandbox tests to vi.stubEnv()/vi.unstubAllEnvs() to match the repo's testing convention (per gemini-code-assist feedback and existing usage in envVarResolver.test.ts and others). Addresses gemini-code-assist review on google-gemini#25427.
|
@scidomino addressed all three in 8d919e9 - |
|
Summary
Custom (non-builtin)
SEATBELT_PROFILEvalues now resolve from$HOME/.gemini/sandbox-macos-${profile}.sbfirst, falling back to the existing project-level.gemini/sandbox-macos-${profile}.sb. This lets a user keep one custom profile that works across every workspace, which is what was requested in #24991.Details
The previous resolution path (in
packages/cli/src/utils/sandbox.ts:67-79) did:BUILTIN_SEATBELT_PROFILESpath.join(GEMINI_DIR, 'sandbox-macos-${profile}.sb')for everything else - i.e. only the project's.gemini/The change keeps step 1 unchanged. For non-builtin profiles, it now checks
path.join(homedir(), GEMINI_DIR, fileName)and uses that file when it exists, otherwise falls back to the project-level path. The sameFatalSandboxErroris thrown if neither location has the file.This matches the approach proposed in #24991 (comment) by @scidomino:
@flexponsive (the issue author) confirmed this would solve the problem. Two prior PRs (#25013, #25024) implemented the alternative
SEATBELT_PROFILE-as-absolute-path approach and were closed with "we don't want to impl it this way" - so this PR deliberately takes the maintainer-directed path.homedirandGEMINI_DIRare already imported from@google/gemini-cli-corein this file, mirroring the user-level.geminilookups elsewhere (e.g.packages/core/src/services/fileKeychain.ts:19,packages/cli/src/config/trustedFolders.ts:30).Related Issues
Fixes #24991
How to Validate
npm run build --workspace @google/gemini-cli-core && npm run build --workspace @google/gemini-cli-test-utilsnpx vitest run packages/cli/src/utils/sandbox.test.ts- 18 tests pass, including two new tests:should resolve custom seatbelt profile from user home directoryshould fall back to project .gemini directory when user profile is missingnpx prettier --check packages/cli/src/utils/sandbox.ts packages/cli/src/utils/sandbox.test.ts- cleannpx eslint packages/cli/src/utils/sandbox.ts packages/cli/src/utils/sandbox.test.ts- no errorsnpm run typecheck --workspace @google/gemini-cli- passesManual smoke (macOS):
Run from any other workspace and the same profile resolves.
Pre-Merge Checklist
docs/cli/sandbox.mdif you'd prefer.This contribution was developed with AI assistance (Codex).