Skip to content

fix(robots): preserve query string order in robots.txt matching#903

Open
Noethix55555 wants to merge 1 commit into
gocolly:masterfrom
Noethix55555:fix/robots-query-order
Open

fix(robots): preserve query string order in robots.txt matching#903
Noethix55555 wants to merge 1 commit into
gocolly:masterfrom
Noethix55555:fix/robots-query-order

Conversation

@Noethix55555

Copy link
Copy Markdown

Fixes #902

robots.txt path matching treats the path and query as an ordered, opaque string. checkRobots re-encoded the query with u.Query().Encode(), which alphabetically sorts the keys. As a result a Disallow rule containing a query string (e.g. /p?z=) failed to match a URL with the same keys in a different on-wire order, silently bypassing the rule.

This uses u.RawQuery verbatim. Added a regression test serving Disallow: /p?z= and asserting that /p?z=1&a=2 is blocked; it fails on master (request is served with 200) and passes with the fix.

robots.txt path matching treats the path and query as an ordered,
opaque string. checkRobots re-encoded the query with u.Query().Encode(),
which alphabetically sorts the keys, so a Disallow rule containing a
query string (e.g. /p?z=) failed to match a URL with the same keys in
a different order. Use u.RawQuery verbatim instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

robots.txt query string is re-sorted, bypassing Disallow rules with query strings

1 participant