Skip to content

Commit a0c57a8

Browse files
fionnhugovk
andauthored
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>
1 parent 3d724dd commit a0c57a8

File tree

4 files changed

+4
-3
lines changed

4 files changed

+4
-3
lines changed

Lib/test/test_webbrowser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ def test_default_open(self):
351351
url = "https://python.org"
352352
self.browser.open(url)
353353
self.assertTrue(self.popen_pipe._closed)
354-
self.assertEqual(self.popen_pipe.cmd, "osascript")
354+
self.assertEqual(self.popen_pipe.cmd, "/usr/bin/osascript")
355355
script = self.popen_pipe.pipe.getvalue()
356356
self.assertEqual(script.strip(), f'open location "{url}"')
357357

Lib/turtledemo/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def __init__(self, filename=None):
136136
# so that our menu bar appears.
137137
subprocess.run(
138138
[
139-
'osascript',
139+
'/usr/bin/osascript',
140140
'-e', 'tell application "System Events"',
141141
'-e', 'set frontmost of the first process whose '
142142
'unix id is {} to true'.format(os.getpid()),

Lib/webbrowser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ def open(self, url, new=0, autoraise=True):
656656
end
657657
'''
658658

659-
osapipe = os.popen("osascript", "w")
659+
osapipe = os.popen("/usr/bin/osascript", "w")
660660
if osapipe is None:
661661
return False
662662

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Invoke :program:`osascript` with absolute path in :mod:`webbrowser` and :mod:`!turtledemo`.

0 commit comments

Comments
 (0)