python / python/cpython

urllib.robotparser.RobotFileParser.can_fetch crashes on a malformed URL

オープン
#153,795 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

stdlib type-bug
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

Bug description:

urllib.robotparser.RobotFileParser.can_fetch is documented to return a bool,
but it passes url straight to urllib.parse._urlsplit, so a malformed URL
(an unterminated IPv6 authority) raises a bare ValueError instead of a
result:

import urllib.robotparser
p = urllib.robotparser.RobotFileParser()
p.parse(["User-agent: *", "Disallow: /"])
p.can_fetch("*", "http://[::1")   # ValueError: Invalid IPv6 URL

The url argument is crawl-frontier-controlled (it comes from parsed pages).

Proposed behavior: a URL that cannot be parsed matches no rule, so can_fetch
returns True (RFC 9309 default that access is not restricted when no rule
applies), rather than raising or being conservatively False.

This is a sibling of #153404 (robotparser raising ValueError on a non-decimal
digit in Crawl-delay / Request-rate); the sink there is the robots.txt
content, here it is the url argument.

CPython versions tested on:

3.13, 3.14, 3.15

Operating systems tested on:

macOS

Linked PRs
  • gh-153796

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

urllib.robotparser.RobotFileParser.can_fetch から始め、終端されていない IPv6 authority を含む不正な URL のケースを再現します。urllib.parse._urlsplit が入力をどのように処理するかを確認します。can_fetch が ValueError を送出せずに True を返し、不正な URL の動作に対するカバレッジが含まれていれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
networking
issue の種類
バグ
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。