Keep an out-of-scope redirect from stopping the crawl - #86
Merged
Conversation
urlx.SameSite matches hostnames exactly, so a seed that redirects apex to www (or the reverse) lands on a host the scope rejects. Resolving the page's relative links against that host put every one of them out of scope: they stayed absolute, nothing was enqueued, and the crawl saved the seed page and stopped. Assets go through SameRegistrableDomain and kept downloading, so the run ended with a complete-looking single page and no error. scopedResolveBase falls back to the document <base href>, and then to the enqueued URL, when the redirect target is out of scope. A redirect that genuinely leaves the site keeps the previous behaviour, since those links are out of scope either way and are re-fetched and re-redirected if they are reached on their own. Follow-up to #74.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #74.
urlx.SameSitematches hostnames exactly (urlx/urlx.go:212), with subdomains in scope only under--subdomains. So when a seedhttps://example.com/redirects tohttps://www.example.com/, which is how a large share of the web is configured, resolving the page's relative links against the final URL puts every one of them out of scope. They stay absolute, none are enqueued, and the crawl saves the seed page and stops. The reverse, www to apex, breaks the same way.The failure is quiet. Assets are matched with
SameRegistrableDomain, which foldswww.example.comandexample.comtogether, so they keep downloading and the run ends with a complete-looking single page and no error.Probe against the merged tree before this change:
scopedResolveBasefalls back to the document<base href>, and then to the enqueued URL, when the redirect target is out of scope. A redirect that genuinely leaves the site (example.com/go/xtopartner.com) keeps the previous behaviour, since those links are out of scope either way and get re-fetched and re-redirected if they are reached on their own.TestScopedResolveBaseKeepsRedirectInScopecovers apex to www, www to apex, a same-host redirect still winning, an off-scope document base being dropped, and an in-scope document base surviving an off-scope redirect. Each case also asserts the chosen base is in scope, which is the property that actually matters.Separately worth an issue rather than this PR: when the seed itself redirects to another host, adopting the final host as the crawl scope is probably what
kage clone example.commeans. That changesc.seedHostand the output directory, so it is a design decision.