@@ -174,6 +174,33 @@ function sanitizeInheritedGitAllowProtocolValue(value: string): string {
174174 return safeProtocols . join ( ":" ) ;
175175}
176176
177+ export function sanitizeHostInheritedEnvEntry (
178+ rawKey : string ,
179+ value : string ,
180+ ) : [ string , string ] | null {
181+ const key = normalizeEnvVarKey ( rawKey ) ;
182+ if ( ! key ) {
183+ return null ;
184+ }
185+ // Preserve inherited Git allowlists without widening malformed or unsafe entries by deletion.
186+ // Protocols outside Git's safe default set are removed instead of being passed through.
187+ if ( key . toUpperCase ( ) === GIT_ALLOW_PROTOCOL_ENV_KEY ) {
188+ return [ key , sanitizeInheritedGitAllowProtocolValue ( value ) ] ;
189+ }
190+ // Preserve non-permissive Git boolean values. Permissive values must become explicit `0`
191+ // because Git's unset default still permits protocols with policy `user`.
192+ if ( key . toUpperCase ( ) === GIT_PROTOCOL_FROM_USER_ENV_KEY ) {
193+ return [
194+ key ,
195+ isPermissiveGitProtocolFromUserValue ( value ) ? GIT_PROTOCOL_FROM_USER_DISABLED_VALUE : value ,
196+ ] ;
197+ }
198+ if ( isDangerousHostInheritedEnvVarName ( key ) ) {
199+ return null ;
200+ }
201+ return [ key , value ] ;
202+ }
203+
177204function sanitizeHostEnvOverridesWithDiagnostics ( params ?: {
178205 overrides ?: Record < string , string > | null ;
179206 blockPathOverrides ?: boolean ;
@@ -236,26 +263,12 @@ export function sanitizeHostExecEnvWithDiagnostics(params?: {
236263
237264 const merged : Record < string , string > = { } ;
238265 for ( const [ key , value ] of listNormalizedEnvEntries ( baseEnv ) ) {
239- // Preserve inherited Git allowlists without widening malformed or unsafe entries by deletion.
240- // Protocols outside Git's safe default set are removed instead of being passed through.
241- if ( key . toUpperCase ( ) === GIT_ALLOW_PROTOCOL_ENV_KEY ) {
242- merged [ key ] = sanitizeInheritedGitAllowProtocolValue ( value ) ;
243- continue ;
244- }
245- // Preserve non-permissive Git boolean values. Permissive values must become explicit `0`
246- // because Git's unset default still permits protocols with policy `user`.
247- if ( key . toUpperCase ( ) === GIT_PROTOCOL_FROM_USER_ENV_KEY ) {
248- if ( ! isPermissiveGitProtocolFromUserValue ( value ) ) {
249- merged [ key ] = value ;
250- } else {
251- merged [ key ] = GIT_PROTOCOL_FROM_USER_DISABLED_VALUE ;
252- }
253- continue ;
254- }
255- if ( isDangerousHostInheritedEnvVarName ( key ) ) {
266+ const sanitizedEntry = sanitizeHostInheritedEnvEntry ( key , value ) ;
267+ if ( ! sanitizedEntry ) {
256268 continue ;
257269 }
258- merged [ key ] = value ;
270+ const [ sanitizedKey , sanitizedValue ] = sanitizedEntry ;
271+ merged [ sanitizedKey ] = sanitizedValue ;
259272 }
260273
261274 const overrideResult = sanitizeHostEnvOverridesWithDiagnostics ( {
0 commit comments