Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Lib/test/test_webbrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ def test_open_bad_new_parameter(self):
arguments=[URL],
kw=dict(new=999))

def test_reject_action_dash_prefixes(self):
browser = self.browser_class(name=CMD_NAME)
with self.assertRaises(ValueError):
browser.open('%action--incognito')


class EdgeCommandTest(CommandTestMixin, unittest.TestCase):

Expand Down
3 changes: 2 additions & 1 deletion Lib/webbrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ def _invoke(self, args, remote, autoraise, url=None):

def open(self, url, new=0, autoraise=True):
sys.audit("webbrowser.open", url)
self._check_url(url)
if new == 0:
action = self.remote_action
elif new == 1:
Expand All @@ -288,6 +287,8 @@ def open(self, url, new=0, autoraise=True):
raise Error("Bad 'new' parameter to open(); "
f"expected 0, 1, or 2, got {new}")

self._check_url(url.replace("%action", action))

args = [arg.replace("%s", url).replace("%action", action)
for arg in self.remote_args]
args = [arg for arg in args if arg]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
A bypass in :mod:`webbrowser` allowed URLs prefixed with ``%action`` to pass
the dash-prefix safety check.
Loading