Repository navigation
fix(core): allow scoped Git credential config #9870
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
9 commits
Select commit
Hold shift + click to select a range
34fce2d
fix(core): allow scoped Git credential config
callmeYe 0699929
fix(core): handle Git config URL false positives
callmeYe bd39137
docs(core): clarify Git client safety invariant
callmeYe c9fd421
Merge remote-tracking branch 'origin/main' into codex/fix-extension-g…
callmeYe 2224d72
fix(core): reject unsafe Git extension inputs
callmeYe 926513d
docs(core): reattach cloneFromGit JSDoc and note blocklist mirror (#9…
callmeYe bc03c08
fix(core): inherit wrapper environment for restricted Git clients (#9…
callmeYe d9cf51c
fix(core): reject ambiguous credentialed Git sources and block ambien…
callmeYe 56eef4d
fix(core): preserve Git credential isolation
callmeYe 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2026 Qwen Team | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; | ||
| import * as fs from 'node:fs/promises'; | ||
| import * as os from 'node:os'; | ||
| import * as path from 'node:path'; | ||
| import { simpleGit } from 'simple-git'; | ||
| import { createExtensionGitClient } from './extension-git-client.js'; | ||
|
|
||
| describe('createExtensionGitClient', () => { | ||
| let tempDir: string; | ||
|
|
||
| beforeEach(async () => { | ||
| tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'extension-git-client-')); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| vi.unstubAllEnvs(); | ||
| await fs.rm(tempDir, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| it('runs authenticated Git commands with pinned network config', async () => { | ||
| let spawned = false; | ||
| const git = createExtensionGitClient(simpleGit, { | ||
| baseDir: tempDir, | ||
| networkPolicy: 'public', | ||
| networkConfig: [ | ||
| 'http.curloptResolve=git.example.com:443:8.8.8.8', | ||
| 'http.followRedirects=false', | ||
| 'http.proxy=', | ||
| 'protocol.allow=never', | ||
| 'protocol.https.allow=always', | ||
| ], | ||
| authentication: { | ||
| source: 'https://git.example.com/owner/repo.git', | ||
| credential: { username: 'user', password: 'token' }, | ||
| }, | ||
| }); | ||
| git.outputHandler(() => { | ||
| spawned = true; | ||
| }); | ||
|
|
||
| await expect(git.version()).resolves.toBeDefined(); | ||
| expect(spawned).toBe(true); | ||
| }); | ||
|
|
||
| it('runs authenticated Git commands without pinned network config', async () => { | ||
| let spawned = false; | ||
| const git = createExtensionGitClient(simpleGit, { | ||
| baseDir: tempDir, | ||
| authentication: { | ||
| source: 'https://git.example.com/owner/repo.git', | ||
| credential: { username: 'user', password: 'token' }, | ||
| }, | ||
| }); | ||
| git.outputHandler(() => { | ||
| spawned = true; | ||
| }); | ||
|
|
||
| await expect(git.version()).resolves.toBeDefined(); | ||
| expect(spawned).toBe(true); | ||
| }); | ||
|
|
||
| it('does not inherit Git config count for anonymous public commands', async () => { | ||
| vi.stubEnv('GIT_CONFIG_COUNT', '1'); | ||
| vi.stubEnv('GIT_CONFIG_KEY_0', 'http.extraHeader'); | ||
| vi.stubEnv('GIT_CONFIG_VALUE_0', 'Authorization: Basic external'); | ||
| let spawned = false; | ||
| const git = createExtensionGitClient(simpleGit, { | ||
| baseDir: tempDir, | ||
| networkPolicy: 'public', | ||
| }); | ||
| git.outputHandler(() => { | ||
| spawned = true; | ||
| }); | ||
|
|
||
| await expect(git.version()).resolves.toBeDefined(); | ||
| expect(spawned).toBe(true); | ||
| }); | ||
| }); |
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,81 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2026 Qwen Team | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import * as os from 'node:os'; | ||
| import type { SimpleGit, SimpleGitFactory } from 'simple-git'; | ||
| import type { ExtensionInstallMetadata } from '../config/config.js'; | ||
| import type { GitCredential } from './extension-git-credentials.js'; | ||
|
|
||
| interface ExtensionGitAuthentication { | ||
| source: string; | ||
| credential: GitCredential; | ||
| } | ||
|
|
||
| interface ExtensionGitClientOptions { | ||
| baseDir: string; | ||
| signal?: AbortSignal; | ||
| networkPolicy?: ExtensionInstallMetadata['networkPolicy']; | ||
| networkConfig?: string[]; | ||
| authentication?: ExtensionGitAuthentication; | ||
| } | ||
|
|
||
| export function createExtensionGitClient( | ||
| simpleGit: SimpleGitFactory, | ||
| { | ||
| baseDir, | ||
| signal, | ||
| networkPolicy, | ||
| networkConfig = [], | ||
| authentication, | ||
| }: ExtensionGitClientOptions, | ||
| ): SimpleGit { | ||
| const restrictEnvironment = | ||
| networkPolicy === 'public' || authentication !== undefined; | ||
| const hasNetworkConfig = networkConfig.length > 0; | ||
| const git = simpleGit(baseDir, { | ||
| ...(signal ? { abort: signal } : {}), | ||
| ...(hasNetworkConfig ? { config: networkConfig } : {}), | ||
| ...(restrictEnvironment || hasNetworkConfig | ||
| ? { | ||
| unsafe: { | ||
| ...(restrictEnvironment ? { allowUnsafeConfigPaths: true } : {}), | ||
| ...(hasNetworkConfig ? { allowUnsafeProtocolOverride: true } : {}), | ||
| ...(authentication ? { allowUnsafeConfigEnvCount: true } : {}), | ||
| }, | ||
| } | ||
| : {}), | ||
| }); | ||
| if (!restrictEnvironment) return git; | ||
|
|
||
| const environment: Record<string, string> = { | ||
| GIT_CONFIG_NOSYSTEM: '1', | ||
| GIT_CONFIG_GLOBAL: os.devNull, | ||
| }; | ||
| for (const key of [ | ||
| 'PATH', | ||
| 'Path', | ||
| 'SystemRoot', | ||
| 'SYSTEMROOT', | ||
| 'WINDIR', | ||
| 'TEMP', | ||
| 'TMP', | ||
| 'TMPDIR', | ||
| ]) { | ||
| const value = process.env[key]; | ||
| if (value !== undefined) environment[key] = value; | ||
| } | ||
| if (authentication) { | ||
| const value = Buffer.from( | ||
| `${authentication.credential.username}:${authentication.credential.password}`, | ||
| 'utf8', | ||
| ).toString('base64'); | ||
| environment['GIT_CONFIG_COUNT'] = '1'; | ||
| environment['GIT_CONFIG_KEY_0'] = | ||
| `http.${authentication.source}.extraHeader`; | ||
|
callmeYe marked this conversation as resolved.
Resolved
|
||
| environment['GIT_CONFIG_VALUE_0'] = `Authorization: Basic ${value}`; | ||
| } | ||
| return git.env(environment); | ||
| } | ||
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
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.