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.11] gh-143930: Reject leading dashes in webbrowser URLs (GH-143931)#146364

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

[3.11] gh-143930: Reject leading dashes in webbrowser URLs (GH-143931)#146364
tomcruiseqi wants to merge 1 commit intopython:3.11from
tomcruiseqi:backport-82a24a4-3.11

Conversation

@tomcruiseqi
Copy link

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

CopilotAI review requested due to automatic review settingsMarch 24, 2026 09:40
@tomcruiseqitomcruiseqi changed the titlegh-143930: Reject leading dashes in webbrowser URLs[3.11] gh-143930: Reject leading dashes in webbrowser URLs (GH-143931)Mar 24, 2026
@bedevere-appbedevere-appbot added the type-securityA security issue labelMar 24, 2026
@tomcruiseqitomcruiseqi changed the title[3.11] gh-143930: Reject leading dashes in webbrowser URLs (GH-143931)[3.11] gh-143930: Reject leading dashes in webbrowser URLsMar 24, 2026
@tomcruiseqitomcruiseqi changed the title[3.11] gh-143930: Reject leading dashes in webbrowser URLs[3.11] gh-143930: Reject leading dashes in webbrowser URLs (GH-143931)Mar 24, 2026
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

Security hardening forwebbrowser to prevent option-injection style issues when URLs are forwarded to external browser commands.

Changes:

  • Add URL validation that rejects inputs whose first non-whitespace character is-.
  • Invoke this validation across built-in browser controller implementations before launching/dispatching.
  • Add a regression test for the new rejection behavior and a Security NEWS entry.

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 forwebbrowser.open().
Lib/webbrowser.pyIntroduces_check_url() and applies it to multiple controllers before executing browser actions.
Lib/test/test_webbrowser.pyAdds a regression test ensuring dash-prefixed inputs are rejected.

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

Comment on lines +158 to +163
@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.

Becauseregister() can return controllers that don’t inherit fromBaseBrowser (and therefore won’t call_check_url()), invalid dash-prefixed URLs can still reach custom backends viawebbrowser.open(). To make the guarantee match the NEWS entry/title, consider validating once at the public API boundary (module-levelopen() /open_new*()) before dispatching to any controller.

Copilot uses AI. Check for mistakes.
Comment on lines +62 to +66
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.

This adds coverage forGenericBrowser, but the new URL validation is also invoked byBackgroundBrowser,UnixBrowser subclasses, and platform-specific controllers. Consider factoring this intoCommandTestMixin (or adding equivalent tests per class) so the rejection behavior is enforced across the other command-based browser implementations too.

Copilot uses AI. Check for mistakes.
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 includes the raw URL; using repr (or otherwise escaping/quoting) would make the exception unambiguous and avoid embedding control characters/newlines in error output. Consider formatting the URL with !r and/or using a more specific message (e.g., that leading dashes are rejected).

Suggested change
raiseValueError(f"Invalid URL:{url}")
raiseValueError(f"Invalid URL (leading dashes are not allowed):{url!r}")

Copilot uses AI. Check for mistakes.
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

Labels

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