From 264b1cad9a23131bad8ede3b4f0613e3dcb9002e Mon Sep 17 00:00:00 2001 From: MackDing Date: Fri, 22 May 2026 10:01:39 +0800 Subject: [PATCH] fix: avoid shell interpolation in permission dialogs --- gui_agents/s1/cli_app.py | 35 +++++++++++++++++++++++++++++------ gui_agents/s2/cli_app.py | 35 +++++++++++++++++++++++++++++------ gui_agents/s2_5/cli_app.py | 35 +++++++++++++++++++++++++++++------ gui_agents/s3/cli_app.py | 35 +++++++++++++++++++++++++++++------ 4 files changed, 116 insertions(+), 24 deletions(-) diff --git a/gui_agents/s1/cli_app.py b/gui_agents/s1/cli_app.py index 68ac3d5c..a2b0f57a 100644 --- a/gui_agents/s1/cli_app.py +++ b/gui_agents/s1/cli_app.py @@ -5,6 +5,7 @@ import os import platform import signal +import subprocess import sys import time @@ -138,16 +139,38 @@ def signal_handler(signum, frame): def show_permission_dialog(code: str, action_description: str): """Show a platform-specific permission dialog and return True if approved.""" + prompt_text = ( + "Do you want to execute this action?\n\n" + f"{code}" + ) + if action_description: + prompt_text += f" which will try to {action_description}" + if platform.system() == "Darwin": - result = os.system( - f'osascript -e \'display dialog "Do you want to execute this action?\n\n{code} which will try to {action_description}" with title "Action Permission" buttons {{"Cancel", "OK"}} default button "OK" cancel button "Cancel"\'' + script = ( + 'display dialog argv item 1 with title "Action Permission" ' + 'buttons {"Cancel", "OK"} default button "OK" cancel button "Cancel"' + ) + result = subprocess.run( + ["osascript", "-e", script, prompt_text], + check=False, ) - return result == 0 + return result.returncode == 0 elif platform.system() == "Linux": - result = os.system( - f'zenity --question --title="Action Permission" --text="Do you want to execute this action?\n\n{code}" --width=400 --height=200' + result = subprocess.run( + [ + "zenity", + "--question", + "--title", + "Action Permission", + "--text", + prompt_text, + "--width=400", + "--height=200", + ], + check=False, ) - return result == 0 + return result.returncode == 0 return False diff --git a/gui_agents/s2/cli_app.py b/gui_agents/s2/cli_app.py index f03aa8e1..f909c005 100644 --- a/gui_agents/s2/cli_app.py +++ b/gui_agents/s2/cli_app.py @@ -6,6 +6,7 @@ import platform import pyautogui import signal +import subprocess import sys import time @@ -131,16 +132,38 @@ def signal_handler(signum, frame): def show_permission_dialog(code: str, action_description: str): """Show a platform-specific permission dialog and return True if approved.""" + prompt_text = ( + "Do you want to execute this action?\n\n" + f"{code}" + ) + if action_description: + prompt_text += f" which will try to {action_description}" + if platform.system() == "Darwin": - result = os.system( - f'osascript -e \'display dialog "Do you want to execute this action?\n\n{code} which will try to {action_description}" with title "Action Permission" buttons {{"Cancel", "OK"}} default button "OK" cancel button "Cancel"\'' + script = ( + 'display dialog argv item 1 with title "Action Permission" ' + 'buttons {"Cancel", "OK"} default button "OK" cancel button "Cancel"' + ) + result = subprocess.run( + ["osascript", "-e", script, prompt_text], + check=False, ) - return result == 0 + return result.returncode == 0 elif platform.system() == "Linux": - result = os.system( - f'zenity --question --title="Action Permission" --text="Do you want to execute this action?\n\n{code}" --width=400 --height=200' + result = subprocess.run( + [ + "zenity", + "--question", + "--title", + "Action Permission", + "--text", + prompt_text, + "--width=400", + "--height=200", + ], + check=False, ) - return result == 0 + return result.returncode == 0 return False diff --git a/gui_agents/s2_5/cli_app.py b/gui_agents/s2_5/cli_app.py index a6e34fa8..6944da54 100644 --- a/gui_agents/s2_5/cli_app.py +++ b/gui_agents/s2_5/cli_app.py @@ -6,6 +6,7 @@ import platform import pyautogui import signal +import subprocess import sys import time @@ -131,16 +132,38 @@ def signal_handler(signum, frame): def show_permission_dialog(code: str, action_description: str): """Show a platform-specific permission dialog and return True if approved.""" + prompt_text = ( + "Do you want to execute this action?\n\n" + f"{code}" + ) + if action_description: + prompt_text += f" which will try to {action_description}" + if platform.system() == "Darwin": - result = os.system( - f'osascript -e \'display dialog "Do you want to execute this action?\n\n{code} which will try to {action_description}" with title "Action Permission" buttons {{"Cancel", "OK"}} default button "OK" cancel button "Cancel"\'' + script = ( + 'display dialog argv item 1 with title "Action Permission" ' + 'buttons {"Cancel", "OK"} default button "OK" cancel button "Cancel"' + ) + result = subprocess.run( + ["osascript", "-e", script, prompt_text], + check=False, ) - return result == 0 + return result.returncode == 0 elif platform.system() == "Linux": - result = os.system( - f'zenity --question --title="Action Permission" --text="Do you want to execute this action?\n\n{code}" --width=400 --height=200' + result = subprocess.run( + [ + "zenity", + "--question", + "--title", + "Action Permission", + "--text", + prompt_text, + "--width=400", + "--height=200", + ], + check=False, ) - return result == 0 + return result.returncode == 0 return False diff --git a/gui_agents/s3/cli_app.py b/gui_agents/s3/cli_app.py index 55816be0..aceabca1 100644 --- a/gui_agents/s3/cli_app.py +++ b/gui_agents/s3/cli_app.py @@ -6,6 +6,7 @@ import platform import pyautogui import signal +import subprocess import sys import time @@ -132,16 +133,38 @@ def signal_handler(signum, frame): def show_permission_dialog(code: str, action_description: str): """Show a platform-specific permission dialog and return True if approved.""" + prompt_text = ( + "Do you want to execute this action?\n\n" + f"{code}" + ) + if action_description: + prompt_text += f" which will try to {action_description}" + if platform.system() == "Darwin": - result = os.system( - f'osascript -e \'display dialog "Do you want to execute this action?\n\n{code} which will try to {action_description}" with title "Action Permission" buttons {{"Cancel", "OK"}} default button "OK" cancel button "Cancel"\'' + script = ( + 'display dialog argv item 1 with title "Action Permission" ' + 'buttons {"Cancel", "OK"} default button "OK" cancel button "Cancel"' + ) + result = subprocess.run( + ["osascript", "-e", script, prompt_text], + check=False, ) - return result == 0 + return result.returncode == 0 elif platform.system() == "Linux": - result = os.system( - f'zenity --question --title="Action Permission" --text="Do you want to execute this action?\n\n{code}" --width=400 --height=200' + result = subprocess.run( + [ + "zenity", + "--question", + "--title", + "Action Permission", + "--text", + prompt_text, + "--width=400", + "--height=200", + ], + check=False, ) - return result == 0 + return result.returncode == 0 return False