]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-148169: Fix webbrowser `%action` substitution bypass of dash-prefix check (#148170)
authorStan Ulbrych <stan@python.org>
Mon, 13 Apr 2026 19:02:52 +0000 (20:02 +0100)
committerGitHub <noreply@github.com>
Mon, 13 Apr 2026 19:02:52 +0000 (19:02 +0000)
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 299dc185fcf21155d67c0a478c549d9d81bed64b..2ba3af8d5bf22fc8e4aded70d604b4d804bf87c7 100644 (file)
@@ -119,6 +119,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):
 
index 0e0b5034e5f53d981ea95cf034a3a3c30e4ea735..97aad6eea509eb54db0c10523f66dccbb9c34069 100644 (file)
@@ -274,7 +274,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:
@@ -288,7 +287,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)
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.