Repository navigation
fix(crawler): read gzip sitemaps within 50 MB, a guessed path that answers HTML is no sitemap (#662, #670) - #686
Conversation
…swers HTML is no sitemap #662 #670 #662: a gzip child sitemap (.xml.gz served as application/gzip, no Content-Encoding) reached the XML parser as compressed bytes and was reported as "Unknown sitemap format". The walk now reads the body as bytes, undoes Content-Encoding itself (fetched with Bun's decompress: false, Accept-Encoding: gzip) and decompresses a remaining gzip file once. Every stage is bounded by the 50 MB protocol limit: Bun's own decoding inflated a 1 MB Content-Encoding bomb to ~1.4 GB, now ~66 MB. Distinct errors for oversize, corrupt gzip/br/deflate and unsupported codings. #670: on a catch-all server every guessed common location was stored as a sitemap failing with "Unknown sitemap format". A guessed location that answers with an HTML page or a non-XML body is now no sitemap; one named in robots.txt or a sitemap index is still reported, labelled "Not a sitemap: the URL returned an HTML page". Classification is a linear scan of the opening (comments, PIs, doctype), and a body that opens with a sitemap root is never ruled out. Signed-off-by: Nik Cubrilovic <[email protected]>
|
Reviewed
Security and performance: the bounds (wire, post- |
…late bombs and a redirected claim #662 #670 Signed-off-by: Nik Cubrilovic <[email protected]>
|
Triage of the review, fixed in 568b59b:
|
|
Review of #686 (gzip sitemaps, catch-all HTML sitemaps). I read the diff, mainly The design holds up. Reading raw bytes with
No critical or high findings. |
…pin Bun's raw-bytes fetch #662 #670 Signed-off-by: Nik Cubrilovic <[email protected]>
|
Second review, fixed in 48c1b42:
|
|
Review of #686 (gzip sitemap decoding, bounded reads, guessed-HTML handling). I read the diff but did not run the tests. I found nothing blocking. The design is sound: bytes on the wire, each decoded layer and a gzip file inside are all capped at 50 MB, and the error messages are documented and tested.
|
|
Third review: no code change, triage below.
|
|
Reviewed the
Test coverage is thorough: gzip bomb, endless body, corrupt and truncated gzip, br/deflate, redirect headers, catch-all and declared cases, and linear time on 5,000 comments. The CHANGELOG and docs are updated. The PR already flags the |
Closes #662
Closes #670
What changed
All in
packages/crawler/src/sitemaps.ts(the sitemap walk);crawl/sitemap-validandcrawl/sitemap-existsare unchanged and report what the walk stores.#662, gzip sitemaps.
fetchSitemapread every body withresponse.text(), so a.xml.gzchild served asapplication/gzipreached the XML parser as compressed bytes. Now:SITEMAP_MAX_BYTES= 52,428,800).Content-Encodingis undone by the walk itself, within the same limit. The fetch passes Bun'sdecompress: falseand sendsAccept-Encoding: gzip. This was needed for the bound to be real: Bun's own decoding inflates a whole response before a reader can stop it. Measured with a 1 MBContent-Encoding: gzipbomb (1 GiB of spaces), server and client in separate processes:response.text()(old path) peaked +1.39 GB, a 50 MB-capped reader on Bun-decoded fetch peaked +1.79 GB, the new path +66 MB. gzip, x-gzip, deflate (zlib or raw) and br are decoded; anything else, or a stacked coding, isUnsupported Content-Encoding: <coding>. On a runtime other than Bun (where fetch ignoresdecompress: falseand decodes), the header is not re-applied, and a body that opens with markup under a coding that does not decode is read as already decoded.1f 8bis a gzip file and is decompressed once,maxOutputLengthbounded, then parsed.Sitemap exceeds the 50 MB uncompressed size limit,Corrupt gzip body: <zlib reason>(Corrupt br body/Corrupt deflate bodyfor those codings). An uncompressed sitemap over 50 MB is now refused the same way (search engines reject it too).#670, catch-all servers.
decodeSitemapBodyclassifies the body's opening with a linear scan (whitespace, XML declaration, PIs, comments, a non-HTML doctype with its internal subset): an HTML doctype or<html>root, or a body that is not XML at all, or a non-sitemap root served astext/htmlwhen the parse found nothing, isnotASitemap. A body that opens with<urlset>/<sitemapindex>is never ruled out, however broken. After the walk,discoverSitemapsdrops anotASitemapresult unless the site claimed that URL (a robots.txtSitemap:line or a child entry of a parsed index); a dropped one lands infailedwith sourcecommon, which no rule reports. A claimed one stays stored withNot a sitemap: the URL returned an HTML page.Behaviour change worth knowing: on a catch-all site with no sitemap,
crawl/sitemap-existsused to PASS ("8 sitemap(s) found") because the eight HTML pages were stored as sitemaps; it now reportsNo XML sitemap found.Acceptance evidence
BEFORE = squirrel 0.0.108 binary, AFTER = CLI from this branch (
bun run apps/cli/src/cli.ts audit <fixture> --http --refresh -m 2 -f json --rule-include crawl/sitemap-valid --rule-include crawl/sitemap-exists), local fixtures, storedsitemapsrows read from the project DB:child.xml.gz(application/gzip, no CE)Unknown sitemap format, 0 URLs, sitemap-syntax failchild.xmlcontrolUnknown sitemap formatCorrupt gzip body: invalid stored block lengthsParse error: readTagExp ... <binary garbage>Sitemap exceeds the 50 MB uncompressed size limitContent-Encoding: gzipsitemap8 error(s) in 8 sitemap(s); sitemap-exists passedNo XML sitemap found/site-map.xml(HTML)/site-map.xmlNot a sitemap: the URL returned an HTML page/sitemap_index.xmlUnknown sitemap formatTests (new):
packages/crawler/tests/sitemap-gzip.test.ts(gzip child vs plain child against a real origin, CE gzip, CE + gzip file, corrupt and truncated gzip, gzip bomb, endless body cut at the limit, decompressed once, br/deflate/raw deflate, unsupported/stacked/constructorcoding,decompress: false+Accept-Encoding: gzipon every redirect hop) andpackages/crawler/tests/sitemap-guessed-html.test.ts(catch-all, declared-but-HTML in robots.txt and at a common location, real guessed sitemap, guessed path that an index names, XML non-sitemap still reported, classifier cases incl. doctype/comment/PI openings, gzipped HTML, broken sitemap served as text/html, linear time on 5,000 comments).Local gates:
tsgo --noEmitin packages/crawler and packages/audit-engine clean. Tests, explicit files: the two new files plus crawler sitemap-entity-expansion, sitemap-xml-escapes, sitemap-news-namespace, sitemap-gate, preamble-budget, refusals, redirect-header-security, fetch-body-deadline, discovery-probes, sitemaps-column-collision, sitemap-news-column, slow-origin-crawl, full-crawl-harness; audit-engine robots-sitemap-scheme-less, truncated-sitemap-discovery, refused-fetches-e2e; cli crawler/sitemap-cap: all pass.scripts/test-suites.ts --checkok. Docs:[email protected] check --strictpasses (426 pages). Three codex review rounds; findings fixed (regex backtracking replaced by the scanner, gzipped HTML, root vs extraction-error, long comments, doctype/comments in the doctype, the Bun eager-decode memory hole, inherited-property coding lookup, doc wording).Docs:
docs/rules/crawl/sitemap-valid.mdx(the error labels as templates, gzip handling, guessed locations),docs/rules/crawl/sitemap-exists.mdx(a guessed location answering with a page does not count). CHANGELOG under Unreleased / Fixed.Agent skill (
squirrelscan/skills): no change needed; the skill does not describe sitemap errors.Follow-ups (not fixed here)
apps/cli/src/crawl/sitemaps.tsis a dead legacy copy of the walk (only tests import it) that still readsresponse.text().parseSitemapturns a bare-year<lastmod>2024</lastmod>(valid W3C datetime) intoParse error: ... trim is not a functionfor the whole file: fast-xml-parser hands numbers through.readBodyCapped): aContent-Encodingbomb is inflated in full before the cap applies. Tracked in the private monorepo (hosted-crawl impact).Unknown sitemap format, guessed ones now count as no sitemap.