-
Notifications
You must be signed in to change notification settings - Fork 13k
fix(cli): allow restricted .env loading in untrusted sandboxed folders #17806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
fa7eb46
fix(cli): allow restricted .env loading in untrusted sandboxed folders
galz10 7803a0d
fix: lint errors
galz10 f936b0f
fix(cli): sanitize whitelisted env vars in untrusted sandboxed folders
galz10 2efc8e4
Merge branch 'main' into galzahavi/fix/trustfolder-untrusted-auth
galz10 8d9ca69
chore: consolidate tests into single file
galz10 d824823
refactor(cli): clean up settings logic and improve test type safety
galz10 09a8353
test(cli): revert increased timeout in config integration tests
galz10 2420fbb
Merge branch 'main' into galzahavi/fix/trustfolder-untrusted-auth
galz10 c826131
chore: set folderTrust.enabled to true by default
galz10 b349c22
test(cli): fix tests after enabling folder trust by default
galz10 171205f
Merge branch 'main' into galzahavi/fix/trustfolder-untrusted-auth
galz10 5ea0128
chore: set folderTrust.enabled to false for int tests
galz10 4cc17e3
Merge branch 'main' into galzahavi/fix/trustfolder-untrusted-auth
galz10 cd0526d
fix failure
galz10 194e7fb
fix: test-rig
galz10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; | ||
| import * as fs from 'node:fs'; | ||
| import * as path from 'node:path'; | ||
| import { loadEnvironment, loadSettings, getSettingsSchema } from './settings.js'; | ||
| import { validateAuthMethod } from './auth.js'; | ||
| import { isWorkspaceTrusted } from './trustedFolders.js'; | ||
| import { AuthType } from '@google/gemini-cli-core'; | ||
|
|
||
| vi.mock('./trustedFolders.js', () => ({ | ||
| isWorkspaceTrusted: vi.fn(), | ||
| isFolderTrustEnabled: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock('node:fs', async (importOriginal) => { | ||
| const actual = await importOriginal<typeof fs>(); | ||
| return { | ||
| ...actual, | ||
| existsSync: vi.fn(), | ||
| readFileSync: vi.fn(), | ||
| realpathSync: vi.fn().mockImplementation((p) => p), | ||
| }; | ||
| }); | ||
|
|
||
| describe('Verification: Auth and Trust Interaction', () => { | ||
| beforeEach(() => { | ||
| vi.stubEnv('GEMINI_API_KEY', ''); | ||
| vi.resetAllMocks(); | ||
| vi.mocked(isWorkspaceTrusted).mockReturnValue({ isTrusted: true, source: 'file' }); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.unstubAllEnvs(); | ||
| }); | ||
|
|
||
| it('should verify loadEnvironment returns early and validateAuthMethod fails when untrusted', () => { | ||
| // 1. Mock untrusted workspace | ||
| vi.mocked(isWorkspaceTrusted).mockReturnValue({ isTrusted: false, source: 'file' }); | ||
|
|
||
| // 2. Mock .env file existence | ||
| const envPath = path.resolve(process.cwd(), '.env'); | ||
| vi.mocked(fs.existsSync).mockImplementation((p) => p === envPath); | ||
| vi.mocked(fs.readFileSync).mockImplementation((p) => { | ||
| if (p === envPath) return 'GEMINI_API_KEY=shhh-secret'; | ||
| return ''; | ||
| }); | ||
|
|
||
| // 3. Load environment (should return early) | ||
| const settings = loadSettings(process.cwd()); | ||
| loadEnvironment(settings.merged); | ||
|
|
||
| // 4. Verify env var NOT loaded | ||
| expect(process.env['GEMINI_API_KEY']).toBe(''); | ||
|
|
||
| // 5. Verify validateAuthMethod fails | ||
| const result = validateAuthMethod(AuthType.USE_GEMINI); | ||
| expect(result).toContain('you must specify the GEMINI_API_KEY environment variable'); | ||
| }); | ||
|
|
||
| it('should identify if sandbox flag is available in Settings', () => { | ||
| const schema = getSettingsSchema(); | ||
| expect(schema.tools.properties).toBeDefined(); | ||
| expect('sandbox' in schema.tools.properties!).toBe(true); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.