agent: code-atomiser-fix — broaden clipboard/paste guards to documented secondary windows

The Trust-3/Trust-6 fix in commit 7aee534 added ensure_main_window to
copy_to_clipboard, paste_text, and paste_text_replacing. That was over-
broad: the transcript-viewer and transcription-preview windows
legitimately call copy_to_clipboard (their "copy raw" / "copy
transcript" buttons), and the transcription-preview window legitimately
calls paste_text_replacing (the preview paste-to-foreground flow).

The original Trust-3/Trust-6 finding was about asymmetric exposure to
arbitrary windows, not about banning the documented secondary windows.
Fix: add ensure_window_in_set helper in commands::security, mirror the
allow-list against src-tauri/capabilities/secondary-windows.json so the
IPC trust boundary and the permission grant stay in lock-step.

  copy_to_clipboard         -> main + transcript-viewer + transcription-preview
  paste_text_replacing      -> main + transcription-preview
  paste_text                -> main only (unchanged; no secondary caller)

Adds two unit tests for ensure_window_in_set_label covering the
listed-label accept path and the unlisted-label reject path. The
existing Trust-3/Trust-6 tests remain in place and continue to assert
the size cap and the constants-equality invariant.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-13 18:09:26 +01:00
parent 9653e25e32
commit 12b413d645
3 changed files with 66 additions and 8 deletions

View File

@@ -21,7 +21,13 @@ use arboard::Clipboard;
use serde::Serialize;
use tauri::Manager;
use crate::commands::security::ensure_main_window;
use crate::commands::security::{ensure_main_window, ensure_window_in_set};
/// Windows allowed to invoke `paste_text_replacing`. The
/// `transcription-preview` window's paste-to-foreground flow legitimately
/// uses this command; mirror the secondary-windows capability grant in
/// `src-tauri/capabilities/secondary-windows.json`.
const PASTE_REPLACING_ALLOWED_WINDOWS: &[&str] = &["main", "transcription-preview"];
/// Refuse-to-paste limit. Matches `commands::clipboard::MAX_CLIPBOARD_BYTES`
/// (1 MiB) so paste and copy surfaces share a single rejection rule.
@@ -208,7 +214,7 @@ pub async fn paste_text_replacing(
app: tauri::AppHandle,
text: String,
) -> Result<PasteOutcome, String> {
ensure_main_window(&window)?;
ensure_window_in_set(&window, PASTE_REPLACING_ALLOWED_WINDOWS)?;
if text.len() > MAX_PASTE_BYTES {
return Err(format!(
"Paste payload too large ({} bytes; limit {} bytes).",