gh-137586: Open external osascript program with absolute path (GH-137584)

Open web browser with absolute path

On macOS, web browsers are opened via popen calling osascript. However,
if a user has a colliding osascript executable earlier in their PATH,
this may fail or cause unwanted behaviour.

Depending on one's environment or level of paranoia, this may be considered a security vulnerability.

Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
This commit is contained in:
Fionn 2026-04-07 00:42:10 +08:00 committed by GitHub
parent 3d724dd914
commit a0c57a8d17
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 4 additions and 3 deletions

View file

@ -351,7 +351,7 @@ def test_default_open(self):
url = "https://python.org"
self.browser.open(url)
self.assertTrue(self.popen_pipe._closed)
self.assertEqual(self.popen_pipe.cmd, "osascript")
self.assertEqual(self.popen_pipe.cmd, "/usr/bin/osascript")
script = self.popen_pipe.pipe.getvalue()
self.assertEqual(script.strip(), f'open location "{url}"')

View file

@ -136,7 +136,7 @@ def __init__(self, filename=None):
# so that our menu bar appears.
subprocess.run(
[
'osascript',
'/usr/bin/osascript',
'-e', 'tell application "System Events"',
'-e', 'set frontmost of the first process whose '
'unix id is {} to true'.format(os.getpid()),

View file

@ -656,7 +656,7 @@ def open(self, url, new=0, autoraise=True):
end
'''
osapipe = os.popen("osascript", "w")
osapipe = os.popen("/usr/bin/osascript", "w")
if osapipe is None:
return False

View file

@ -0,0 +1 @@
Invoke :program:`osascript` with absolute path in :mod:`webbrowser` and :mod:`!turtledemo`.