Compare commits

...

2 Commits

Author SHA1 Message Date
Sri Pasumarthi 50ce2b9a5e fix(core): ensure true fallbacks for TERM and COLORTERM variables 2026-03-03 22:08:19 -08:00
Arnav Raj 3ebc7d7c1a fix(core): whitelist TERM and COLORTERM in environment sanitization
Terminal editors (vim, emacs) and interactive commands (top) fail when
these variables are redacted. They are safe to pass through as they
only describe terminal capabilities.

Fixes #20444
2026-02-27 05:28:03 +05:30
3 changed files with 30 additions and 2 deletions
@@ -32,6 +32,28 @@ describe('sanitizeEnvironment', () => {
expect(sanitized).toEqual(env);
});
it('should allow TERM and COLORTERM environment variables', () => {
const env = {
TERM: 'xterm-256color',
COLORTERM: 'truecolor',
};
const sanitized = sanitizeEnvironment(env, EMPTY_OPTIONS);
expect(sanitized).toEqual(env);
});
it('should preserve TERM and COLORTERM even in strict sanitization mode', () => {
const env = {
GITHUB_SHA: 'abc123',
TERM: 'xterm-256color',
COLORTERM: 'truecolor',
SOME_OTHER_VAR: 'value',
};
const sanitized = sanitizeEnvironment(env, EMPTY_OPTIONS);
expect(sanitized['TERM']).toBe('xterm-256color');
expect(sanitized['COLORTERM']).toBe('truecolor');
expect(sanitized['SOME_OTHER_VAR']).toBeUndefined();
});
it('should allow variables prefixed with GEMINI_CLI_', () => {
const env = {
GEMINI_CLI_FOO: 'bar',
@@ -71,6 +71,10 @@ export const ALWAYS_ALLOWED_ENVIRONMENT_VARIABLES: ReadonlySet<string> =
'TMPDIR',
'USER',
'LOGNAME',
// Terminal capability variables (needed by editors like vim/emacs and
// interactive commands like top)
'TERM',
'COLORTERM',
// GitHub Action-related variables
'ADDITIONAL_CONTEXT',
'AVAILABLE_LABELS',
@@ -313,10 +313,11 @@ export class ShellExecutionService {
shell: false,
detached: !isWindows,
env: {
TERM: 'xterm-256color',
COLORTERM: 'truecolor',
...sanitizeEnvironment(process.env, sanitizationConfig),
[GEMINI_CLI_IDENTIFICATION_ENV_VAR]:
GEMINI_CLI_IDENTIFICATION_ENV_VAR_VALUE,
TERM: 'xterm-256color',
PAGER: 'cat',
GIT_PAGER: 'cat',
},
@@ -575,12 +576,13 @@ export class ShellExecutionService {
cols,
rows,
env: {
TERM: 'xterm-256color',
COLORTERM: 'truecolor',
...sanitizeEnvironment(
process.env,
shellExecutionConfig.sanitizationConfig,
),
GEMINI_CLI: '1',
TERM: 'xterm-256color',
PAGER: shellExecutionConfig.pager ?? 'cat',
GIT_PAGER: shellExecutionConfig.pager ?? 'cat',
},