]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.10] gh-148169: Fix webbrowser `%action` substitution bypass of dash-prefix check...
authorStan Ulbrych <stan@python.org>
Mon, 13 Apr 2026 21:41:53 +0000 (22:41 +0100)
committerGitHub <noreply@github.com>
Mon, 13 Apr 2026 21:41:53 +0000 (22:41 +0100)
(cherry picked from commit d22922c8a7958353689dc4763dd72da2dea03fff)

Lib/test/test_webbrowser.py
Lib/webbrowser.py
Misc/NEWS.d/next/Security/2026-03-31-09-15-51.gh-issue-148169.EZJzz2.rst [new file with mode: 0644]

index c9f8f1bb8f16d8c97b066e7ff086ad3a2b38ec1d..05ad9b0d6f26f9dbda340da88ded4ef4e8c5733b 100644 (file)
@@ -101,6 +101,14 @@ class ChromeCommandTest(CommandTestMixin, unittest.TestCase):
                    options=[],
                    arguments=[URL])
 
+    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 MozillaCommandTest(CommandTestMixin, unittest.TestCase):
 
index 866633790860c3c1e2423e934d700d32a64e2957..dbea4cabe3277d1aec1af32d43b1ed631e346be1 100755 (executable)
@@ -264,7 +264,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:
@@ -278,7 +277,9 @@ class UnixBrowser(BaseBrowser):
             raise Error("Bad 'new' parameter to open(); " +
                         "expected 0, 1, or 2, got %s" % 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)
diff --git a/Misc/NEWS.d/next/Security/2026-03-31-09-15-51.gh-issue-148169.EZJzz2.rst b/Misc/NEWS.d/next/Security/2026-03-31-09-15-51.gh-issue-148169.EZJzz2.rst
new file mode 100644 (file)
index 0000000..45cdeeb
--- /dev/null
@@ -0,0 +1,2 @@
+A bypass in :mod:`webbrowser` allowed URLs prefixed with ``%action`` to pass
+the dash-prefix safety check.