Skip to content

fix(sitemap): land the sitemap stack and fetch cross-host sitemaps from their own hosts - #494

Merged
tobocop2 merged 29 commits into
integration/0927from
land/sitemap-309
Sep 29, 2026
Merged

tobocop2 merged 29 commits into
integration/0927from
land/sitemap-309

Conversation

@tobocop2

@tobocop2 tobocop2 commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Problem

A sitemap index that listed child sitemaps on other hosts returned none of their pages: each child was moved onto the index's host, collapsed into an address already visited, and dropped. Sitemap addresses were also handled as raw text, and relative addresses resolved against the wrong base after a redirect.

Cross-host sitemaps

Index children and robots.txt sitemap lines on another host are fetched from that host. The SSRF policy checks each fetch, and seed credentials and custom headers go only to the seed host.

Parsed addresses

Redirect targets, index children and urlset entries go through the URL parser before they are fetched, deduplicated or returned. Relative addresses resolve against the address that served the document.

Duplicates

A child that differs only by a fragment is fetched once, and a sitemap that lists itself is not reported as a page.

Search

The map search matches the decoded address after Unicode normalization and case folding, so café finds caf%C3%A9. The Turkish dotted and dotless i are the known exception. A search field on a POST /v1/map request replaces the server's configured search for that call.

Lands #219, #266, #303, #332, #356, #364 and #366.

Closes #207
Closes #227
Closes #226
Closes #323
Closes #324
Closes #339
Closes #338
Closes #398
Closes #363
Closes #362
Closes #268
Closes #374
Closes #349
Closes #340

…ot parse

An absolute redirect target was returned exactly as sent: a
case-sensitive http/https prefix check skipped the URL parser, so an
embedded tab or newline, trailing spaces or an upper-case scheme reached
the follower raw, while a relative target was parsed and normalized.

Resolve every target through the same URL join, which already treats a
target with its own scheme as absolute, and parse the target alone when
the base does not parse. A target that does not parse is refused: its
redirect source (Location, Refresh, meta refresh) contributes nothing,
and sitemap discovery skips it instead of fetching raw text. A refused
target is logged at debug level by source and length only, never by
value, so credentials in it cannot reach the log.

Each refusing call site has a test, and each log site has a capture
test. The capture tests run serially with the tests that reach the same
callsites, because tracing caches the interest of each callsite.

Closes #207
The redirect chain took the next target as a string and ran the SSRF
check only when that string parsed, so a target that did not parse
skipped the check. The redirect resolver now returns a parsed URL, every
redirect source passes it on, and the chain accepts only a parsed URL,
so the check always runs and a string cannot reach it.

Closes #227
A sitemap-index child <loc> that was an absolute same-host address, or
any child when the index URL had no usable base, was fetched as raw
text and used as its own duplicate key. A child with an upper-case
scheme or host, a default port or stray whitespace was fetched
unnormalized and could be fetched twice under two spellings.

Every child now goes through the same resolver as redirect targets, and
the parsed form is both fetched and used as the duplicate key. A child
that does not parse is skipped and logged by length only. The index URL
is logged redacted when it parses, and by length only when it does not,
because the credential redactor returns an address that does not parse
unchanged.

Closes #226
map() returned each urlset <loc> as the trimmed raw text. Two spellings
of one page (an upper-case scheme or host, a default port, an embedded
tab or newline) came back as two entries, a relative <loc> came back as
a bare path, and a <loc> that is not an address came back as text.

Every urlset consumer (the leaf of a sitemap walk and a urlset or gzip
fetched directly) now goes through one collector. It resolves each <loc>
against the sitemap's own URL with the resolver sitemap-index children
use, without their host rewrite, so an entry on another host stays on
that host. A <loc> that does not parse is dropped and logged by length;
the sitemap URL is logged redacted when it parses and by length when it
does not, through the log helper the index-child path now shares.

Entries are deduplicated on the parsed address across every document
of one map() call: the walk context, created once per call, holds the
set behind a mutex that is only locked in synchronous code. A duplicate
is dropped before it counts toward map_limit. A relative <loc> now
resolves to an address, so exclude_paths applies to it, and map_search
matches the normalized address rather than the raw spelling.

Closes #323
…ed and deduped

A sitemap-index child differing from a sibling only by a URL fragment, such as
/a.xml and /a.xml#x, was fetched twice: the fragment never reaches the server,
so both name the same document, but rewrite_url_host kept it on the same-host
and different-host normalization paths before the address was fetched and
used as the duplicate key.

Both are now dropped in rewrite_url_host itself, which fixes it for both of
its callers: the sitemap-index child address (this bug) and the robots.txt
Sitemap: directive address, which is fetched and deduped the same way.

Closes #324
…redirects

A relative <loc> resolved against the sitemap URL the walk requested,
not the URL that answered. When /sitemap.xml redirected to
/nested/sitemap.xml, <loc>page</loc> became /page instead of
/nested/page. Urlset entries and sitemap-index children had the defect
on every fetch path: robots.txt directives, /sitemap.xml, child
sitemaps and a direct fetch of the mapped URL.

Each fetched sitemap document now carries the URL that served it after
redirects, and every <loc> resolves against it. The requested URL stays
the key of the visited set. An absolute index child is rewritten onto
the host that served the index, the same host a relative child resolves
to, so after a redirect to another host the children stay on the
redirect's target host. Both hosts pass the SSRF check before any fetch.

The doc comment on the fetch result's final URL said it always equals
the request URL on native targets. Redirects are followed hop by hop,
so it is the URL of the last hop; the comment now says so.

Closes #339
…dress

map() returns each address in the URL parser's normalized form, which
percent-encodes a non-ASCII path and encodes a non-ASCII host as punycode.
A search for cafe (with an accent) never found the matching
percent-encoded path, and a search for a non-ASCII host name never found
its punycode form, because map_search compared the caller's typed term
against that encoded text directly.

map_search now also matches a decoded, human-readable form of the
address: the host converted back from punycode, and the path, query and
fragment percent-decoded. Punycode is not substring-safe, since it
transforms a whole host label rather than each character on its own, so
normalizing the search term the address's way cannot be made correct for
the host case. Decoding the address instead covers both cases with one
pass, and an ASCII address decodes back to itself unchanged, so today's
ASCII behaviour is untouched.
Brings the stack onto the integration branch before the child resolver
changes, so a cross-host child fetch already runs under the seed-host
scoping of credentials and custom headers.

The redirect resolver keeps the stack's Option<Url> return and its
fallback for an unparseable base, built on the userinfo helpers, so every
resolved target is parsed and carries no userinfo. The redirect sources
take integration's structure (non-web scheme check, meta refresh against
the document base) with typed targets; a target that fails to parse is
logged by length with the source it came from. The urlset reader keeps
the stack's resolver and dedup. map() tests go through a SeedUrl wrapper;
the credentialed-seed log test now calls the urlset reader directly,
since no seed with userinfo reaches map() any more.
…ragment

A sitemap index child with an absolute address was moved onto the host
that served the index, keeping only its path and query. Children on
other hosts, such as blog.example.com and shop.example.com listed by an
index on example.com, all became the index's own address and were
skipped as cycles, so their pages were missing from map().

The child resolver now joins every child, absolute or relative, against
the index URL after redirects through the same resolver as redirect
targets, which strips userinfo, and then drops the fragment. An absolute
child keeps its own host. The SSRF policy checks each child fetch, and
seed credentials and custom headers stay on the seed host. Dropping the
fragment on the resolved address also covers a relative child such as
a.xml#x, which kept its fragment before and was fetched twice (#363).

The #364 test that pinned the collapse now checks that an absolute
child is fetched from its own host after the index redirected.
A robots.txt Sitemap line on another host was moved onto the seed's
host with its path kept, so map() fetched a different document or none.
The sitemaps.org protocol lets robots.txt name a sitemap on another
host. The line is now resolved like any other target and fetched from
its own host; the SSRF policy gates the fetch and seed credentials stay
on the seed host.

That was the last caller of the host-rewrite helper, which reparsed a
URL its callers already held (#268). The helper and its four tests are
deleted.
…ase folding

A map_search term only matched an address with the same Unicode
spelling and simple lower-casing: café written with a combining accent
did not find café, and STRASSE did not find /Straße. The term and the
decoded address are now compared in one key form: canonical
decomposition, default case folding, then canonical composition, from
the ICU4X icu_normalizer (already in the graph through idna) and
icu_casemap crates, both built with compiled data only.

The raw address side stays a lower-case compare: it is ASCII after
parsing, where the key and lower-casing agree. Default case folding
has no locale, so the Turkish dotted and dotless i do not match their
Turkish case partners; the filter doc and the URL discovery guide say
so. The decoded form's doc now says it exists only to match a term,
and the two decoder tests that pass against an identity decoder are
labelled as guards.
POST /v1/map filtered its result with its own lower-case substring
check against the returned address, so a non-ASCII term never matched
an address map() percent-encodes or writes as punycode. The handler now
sets map_search on a per-call config, as the CLI and the MCP map tool
do, so the endpoint matches the same way and gets the Unicode
normalization and case folding of the library filter.

The handler change and its three router tests come from the rescued
work-in-progress on wip/rescue-wt-362.
…d it

The visited set of a sitemap walk held only the requested address of
each document, while children resolve against the address after
redirects since #364. An index at /sitemap.xml that redirected to
/nested/index.xml and listed index.xml was therefore fetched a second
time. The walk now records the address that served an index too, so
that child is a cycle. A redirected index counts twice toward the
document budget, once per address.
…ts.txt address

A relative Sitemap line was resolved against the URL being mapped, so
when robots.txt redirected to another path or host the line pointed at
the wrong sitemap. The robots fetch now also reports the address that
served robots.txt after redirects when it read the file, and map()
resolves each Sitemap line against that address. This is the #364 fix
on the robots.txt path.
A urlset <loc> that is only a query or a fragment, such as ?q=1 or
#frag, resolves to the sitemap's own address, and map() reported the
sitemap document as a page. The same held for a <loc> that is the
sitemap's address itself. Such an entry is now skipped: a <loc> that
starts with a query, or one that resolves to the document's address
once fragments are ignored.
The fuzz crate is its own workspace with its own lockfile, so the two
ICU4X crates the map search filter uses were missing from it; the same
update also records dependencies the lockfile had drifted behind on.
@tobocop2 tobocop2 changed the title fix(sitemap): land the sitemap stack and fetch cross-host child sitemaps from their own hosts fix(sitemap): land the sitemap stack and fetch cross-host sitemaps from their own hosts Sep 29, 2026
Add the tests that catch a robots.txt Sitemap: line on a denied host, one
that redirects to a denied host, and the seed credential and custom header
leaking to that line's own host or to an index child. Nothing in the PR
suite failed if any of those checks were removed.

Label the two existing tests that pass regardless of this change as guards,
with the reason each cannot fail from it.

Correct the changelog line that said a query-only <loc> names the sitemap
document: the code drops it because it is query-only, not because it
resolves to the sitemap's own address, and a served-at-root urlset can
prove the two are different. Add a test that pins the dropped case.
The scrape-path GUARD comment in ssrf_integration.rs credited http_fetch
with re-validating a redirect hop; a scrape never calls http_fetch, so
the real second check is the Tower service's do_fetch in
tower/service.rs. Name it instead.

The names_the_sitemap_itself doc and the map.rs assertion message said a
query-only <loc> is dropped for naming the sitemap document. It is
dropped for being query-only; /?page=2 served from / is a page, as the
PR's own test shows. Only a <loc> that resolves to the sitemap's own
address, once a fragment is ignored, is dropped for naming it.

No behaviour change.
@tobocop2
tobocop2 marked this pull request as ready for review September 29, 2026 03:56
@tobocop2
tobocop2 requested a review from Goldziher as a code owner September 29, 2026 03:56
@tobocop2
tobocop2 merged commit 2051cfa into integration/0927 Sep 29, 2026
tobocop2 added a commit that referenced this pull request Sep 29, 2026
The stack under this branch landed on integration as one squash (#494).
Every conflict takes integration's side; this branch's own change sits on
top. Integration's link extractor now also takes the page text, so the
HTML branch passes it along with the final URL.
tobocop2 added a commit that referenced this pull request Sep 29, 2026
Brings in 2051cfa (#494, sitemap stack). The merge auto-resolved
CHANGELOG.md, the docs changelog, engine/redirect.rs and http.rs; no
other file conflicted. alef 0.97.1 regeneration on the box left the
generation-inputs hash unchanged, so no further hash update is needed.
@Goldziher
Goldziher deleted the land/sitemap-309 branch October 10, 2026 07:50
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.

1 participant