mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-29 13:13:21 -07:00
fix(core): allow disabling environment variable redaction (#23927)
This commit is contained in:
@@ -375,9 +375,9 @@ describe('sanitizeEnvironment', () => {
|
||||
});
|
||||
|
||||
describe('getSecureSanitizationConfig', () => {
|
||||
it('should enable environment variable redaction by default', () => {
|
||||
it('should default enableEnvironmentVariableRedaction to false', () => {
|
||||
const config = getSecureSanitizationConfig();
|
||||
expect(config.enableEnvironmentVariableRedaction).toBe(true);
|
||||
expect(config.enableEnvironmentVariableRedaction).toBe(false);
|
||||
});
|
||||
|
||||
it('should merge allowed and blocked variables from base and requested configs', () => {
|
||||
@@ -440,13 +440,13 @@ describe('getSecureSanitizationConfig', () => {
|
||||
expect(config.blockedEnvironmentVariables).toEqual(['BLOCKED_VAR']);
|
||||
});
|
||||
|
||||
it('should force enableEnvironmentVariableRedaction to true even if requested false', () => {
|
||||
it('should respect requested enableEnvironmentVariableRedaction value', () => {
|
||||
const requestedConfig = {
|
||||
enableEnvironmentVariableRedaction: false,
|
||||
};
|
||||
|
||||
const config = getSecureSanitizationConfig(requestedConfig);
|
||||
|
||||
expect(config.enableEnvironmentVariableRedaction).toBe(true);
|
||||
expect(config.enableEnvironmentVariableRedaction).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -230,6 +230,9 @@ export function getSecureSanitizationConfig(
|
||||
allowedEnvironmentVariables: [...new Set(allowed)],
|
||||
blockedEnvironmentVariables: [...new Set(blocked)],
|
||||
// Redaction must be enabled for secure configurations
|
||||
enableEnvironmentVariableRedaction: true,
|
||||
enableEnvironmentVariableRedaction:
|
||||
requestedConfig.enableEnvironmentVariableRedaction ??
|
||||
baseConfig?.enableEnvironmentVariableRedaction ??
|
||||
false,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -41,6 +41,11 @@ describe('NoopSandboxManager', () => {
|
||||
MY_SECRET: 'super-secret',
|
||||
SAFE_VAR: 'is-safe',
|
||||
},
|
||||
config: {
|
||||
sanitizationConfig: {
|
||||
enableEnvironmentVariableRedaction: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const result = await sandboxManager.prepareCommand(req);
|
||||
@@ -51,7 +56,7 @@ describe('NoopSandboxManager', () => {
|
||||
expect(result.env['MY_SECRET']).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should NOT allow disabling environment variable redaction if requested in config (vulnerability fix)', async () => {
|
||||
it('should allow disabling environment variable redaction if requested in config', async () => {
|
||||
const req = {
|
||||
command: 'echo',
|
||||
args: ['hello'],
|
||||
@@ -68,8 +73,8 @@ describe('NoopSandboxManager', () => {
|
||||
|
||||
const result = await sandboxManager.prepareCommand(req);
|
||||
|
||||
// API_KEY should be redacted because SandboxManager forces redaction and API_KEY matches NEVER_ALLOWED_NAME_PATTERNS
|
||||
expect(result.env['API_KEY']).toBeUndefined();
|
||||
// API_KEY should be preserved because redaction was explicitly disabled
|
||||
expect(result.env['API_KEY']).toBe('sensitive-key');
|
||||
});
|
||||
|
||||
it('should respect allowedEnvironmentVariables in config but filter sensitive ones', async () => {
|
||||
@@ -84,6 +89,7 @@ describe('NoopSandboxManager', () => {
|
||||
config: {
|
||||
sanitizationConfig: {
|
||||
allowedEnvironmentVariables: ['MY_SAFE_VAR', 'MY_TOKEN'],
|
||||
enableEnvironmentVariableRedaction: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -107,6 +113,7 @@ describe('NoopSandboxManager', () => {
|
||||
config: {
|
||||
sanitizationConfig: {
|
||||
blockedEnvironmentVariables: ['BLOCKED_VAR'],
|
||||
enableEnvironmentVariableRedaction: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user