Skip to content

Commit c70ee10

Browse files
Fix webbrowser `%action check bypass
1 parent 70d1b08 commit c70ee10

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Lib/test/test_webbrowser.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ def test_open_bad_new_parameter(self):
116116
arguments=[URL],
117117
kw=dict(new=999))
118118

119+
def test_reject_action_dash_prefixes(self):
120+
browser = self.browser_class(name=CMD_NAME)
121+
with self.assertRaises(ValueError):
122+
browser.open('%action--incognito')
123+
119124

120125
class EdgeCommandTest(CommandTestMixin, unittest.TestCase):
121126

Lib/webbrowser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ def _invoke(self, args, remote, autoraise, url=None):
274274

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

290+
self._check_url(url.replace("%action", action))
291+
291292
args = [arg.replace("%s", url).replace("%action", action)
292293
for arg in self.remote_args]
293294
args = [arg for arg in args if arg]

0 commit comments

Comments
 (0)