From 56eac226a0fee9ca1cd8076631150f1006f18025 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 27 Oct 2026 18:14:44 +0000 Subject: [PATCH 1/2] fix(stdlib): prevent command injection in notification alert on Windows Fixed command injection vulnerability in alert function of std.notification on Windows by replacing msg.exe execution with Base64 UTF-16LE encoded PowerShell script invocation. Co-authored-by: Tcode-Motion <188012755+Tcode-Motion@users.noreply.github.com> --- stdlib/src/notification.rs | 69 +++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/stdlib/src/notification.rs b/stdlib/src/notification.rs index b4898fe7..a424a94e 100644 --- a/stdlib/src/notification.rs +++ b/stdlib/src/notification.rs @@ -78,7 +78,20 @@ impl StdlibRegistry { let msg = args[0].to_string(); #[cfg(target_os = "windows")] { - let _ = std::process::Command::new("msg").args(["*", &msg]).spawn(); + use base64::Engine; + use std::process::Command; + + let b64_msg = base64::engine::general_purpose::STANDARD.encode(msg.encode_utf16().flat_map(|c| c.to_le_bytes()).collect::>()); + + let script = format!( + "Add-Type -AssemblyName PresentationFramework; [System.Windows.MessageBox]::Show([System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String('{}')), 'Alert')", + b64_msg + ); + let b64_script = base64::engine::general_purpose::STANDARD.encode(script.encode_utf16().flat_map(|c| c.to_le_bytes()).collect::>()); + + let _ = Command::new("powershell") + .args(["-EncodedCommand", &b64_script]) + .spawn(); } #[cfg(not(target_os = "windows"))] { @@ -127,4 +140,58 @@ mod tests { assert_eq!(alert.name(), "alert"); assert_eq!(alert.arity(), 1); } + + #[test] + fn test_alert_execution_with_special_characters() { + use std::collections::HashSet; + use techscript_runtime::context::{RuntimeConfig, RuntimeContext}; + + let mut registry = StdlibRegistry { + modules: std::collections::HashMap::new(), + }; + registry.register_notification(); + + let module = registry.get_module("std.notification").unwrap(); + let alert = module.exports.get("alert").unwrap(); + + let mut caps = HashSet::new(); + caps.insert(Capability::Process); + let mut ctx = RuntimeContext::new(RuntimeConfig { + strict_mode: false, + max_recursion_depth: 1000, + enable_assertions: true, + capabilities: caps, + }); + + // Test alert with quotes and special characters to ensure escaping/encoding safety + let result = alert.call( + &mut ctx, + vec![RuntimeValue::Str("Hello 'world' \"& calc.exe;".to_string())], + ); + assert!(result.is_ok()); + } + + #[test] + fn test_alert_capability_denied() { + use std::collections::HashSet; + use techscript_runtime::context::{RuntimeConfig, RuntimeContext}; + + let mut registry = StdlibRegistry { + modules: std::collections::HashMap::new(), + }; + registry.register_notification(); + + let module = registry.get_module("std.notification").unwrap(); + let alert = module.exports.get("alert").unwrap(); + + let mut ctx = RuntimeContext::new(RuntimeConfig { + strict_mode: false, + max_recursion_depth: 1000, + enable_assertions: true, + capabilities: HashSet::new(), // Deny all capabilities including Process + }); + + let result = alert.call(&mut ctx, vec![RuntimeValue::Str("Test alert".to_string())]); + assert!(result.is_err()); + } } From 34614e65122d0d3759da06388e6d1dc2d7e4c8a3 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 27 Oct 2026 19:36:11 +0000 Subject: [PATCH 2/2] fix(stdlib): prevent command injection in notification alert on Windows Fixed command injection vulnerability in alert function of std.notification on Windows by replacing msg.exe execution with Base64 UTF-16LE encoded PowerShell script invocation. Co-authored-by: Tcode-Motion <188012755+Tcode-Motion@users.noreply.github.com>