Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[3.10] gh-143930: Reject leading dashes in webbrowser URLs (GH-143931)#146359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ambv merged 1 commit intopython:3.10fromtomcruiseqi:backport-82a24a4-3.10
Mar 24, 2026
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletionsLib/test/test_webbrowser.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -57,6 +57,11 @@ def test_open(self):
options=[],
arguments=[URL])

deftest_reject_dash_prefixes(self):
browser=self.browser_class(name=CMD_NAME)
withself.assertRaises(ValueError):
browser.open(f"--key=val{URL}")


classBackgroundBrowserCommandTest(CommandTestMixin,unittest.TestCase):

Expand Down
14 changes: 14 additions & 0 deletionsLib/webbrowser.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -154,6 +154,12 @@ def open_new(self, url):
def open_new_tab(self, url):
return self.open(url, 2)

@staticmethod
def _check_url(url):
"""Ensures that the URL is safe to pass to subprocesses as a parameter"""
if url and url.lstrip().startswith("-"):
raise ValueError(f"Invalid URL: {url}")


class GenericBrowser(BaseBrowser):
"""Class for all browsers started with a command
Expand All@@ -171,6 +177,7 @@ def __init__(self, name):

def open(self, url, new=0, autoraise=True):
sys.audit("webbrowser.open", url)
self._check_url(url)
cmdline = [self.name] + [arg.replace("%s", url)
for arg in self.args]
try:
Expand All@@ -191,6 +198,7 @@ def open(self, url, new=0, autoraise=True):
cmdline = [self.name] + [arg.replace("%s", url)
for arg in self.args]
sys.audit("webbrowser.open", url)
self._check_url(url)
try:
if sys.platform[:3] == 'win':
p = subprocess.Popen(cmdline)
Expand DownExpand Up@@ -256,6 +264,7 @@ def _invoke(self, args, remote, autoraise, url=None):

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:
Expand DownExpand Up@@ -357,6 +366,7 @@ class Konqueror(BaseBrowser):

def open(self, url, new=0, autoraise=True):
sys.audit("webbrowser.open", url)
self._check_url(url)
# XXX Currently I know no way to prevent KFM from opening a new win.
if new == 2:
action = "newTab"
Expand DownExpand Up@@ -441,6 +451,7 @@ def _remote(self, action):

def open(self, url, new=0, autoraise=True):
sys.audit("webbrowser.open", url)
self._check_url(url)
if new:
ok = self._remote("LOADNEW " + url)
else:
Expand DownExpand Up@@ -603,6 +614,7 @@ def register_standard_browsers():
class WindowsDefault(BaseBrowser):
def open(self, url, new=0, autoraise=True):
sys.audit("webbrowser.open", url)
self._check_url(url)
try:
os.startfile(url)
except OSError:
Expand DownExpand Up@@ -633,6 +645,7 @@ def __init__(self, name):

def open(self, url, new=0, autoraise=True):
sys.audit("webbrowser.open", url)
self._check_url(url)
assert "'" not in url
# hack for local urls
if not ':' in url:
Expand DownExpand Up@@ -670,6 +683,7 @@ def __init__(self, name):
self._name = name

def open(self, url, new=0, autoraise=True):
self._check_url(url)
if self._name == 'default':
script = 'open location "%s"' % url.replace('"', '%22') # opens in default browser
else:
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
Reject leading dashes in URLs passed to:func:`webbrowser.open`
Loading

[8]ページ先頭

©2009-2026 Movatter.jp