Skip to content

Commit 9e42d0b

Browse files
StanFromIrelandmcepl
authored andcommitted
(CVE-2026-4786) Fix webbrowser %action substitution bypass of dash-prefix check
The patch fixes a security bypass in webbrowser.open() where %action expansion could be exploited to circumvent the dash-prefix argument-injection mitigation Fixes: bsc#1262319 (CVE-2026-4786) Fixes: gh#python#148169 From-PR: gh#python/cpython!148170 Patch: CVE-2026-4786-webbrowser-open-action.patch
1 parent 00e27d3 commit 9e42d0b

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

‎Lib/test/test_webbrowser.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ def test_open_new_tab(self):
9393
options=[],
9494
arguments=[URL])
9595

96+
def test_reject_action_dash_prefixes(self):
97+
browser = self.browser_class(name=CMD_NAME)
98+
with self.assertRaises(ValueError):
99+
browser.open('%action--incognito')
100+
# new=1: action is "--new-window", so "%action" itself expands to
101+
# a dash-prefixed flag even with no dash in the original URL.
102+
with self.assertRaises(ValueError):
103+
browser.open('%action', new=1)
96104

97105
class MozillaCommandTest(CommandTestMixin, unittest.TestCase):
98106

‎Lib/webbrowser.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ def _invoke(self, args, remote, autoraise):
227227
return not p.wait()
228228

229229
def open(self, url, new=0, autoraise=True):
230-
self._check_url(url)
231230
if new == 0:
232231
action = self.remote_action
233232
elif new == 1:
@@ -241,7 +240,9 @@ def open(self, url, new=0, autoraise=True):
241240
raise Error("Bad 'new' parameter to open(); " +
242241
"expected 0, 1, or 2, got %s" % new)
243242

244-
args = [arg.replace("%s", url).replace("%action", action)
243+
self._check_url(url.replace("%action", action))
244+
245+
args = [arg.replace("%action", action).replace("%s", url)
245246
for arg in self.remote_args]
246247
args = [arg for arg in args if arg]
247248
success = self._invoke(args, True, autoraise)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
A bypass in :mod:`webbrowser` allowed URLs prefixed with ``%action`` to pass
2+
the dash-prefix safety check.

0 commit comments

Comments
 (0)