mirror of
https://github.com/openai/codex.git
synced 2026-11-18 23:02:23 +00:00
Probe Windows terminal colors without risking startup input (#40598)
## Why Windows Terminal and xterm.js can render a theme that differs from the underlying console color table. Querying that visible theme through OSC shares the console input queue with keystrokes, including input for security-sensitive startup prompts. ## What changed - Defer the Windows OSC color probe until protected startup decisions and the world-writable workspace scan have completed. - Preserve and replay unrelated console input records around the probe, while removing only valid OSC 10 and 11 replies and retaining the console palette as a fallback. - Require an explicit confirmation key after shortcuts select trust, sandbox, or world-writable warning choices, so a fragmented terminal reply cannot accept them. - Accept one- through four-digit OSC RGB components so the visible terminal palette is applied across supported response formats. ## Testing Added coverage for delayed startup scans, protected prompt confirmation, console-record replay, bracketed paste and malformed OSC preservation, RGB response parsing, and light-theme composer rendering. GitOrigin-RevId: b8ae456fe32c701ba3af31e9cc452fc4e8bffa22
This commit is contained in:
1 parent
1f5c9ba183
commit
70b5cfc73b
19 files changed
+1162
-149
No files matched your search
@@ -524,6 +524,80 @@ async fn windows_sandbox_required_enable_prompt_reopens_on_cancel_when_unelevate
|
||||
));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn fragmented_terminal_response_cannot_select_non_admin_windows_sandbox() {
|
||||
for use_fallback_prompt in [false, true] {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
let preset = builtin_approval_presets()
|
||||
.into_iter()
|
||||
.find(|preset| preset.id == "auto")
|
||||
.expect("auto preset");
|
||||
|
||||
if use_fallback_prompt {
|
||||
chat.open_windows_sandbox_fallback_prompt(preset, /*profile_selection*/ None);
|
||||
} else {
|
||||
chat.open_windows_sandbox_enable_prompt(preset, /*profile_selection*/ None);
|
||||
}
|
||||
|
||||
for character in "20;rgb:2222/ffff/ffff".chars() {
|
||||
chat.handle_key_event(KeyEvent::new(KeyCode::Char(character), KeyModifiers::NONE));
|
||||
assert!(
|
||||
!matches!(
|
||||
rx.try_recv(),
|
||||
Ok(AppEvent::BeginWindowsSandboxLegacySetup { .. })
|
||||
),
|
||||
"a fragmented terminal response must not choose the non-admin sandbox"
|
||||
);
|
||||
}
|
||||
|
||||
assert!(chat.has_active_view());
|
||||
chat.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));
|
||||
assert!(matches!(
|
||||
rx.try_recv(),
|
||||
Ok(AppEvent::BeginWindowsSandboxLegacySetup { .. })
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn fragmented_terminal_response_cannot_acknowledge_world_writable_warning() {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
chat.open_world_writable_warning_confirmation(
|
||||
/*preset*/ None,
|
||||
/*profile_selection*/ None,
|
||||
Vec::new(),
|
||||
/*extra_count*/ 0,
|
||||
/*failed_scan*/ true,
|
||||
);
|
||||
|
||||
chat.handle_key_event(KeyEvent::new(KeyCode::Char('1'), KeyModifiers::NONE));
|
||||
assert!(chat.has_active_view());
|
||||
assert!(rx.try_recv().is_err());
|
||||
|
||||
for character in "20;rgb:2222/ffff/ffff".chars() {
|
||||
chat.handle_key_event(KeyEvent::new(KeyCode::Char(character), KeyModifiers::NONE));
|
||||
assert!(
|
||||
!matches!(
|
||||
rx.try_recv(),
|
||||
Ok(AppEvent::UpdateWorldWritableWarningAcknowledged(_)
|
||||
| AppEvent::PersistWorldWritableWarningAcknowledged)
|
||||
),
|
||||
"a fragmented terminal response must not acknowledge the world-writable warning"
|
||||
);
|
||||
}
|
||||
|
||||
assert!(chat.has_active_view());
|
||||
chat.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));
|
||||
assert!(matches!(
|
||||
rx.try_recv(),
|
||||
Ok(AppEvent::UpdateWorldWritableWarningAcknowledged(true))
|
||||
));
|
||||
assert!(matches!(
|
||||
rx.try_recv(),
|
||||
Ok(AppEvent::PersistWorldWritableWarningAcknowledged)
|
||||
));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn required_windows_sandbox_setup_defers_configured_initial_prompt() {
|
||||
let (mut chat, mut rx, mut op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
|
||||
Reference in new issue
Block a user