From cb4e50b78cf47a5a845f810bc5328ceb1b84b47b Mon Sep 17 00:00:00 2001 From: Marco Allegretti Date: Fri, 9 Oct 2026 19:26:47 +0000 Subject: [PATCH 1/3] fix(runtime): bound the clipboard and notification helpers, and attribute notifications The clipboard and notification imports ran wl-paste, wl-copy and notify-send with no deadline and no size limits, and took the clipboard text whole. A notification's icon could be any path or URL, and nothing said which app sent it, so an app could pass one off as the system's. Each helper now runs with a 5-second deadline, after which it is killed and the call fails. Clipboard text is at most 1 MiB in either direction. A notification's title is at most 256 bytes and its body 4096, its icon must be an icon theme name, and it is sent with the app's ID as the application name. Unit tests run real processes for the deadline, the output limit, input passing and failure reporting, and check the notification bounds. check_grants.py still passes. --- crates/weft-runtime/src/desktop.rs | 197 +++++++++++++++++++++++++++++ crates/weft-runtime/src/main.rs | 62 ++------- docs/architecture.md | 2 + 3 files changed, 209 insertions(+), 52 deletions(-) create mode 100644 crates/weft-runtime/src/desktop.rs diff --git a/crates/weft-runtime/src/desktop.rs b/crates/weft-runtime/src/desktop.rs new file mode 100644 index 0000000..528cb4f --- /dev/null +++ b/crates/weft-runtime/src/desktop.rs @@ -0,0 +1,197 @@ +//! The desktop services behind the clipboard and notification imports. +//! +//! Each import runs a helper program (`wl-paste`, `wl-copy`, +//! `notify-send`) with a bounded input, a bounded output and a deadline, +//! after which the helper is killed and the call fails. A notification +//! names the application that sent it, so an app cannot pass one off as +//! the system's. + +use std::io::{Read, Write}; +use std::process::{Command, Stdio}; +use std::time::{Duration, Instant}; + +/// How long a helper may run. +const HELPER_TIMEOUT: Duration = Duration::from_secs(5); +/// The most clipboard text read or written, in bytes. +pub const MAX_CLIPBOARD: usize = 1024 * 1024; +/// The longest notification title and body, in bytes. +pub const MAX_TITLE: usize = 256; +pub const MAX_BODY: usize = 4096; + +/// Runs `command` with `input` on its standard input and returns at most +/// `max_output` bytes of its standard output, or why it failed. +fn run(mut command: Command, input: Option>, max_output: usize) -> Result, String> { + let program = command.get_program().to_string_lossy().into_owned(); + let mut child = command + .stdin(if input.is_some() { + Stdio::piped() + } else { + Stdio::null() + }) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .map_err(|e| format!("cannot run {program}: {e}"))?; + if let (Some(mut stdin), Some(input)) = (child.stdin.take(), input) { + std::thread::spawn(move || { + let _ = stdin.write_all(&input); + }); + } + let reader = |stream: Option>, limit: usize| { + std::thread::spawn(move || { + let mut data = Vec::new(); + if let Some(stream) = stream { + let _ = stream.take(limit as u64 + 1).read_to_end(&mut data); + } + data + }) + }; + let stdout = reader( + child + .stdout + .take() + .map(|s| Box::new(s) as Box), + max_output, + ); + let stderr = reader( + child + .stderr + .take() + .map(|s| Box::new(s) as Box), + 4096, + ); + let deadline = Instant::now() + HELPER_TIMEOUT; + let status = loop { + match child.try_wait() { + Ok(Some(status)) => break status, + Ok(None) if Instant::now() < deadline => std::thread::sleep(Duration::from_millis(10)), + Ok(None) => { + let _ = child.kill(); + let _ = child.wait(); + return Err(format!( + "{program} did not finish within {} s", + HELPER_TIMEOUT.as_secs() + )); + } + Err(e) => return Err(e.to_string()), + } + }; + let output = stdout.join().unwrap_or_default(); + if !status.success() { + let message = String::from_utf8_lossy(&stderr.join().unwrap_or_default()) + .trim() + .to_owned(); + return Err(if message.is_empty() { + format!("{program} exited with {status}") + } else { + message + }); + } + if output.len() > max_output { + return Err(format!("{program} returned more than {max_output} bytes")); + } + Ok(output) +} + +pub fn clipboard_read() -> Result { + let mut command = Command::new("wl-paste"); + command.args(["--no-newline", "--type", "text/plain;charset=utf-8"]); + let data = run(command, None, MAX_CLIPBOARD)?; + String::from_utf8(data).map_err(|_| "the clipboard does not hold UTF-8 text".to_owned()) +} + +pub fn clipboard_write(text: &str) -> Result<(), String> { + if text.len() > MAX_CLIPBOARD { + return Err(format!("clipboard text exceeds {MAX_CLIPBOARD} bytes")); + } + let mut command = Command::new("wl-copy"); + command.args(["--type", "text/plain;charset=utf-8"]); + run(command, Some(text.as_bytes().to_vec()), 0).map(|_| ()) +} + +/// Checks a notification before it is sent. +pub fn check_notification(title: &str, body: &str, icon: Option<&str>) -> Result<(), String> { + if title.len() > MAX_TITLE { + return Err(format!("notification title exceeds {MAX_TITLE} bytes")); + } + if body.len() > MAX_BODY { + return Err(format!("notification body exceeds {MAX_BODY} bytes")); + } + // Only icon theme names: a path or URL would let the app show any file + // or reach the network through the notification service. + if let Some(icon) = icon + && !is_icon_name(icon) + { + return Err("a notification icon must be an icon theme name".to_owned()); + } + Ok(()) +} + +fn is_icon_name(icon: &str) -> bool { + !icon.is_empty() + && icon.len() <= 64 + && !icon.starts_with('.') + && icon + .bytes() + .all(|b| b.is_ascii_alphanumeric() || matches!(b, b'-' | b'_' | b'.')) +} + +/// Sends a notification attributed to `app_id`. +pub fn notify(app_id: &str, title: &str, body: &str, icon: Option<&str>) -> Result<(), String> { + check_notification(title, body, icon)?; + let mut command = Command::new("notify-send"); + command.arg(format!("--app-name={app_id}")); + if let Some(icon) = icon { + command.arg(format!("--icon={icon}")); + } + command.arg("--").arg(title).arg(body); + run(command, None, 0).map(|_| ()) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn notifications_are_bounded_and_icons_are_theme_names() { + assert!(check_notification("t", "b", None).is_ok()); + assert!(check_notification("t", "b", Some("dialog-information")).is_ok()); + assert!(check_notification(&"t".repeat(MAX_TITLE + 1), "b", None).is_err()); + assert!(check_notification("t", &"b".repeat(MAX_BODY + 1), None).is_err()); + for icon in [ + "/etc/passwd", + "file:///x.png", + "https://x/i.png", + "../x", + "", + "a b", + ] { + assert!(check_notification("t", "b", Some(icon)).is_err(), "{icon}"); + } + } + + #[test] + fn helpers_are_bounded_in_time_and_output() { + let mut slow = Command::new("sleep"); + slow.arg("30"); + let started = Instant::now(); + let error = run(slow, None, 0).unwrap_err(); + assert!(error.contains("did not finish"), "{error}"); + assert!(started.elapsed() < HELPER_TIMEOUT + Duration::from_secs(2)); + + let mut chatty = Command::new("head"); + chatty.args(["-c", "2000", "/dev/zero"]); + assert!( + run(chatty, None, 1000) + .unwrap_err() + .contains("more than 1000 bytes") + ); + + let mut echo = Command::new("cat"); + echo.stdin(Stdio::piped()); + assert_eq!(run(echo, Some(b"text".to_vec()), 100).unwrap(), b"text"); + + let failing = Command::new("false"); + assert!(run(failing, None, 0).unwrap_err().contains("exited")); + } +} diff --git a/crates/weft-runtime/src/main.rs b/crates/weft-runtime/src/main.rs index 9c5b92d..94e6d47 100644 --- a/crates/weft-runtime/src/main.rs +++ b/crates/weft-runtime/src/main.rs @@ -2,6 +2,8 @@ use std::path::PathBuf; use anyhow::Context; +#[cfg(feature = "wasmtime-runtime")] +mod desktop; mod grants; #[cfg(feature = "wasmtime-runtime")] mod ipc; @@ -93,6 +95,7 @@ fn main() -> anyhow::Result<()> { tracing::info!(session_id, %app_id, wasm = %wasm_path.display(), "executing module"); run_module( + app_id, &wasm_path, &preopen, grants, @@ -116,6 +119,7 @@ fn ready_line() -> String { #[cfg(not(feature = "wasmtime-runtime"))] fn run_module( + _app_id: &str, _wasm_path: &std::path::Path, _preopen: &[Preopen], _grants: Grants, @@ -129,6 +133,7 @@ fn run_module( #[cfg(feature = "wasmtime-runtime")] fn run_module( + app_id: &str, wasm_path: &std::path::Path, preopen: &[Preopen], grants: Grants, @@ -241,6 +246,7 @@ fn run_module( .context("define weft:app/fetch#fetch")?; let notify_grants = Arc::clone(&grants); + let notify_app = app_id.to_owned(); linker .instance("weft:app/notifications@0.1.0") .context("define weft:app/notifications instance")? @@ -251,7 +257,7 @@ fn run_module( -> wasmtime::Result<(Result<(), String>,)> { let result = notify_grants .notifications() - .and_then(|()| host_notify(&title, &body, icon.as_deref())); + .and_then(|()| desktop::notify(¬ify_app, &title, &body, icon.as_deref())); Ok((result,)) }, ) @@ -270,7 +276,7 @@ fn run_module( -> wasmtime::Result<(Result,)> { Ok((read_grants .clipboard_read() - .and_then(|()| host_clipboard_read()),)) + .and_then(|()| desktop::clipboard_read()),)) }, ) .context("define weft:app/clipboard#read")?; @@ -283,7 +289,7 @@ fn run_module( -> wasmtime::Result<(Result<(), String>,)> { Ok((write_grants .clipboard_write() - .and_then(|()| host_clipboard_write(&text)),)) + .and_then(|()| desktop::clipboard_write(&text)),)) }, ) .context("define weft:app/clipboard#write")?; @@ -463,55 +469,6 @@ fn host_fetch( Err("this runtime was built without network fetch support".to_owned()) } -#[cfg(feature = "wasmtime-runtime")] -fn host_clipboard_read() -> Result { - let out = std::process::Command::new("wl-paste") - .arg("--no-newline") - .output() - .map_err(|e| e.to_string())?; - if out.status.success() { - String::from_utf8(out.stdout).map_err(|e| e.to_string()) - } else { - Err(String::from_utf8_lossy(&out.stderr).trim().to_owned()) - } -} - -#[cfg(feature = "wasmtime-runtime")] -fn host_clipboard_write(text: &str) -> Result<(), String> { - use std::io::Write; - let mut child = std::process::Command::new("wl-copy") - .stdin(std::process::Stdio::piped()) - .spawn() - .map_err(|e| e.to_string())?; - if let Some(stdin) = child.stdin.as_mut() { - stdin - .write_all(text.as_bytes()) - .map_err(|e| e.to_string())?; - } - let status = child.wait().map_err(|e| e.to_string())?; - if status.success() { - Ok(()) - } else { - Err(format!("wl-copy exited with {status}")) - } -} - -#[cfg(feature = "wasmtime-runtime")] -fn host_notify(title: &str, body: &str, icon: Option<&str>) -> Result<(), String> { - let mut cmd = std::process::Command::new("notify-send"); - if let Some(i) = icon { - cmd.arg("--icon").arg(i); - } - cmd.arg("--").arg(title).arg(body); - cmd.status().map_err(|e| e.to_string()).and_then(|s| { - if s.success() { - Ok(()) - } else { - Err(format!("notify-send exited with {s}")) - } - }) -} - #[cfg(feature = "seccomp")] fn apply_seccomp_filter() -> anyhow::Result<()> { use seccompiler::{BpfProgram, SeccompAction, SeccompFilter, SeccompRule}; @@ -578,6 +535,7 @@ mod tests { #[test] fn engine_disabled_build_refuses_to_run_components() { let err = run_module( + "org.weft.test", std::path::Path::new("app.wasm"), &[], Grants::default(), diff --git a/docs/architecture.md b/docs/architecture.md index 93af5ec..d808d06 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -88,6 +88,8 @@ Each capability-controlled host import (fetch, notifications, clipboard) checks | `sys:clipboard:read` / `sys:clipboard:write` | `weft:app/clipboard#read` / `#write` | | `hw:gpu:compute` / `hw:gpu:render` | Not supported; the launch fails | +Clipboard and notifications run `wl-paste`, `wl-copy` and `notify-send` from the runtime's environment, each bounded to 5 seconds, after which the helper is killed and the call fails. Clipboard text is UTF-8 and at most 1 MiB in either direction. A notification's title is at most 256 bytes and its body 4096; its icon must be an icon theme name, not a path or URL; and it is sent with the app's ID as the application name, so an app cannot pass a notification off as the system's. Where a helper is not installed the call fails with that error. + Fetch does not follow redirects: a redirect is returned to the component as a response, so every destination it requests is checked against its grants. HTTP error statuses are responses too; only policy and transport failures are errors. Only the methods GET, HEAD, POST, PUT, PATCH, DELETE and OPTIONS are accepted, and a component cannot set `Host`, `Content-Length`, `Transfer-Encoding` or other hop-by-hop headers. Connecting times out after 10 seconds and the whole request after 30 seconds, not counting DNS resolution; response bodies are limited to 16 MiB. Fetch requires a runtime built with the `net-fetch` feature. Fetch grants name hosts, not addresses: ports are not restricted, and a host that resolves to a loopback or private address (or `net:fetch:*`) can reach local services. IPv6 literals cannot be granted. From 0c9b2c2b0da3f50928fc7b7622d9022a1b51ab9a Mon Sep 17 00:00:00 2001 From: Marco Allegretti Date: Fri, 9 Oct 2026 19:27:39 +0000 Subject: [PATCH 2/3] fix(runtime): do not wait for the process wl-copy leaves serving the selection wl-copy forks a process that keeps serving the selection. That process inherits the helper's output pipes, so reading them to the end would block a clipboard write until the selection changed. wl-copy's output is now discarded, and its failure is reported by exit status. --- crates/weft-runtime/src/desktop.rs | 61 +++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 10 deletions(-) diff --git a/crates/weft-runtime/src/desktop.rs b/crates/weft-runtime/src/desktop.rs index 528cb4f..b4d0f32 100644 --- a/crates/weft-runtime/src/desktop.rs +++ b/crates/weft-runtime/src/desktop.rs @@ -18,18 +18,38 @@ pub const MAX_CLIPBOARD: usize = 1024 * 1024; pub const MAX_TITLE: usize = 256; pub const MAX_BODY: usize = 4096; +/// What a helper's output streams are connected to. +#[derive(Clone, Copy, PartialEq, Eq)] +enum Output { + /// Read: up to the limit from standard output, and standard error for + /// the failure message. + Captured, + /// Discarded, for a helper that leaves a process running which would + /// keep the streams open, as `wl-copy` does to serve the selection. + Discarded, +} + /// Runs `command` with `input` on its standard input and returns at most /// `max_output` bytes of its standard output, or why it failed. -fn run(mut command: Command, input: Option>, max_output: usize) -> Result, String> { +fn run( + mut command: Command, + input: Option>, + max_output: usize, + output: Output, +) -> Result, String> { let program = command.get_program().to_string_lossy().into_owned(); + let stream = || match output { + Output::Captured => Stdio::piped(), + Output::Discarded => Stdio::null(), + }; let mut child = command .stdin(if input.is_some() { Stdio::piped() } else { Stdio::null() }) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) + .stdout(stream()) + .stderr(stream()) .spawn() .map_err(|e| format!("cannot run {program}: {e}"))?; if let (Some(mut stdin), Some(input)) = (child.stdin.take(), input) { @@ -96,7 +116,7 @@ fn run(mut command: Command, input: Option>, max_output: usize) -> Resul pub fn clipboard_read() -> Result { let mut command = Command::new("wl-paste"); command.args(["--no-newline", "--type", "text/plain;charset=utf-8"]); - let data = run(command, None, MAX_CLIPBOARD)?; + let data = run(command, None, MAX_CLIPBOARD, Output::Captured)?; String::from_utf8(data).map_err(|_| "the clipboard does not hold UTF-8 text".to_owned()) } @@ -106,7 +126,13 @@ pub fn clipboard_write(text: &str) -> Result<(), String> { } let mut command = Command::new("wl-copy"); command.args(["--type", "text/plain;charset=utf-8"]); - run(command, Some(text.as_bytes().to_vec()), 0).map(|_| ()) + run( + command, + Some(text.as_bytes().to_vec()), + 0, + Output::Discarded, + ) + .map(|_| ()) } /// Checks a notification before it is sent. @@ -145,7 +171,7 @@ pub fn notify(app_id: &str, title: &str, body: &str, icon: Option<&str>) -> Resu command.arg(format!("--icon={icon}")); } command.arg("--").arg(title).arg(body); - run(command, None, 0).map(|_| ()) + run(command, None, 0, Output::Captured).map(|_| ()) } #[cfg(test)] @@ -175,23 +201,38 @@ mod tests { let mut slow = Command::new("sleep"); slow.arg("30"); let started = Instant::now(); - let error = run(slow, None, 0).unwrap_err(); + let error = run(slow, None, 0, Output::Captured).unwrap_err(); assert!(error.contains("did not finish"), "{error}"); assert!(started.elapsed() < HELPER_TIMEOUT + Duration::from_secs(2)); let mut chatty = Command::new("head"); chatty.args(["-c", "2000", "/dev/zero"]); assert!( - run(chatty, None, 1000) + run(chatty, None, 1000, Output::Captured) .unwrap_err() .contains("more than 1000 bytes") ); let mut echo = Command::new("cat"); echo.stdin(Stdio::piped()); - assert_eq!(run(echo, Some(b"text".to_vec()), 100).unwrap(), b"text"); + assert_eq!( + run(echo, Some(b"text".to_vec()), 100, Output::Captured).unwrap(), + b"text" + ); + + // A helper that leaves a process behind returns once it exits + // itself when its streams are discarded. + let mut forking = Command::new("sh"); + forking.args(["-c", "sleep 30 & exit 0"]); + let started = Instant::now(); + assert!(run(forking, None, 0, Output::Discarded).is_ok()); + assert!(started.elapsed() < Duration::from_secs(2)); let failing = Command::new("false"); - assert!(run(failing, None, 0).unwrap_err().contains("exited")); + assert!( + run(failing, None, 0, Output::Captured) + .unwrap_err() + .contains("exited") + ); } } From 6055e0b0a0d0bf3fa895e16c44d75621aa29172a Mon Sep 17 00:00:00 2001 From: Marco Allegretti Date: Fri, 9 Oct 2026 19:30:47 +0000 Subject: [PATCH 3/3] fix(runtime): keep helper error messages, and send notification bodies as plain text Discarding wl-copy's output also lost its error message, such as a missing Wayland connection. Its standard error is now kept and read only when it fails, which is always before it leaves its selection server. Other fixes: - An output over the limit is reported as such, instead of as the helper dying of the broken pipe. - The clipboard is read as any text type, since the content is checked as UTF-8 anyway. - Notification bodies are sent with markup escaped, since notification servers may render links and images. - A failed wait for a helper kills and reaps it. --- crates/weft-runtime/src/desktop.rs | 73 +++++++++++++++++++++--------- docs/architecture.md | 2 +- 2 files changed, 53 insertions(+), 22 deletions(-) diff --git a/crates/weft-runtime/src/desktop.rs b/crates/weft-runtime/src/desktop.rs index b4d0f32..afd5709 100644 --- a/crates/weft-runtime/src/desktop.rs +++ b/crates/weft-runtime/src/desktop.rs @@ -24,9 +24,11 @@ enum Output { /// Read: up to the limit from standard output, and standard error for /// the failure message. Captured, - /// Discarded, for a helper that leaves a process running which would - /// keep the streams open, as `wl-copy` does to serve the selection. - Discarded, + /// Standard output discarded and standard error read only when the + /// helper fails, for a helper that leaves a process running which + /// keeps its streams open after succeeding, as `wl-copy` does to + /// serve the selection; it fails, if at all, before that. + ErrorsOnly, } /// Runs `command` with `input` on its standard input and returns at most @@ -38,18 +40,17 @@ fn run( output: Output, ) -> Result, String> { let program = command.get_program().to_string_lossy().into_owned(); - let stream = || match output { - Output::Captured => Stdio::piped(), - Output::Discarded => Stdio::null(), - }; let mut child = command .stdin(if input.is_some() { Stdio::piped() } else { Stdio::null() }) - .stdout(stream()) - .stderr(stream()) + .stdout(match output { + Output::Captured => Stdio::piped(), + Output::ErrorsOnly => Stdio::null(), + }) + .stderr(Stdio::piped()) .spawn() .map_err(|e| format!("cannot run {program}: {e}"))?; if let (Some(mut stdin), Some(input)) = (child.stdin.take(), input) { @@ -93,10 +94,19 @@ fn run( HELPER_TIMEOUT.as_secs() )); } - Err(e) => return Err(e.to_string()), + Err(e) => { + let _ = child.kill(); + let _ = child.wait(); + return Err(e.to_string()); + } } }; let output = stdout.join().unwrap_or_default(); + // Checked first: a helper whose output is cut off at the limit may die + // of the broken pipe. + if output.len() > max_output { + return Err(format!("{program} returned more than {max_output} bytes")); + } if !status.success() { let message = String::from_utf8_lossy(&stderr.join().unwrap_or_default()) .trim() @@ -104,18 +114,16 @@ fn run( return Err(if message.is_empty() { format!("{program} exited with {status}") } else { - message + format!("{program}: {message}") }); } - if output.len() > max_output { - return Err(format!("{program} returned more than {max_output} bytes")); - } Ok(output) } pub fn clipboard_read() -> Result { let mut command = Command::new("wl-paste"); - command.args(["--no-newline", "--type", "text/plain;charset=utf-8"]); + // Any text type; the content must still be UTF-8. + command.args(["--no-newline", "--type", "text"]); let data = run(command, None, MAX_CLIPBOARD, Output::Captured)?; String::from_utf8(data).map_err(|_| "the clipboard does not hold UTF-8 text".to_owned()) } @@ -130,7 +138,7 @@ pub fn clipboard_write(text: &str) -> Result<(), String> { command, Some(text.as_bytes().to_vec()), 0, - Output::Discarded, + Output::ErrorsOnly, ) .map(|_| ()) } @@ -162,6 +170,12 @@ fn is_icon_name(icon: &str) -> bool { .all(|b| b.is_ascii_alphanumeric() || matches!(b, b'-' | b'_' | b'.')) } +fn escape_markup(text: &str) -> String { + text.replace('&', "&") + .replace('<', "<") + .replace('>', ">") +} + /// Sends a notification attributed to `app_id`. pub fn notify(app_id: &str, title: &str, body: &str, icon: Option<&str>) -> Result<(), String> { check_notification(title, body, icon)?; @@ -170,7 +184,9 @@ pub fn notify(app_id: &str, title: &str, body: &str, icon: Option<&str>) -> Resu if let Some(icon) = icon { command.arg(format!("--icon={icon}")); } - command.arg("--").arg(title).arg(body); + // Notification servers may render markup in the body, including links + // and images, so it is sent as plain text. + command.arg("--").arg(title).arg(escape_markup(body)); run(command, None, 0, Output::Captured).map(|_| ()) } @@ -178,6 +194,14 @@ pub fn notify(app_id: &str, title: &str, body: &str, icon: Option<&str>) -> Resu mod tests { use super::*; + #[test] + fn notification_bodies_are_plain_text() { + assert_eq!( + escape_markup("a & b"), + "<a href=\"x\">a & b</a>" + ); + } + #[test] fn notifications_are_bounded_and_icons_are_theme_names() { assert!(check_notification("t", "b", None).is_ok()); @@ -206,15 +230,15 @@ mod tests { assert!(started.elapsed() < HELPER_TIMEOUT + Duration::from_secs(2)); let mut chatty = Command::new("head"); - chatty.args(["-c", "2000", "/dev/zero"]); + // Far more than a pipe holds, so the cut-off kills the writer. + chatty.args(["-c", "10000000", "/dev/zero"]); assert!( run(chatty, None, 1000, Output::Captured) .unwrap_err() .contains("more than 1000 bytes") ); - let mut echo = Command::new("cat"); - echo.stdin(Stdio::piped()); + let echo = Command::new("cat"); assert_eq!( run(echo, Some(b"text".to_vec()), 100, Output::Captured).unwrap(), b"text" @@ -225,9 +249,16 @@ mod tests { let mut forking = Command::new("sh"); forking.args(["-c", "sleep 30 & exit 0"]); let started = Instant::now(); - assert!(run(forking, None, 0, Output::Discarded).is_ok()); + assert!(run(forking, None, 0, Output::ErrorsOnly).is_ok()); assert!(started.elapsed() < Duration::from_secs(2)); + let mut failing = Command::new("sh"); + failing.args(["-c", "echo no display >&2; exit 1"]); + assert_eq!( + run(failing, None, 0, Output::ErrorsOnly).unwrap_err(), + "sh: no display" + ); + let failing = Command::new("false"); assert!( run(failing, None, 0, Output::Captured) diff --git a/docs/architecture.md b/docs/architecture.md index d808d06..8f389a7 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -88,7 +88,7 @@ Each capability-controlled host import (fetch, notifications, clipboard) checks | `sys:clipboard:read` / `sys:clipboard:write` | `weft:app/clipboard#read` / `#write` | | `hw:gpu:compute` / `hw:gpu:render` | Not supported; the launch fails | -Clipboard and notifications run `wl-paste`, `wl-copy` and `notify-send` from the runtime's environment, each bounded to 5 seconds, after which the helper is killed and the call fails. Clipboard text is UTF-8 and at most 1 MiB in either direction. A notification's title is at most 256 bytes and its body 4096; its icon must be an icon theme name, not a path or URL; and it is sent with the app's ID as the application name, so an app cannot pass a notification off as the system's. Where a helper is not installed the call fails with that error. +Clipboard and notifications run `wl-paste`, `wl-copy` and `notify-send` from the runtime's environment, each bounded to 5 seconds, after which the helper is killed and the call fails. Clipboard text is UTF-8, of any text type, and at most 1 MiB in either direction. A notification's title is at most 256 bytes and its body 4096, sent as plain text with markup escaped; its icon must be an icon theme name, not a path or URL; and it is sent with the app's ID as the application name, so an app cannot pass a notification off as the system's. Where a helper is not installed the call fails with that error. Fetch does not follow redirects: a redirect is returned to the component as a response, so every destination it requests is checked against its grants. HTTP error statuses are responses too; only policy and transport failures are errors. Only the methods GET, HEAD, POST, PUT, PATCH, DELETE and OPTIONS are accepted, and a component cannot set `Host`, `Content-Length`, `Transfer-Encoding` or other hop-by-hop headers. Connecting times out after 10 seconds and the whole request after 30 seconds, not counting DNS resolution; response bodies are limited to 16 MiB. Fetch requires a runtime built with the `net-fetch` feature.