Commit 87e3437
authored
fix(robots): disallow crawling when robots.txt returns a 5xx (#2065)
`RobotsTxtFile.load` only special-cased 4xx responses (file unavailable
-> allow
all) and parsed the raw response body as robots rules for every other
status. The
HTTP clients do not raise on 5xx, so a server-error response reached
that branch and
its body was handed to Protego. Protego reads a non-robots body (for
example an HTML
`500` error page, or an empty body) as allow-all, so a transient 5xx on
`robots.txt`
silently permitted crawling every URL, the opposite of what the site
expects while it
is failing.
Per RFC 9309 section 2.3.1.4, a `robots.txt` that is unreachable due to
server errors
(5xx) is undefined and a crawler "MUST assume complete disallow". This
PR handles 5xx
explicitly with a disallow-all directive, using the existing
`is_status_code_server_error` helper. The 4xx (allow-all, section
2.3.1.3), 2xx/3xx
(parse the body), and network-error paths are left unchanged.
This only affects users who opt in with `respect_robots_txt_file=True`,
and only when
`robots.txt` returns a 5xx: previously such a response allowed crawling
everything, now
it correctly disallows until the file is reachable again. It also
matches crawlee-JS,
which never parses a non-2xx `robots.txt` body as rules.1 parent 272bb28 commit 87e3437
2 files changed
Lines changed: 20 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
65 | 69 | | |
66 | 70 | | |
67 | 71 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
28 | 38 | | |
29 | 39 | | |
30 | 40 | | |
| |||
0 commit comments