mirror of
https://github.com/python/cpython.git
synced 2026-05-06 04:37:33 -04:00
[3.13] gh-148169: Fix webbrowser %action substitution bypass of dash-prefix check (GH-148170) (#148517)
Co-authored-by: Stan Ulbrych <stan@python.org>
This commit is contained in:
committed by
GitHub
parent
0c83e503cd
commit
d6d68494be
@@ -118,6 +118,15 @@ class ChromeCommandTest(CommandTestMixin, unittest.TestCase):
|
||||
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')
|
||||
# new=1: action is "--new-window", so "%action" itself expands to
|
||||
# a dash-prefixed flag even with no dash in the original URL.
|
||||
with self.assertRaises(ValueError):
|
||||
browser.open('%action', new=1)
|
||||
|
||||
|
||||
class EdgeCommandTest(CommandTestMixin, unittest.TestCase):
|
||||
|
||||
|
||||
+3
-2
@@ -275,7 +275,6 @@ class UnixBrowser(BaseBrowser):
|
||||
|
||||
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:
|
||||
@@ -289,7 +288,9 @@ class UnixBrowser(BaseBrowser):
|
||||
raise Error("Bad 'new' parameter to open(); "
|
||||
f"expected 0, 1, or 2, got {new}")
|
||||
|
||||
args = [arg.replace("%s", url).replace("%action", action)
|
||||
self._check_url(url.replace("%action", action))
|
||||
|
||||
args = [arg.replace("%action", action).replace("%s", url)
|
||||
for arg in self.remote_args]
|
||||
args = [arg for arg in args if arg]
|
||||
success = self._invoke(args, True, autoraise, url)
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
A bypass in :mod:`webbrowser` allowed URLs prefixed with ``%action`` to pass
|
||||
the dash-prefix safety check.
|
||||
Reference in New Issue
Block a user