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#146359

Open
tomcruiseqi wants to merge 1 commit intopython:3.10from
tomcruiseqi:backport-82a24a4-3.10
Open

[3.10] gh-143930: Reject leading dashes in webbrowser URLs#146359
tomcruiseqi wants to merge 1 commit intopython:3.10from
tomcruiseqi:backport-82a24a4-3.10

Conversation

@tomcruiseqi
Copy link

@tomcruiseqitomcruiseqi commentedMar 24, 2026
edited by bedevere-appbot
Loading

Copy link

CopilotAI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Pull request overview

This PR backports a security hardening change towebbrowser to prevent option-injection style issues by rejecting URLs that begin with- (after leading whitespace) before passing them to browser launchers.

Changes:

  • AddBaseBrowser._check_url() to reject leading-dash URLs with aValueError.
  • Invoke_check_url() from multipleopen() implementations that launch browsers.
  • Add a regression test and a Security NEWS blurb.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

FileDescription
Misc/NEWS.d/next/Security/2026-01-16-12-04-49.gh-issue-143930.zYC5x3.rstDocuments the security behavior change inwebbrowser.open().
Lib/webbrowser.pyIntroduces URL validation and applies it to several browser controllers.
Lib/test/test_webbrowser.pyAdds a test ensuring leading-dash inputs are rejected (currently forGenericBrowser).

💡Add Copilot custom instructions for smarter, more guided reviews.Learn how to get started.

def_check_url(url):
"""Ensures that the URL is safe to pass to subprocesses as a parameter"""
ifurlandurl.lstrip().startswith("-"):
raiseValueError(f"Invalid URL:{url}")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The ValueError message interpolates the raw URL, which can include control characters/newlines and makes logs/debug output ambiguous. Consider using a safer/clearer representation (e.g.,url!r) and/or a message that specifically calls out “URLs must not start with '-' after leading whitespace”.

Suggested change
raiseValueError(f"Invalid URL:{url}")
raiseValueError(
f"Invalid URL{url!r}: URLs must not start with '-' after leading whitespace"
)

Copilot uses AI. Check for mistakes.
Comment on lines +157 to +161
@staticmethod
def_check_url(url):
"""Ensures that the URL is safe to pass to subprocesses as a parameter"""
ifurlandurl.lstrip().startswith("-"):
raiseValueError(f"Invalid URL:{url}")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

_check_url() is only effective when each browser implementation calls it. CurrentlyMacOSXOSAScript.open() andGrail.open() do not call_check_url(), so on macOS (default controller) and when Grail is available,webbrowser.open() can still accept leading-dash values. If the intent is to reject leading dashes for allwebbrowser.open() calls, add_check_url() calls to those implementations (or enforce the check once in the module-levelopen() function).

Copilot uses AI. Check for mistakes.
Comment on lines +60 to +64
deftest_reject_dash_prefixes(self):
browser=self.browser_class(name=CMD_NAME)
withself.assertRaises(ValueError):
browser.open(f"--key=val{URL}")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The new test only exercisesGenericBrowser.open(), but this change also adds_check_url() calls in several other controllers (e.g.,BackgroundBrowser,UnixBrowser,Konqueror, and platform-specific implementations). Consider adding a small parametrized test (or a mixin-based loop) to assert that each affectedbrowser_class.open() rejects leading-dash inputs, so the security behavior is covered across implementations.

Copilot uses AI. Check for mistakes.
(cherry picked from commit82a24a4)Co-authored-by: Seth Michael Larson <seth@python.org>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

Copilot code reviewCopilotCopilot left review comments

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@tomcruiseqi@sethmlarson

[8]ページ先頭

©2009-2026 Movatter.jp