🐛 Bug Report: Sitemap loader follows nested sitemaps with no cycle detection or depth limit
📜 Description
SitemapLoader._parse_sitemap calls _extract_urls again for every nested <sitemap><loc> entry. It never records which sitemaps it has already fetched, and there is no maximum depth:
https://github.com/arc53/DocsGPT/blob/436cf51a/docsgpt/parser/remote/sitemap_loader.py#L116-L121
This causes three problems:
-
No cycle detection. If a sitemap index lists itself, or two indexes list each other (this happens with misconfigured CMS plugins), the loader re-fetches the same URL until Python's recursion limit is hit. The
RecursionErroris then swallowed by theexcept Exceptionin_extract_urls, so the ingest "succeeds" with zero documents and only a misleading "No URLs found" message. Hundreds of identical requests are wasted along the way. -
limitdoesn't limit the sitemap stage.limit=20only applies to page fetches inload_data. A sitemap index with thousands of child sitemaps still has every child fetched and parsed before the limit takes effect. -
Malformed XML is uncaught.
ET.fromstring(...)(line 108) raisesParseErroron a broken or truncated sitemap. The error propagates and fails the whole ingest instead of skipping that one sitemap.
👟 Reproduction steps
-
Serve a self-referencing sitemap index. For example, save this as
sitemap.xmland runpython -m http.server 8000(on a host the SSRF guard allows):http:// :8000/sitemap.xml -
In DocsGPT, add a new source of type Sitemap pointing at
http://<host>:8000/sitemap.xml. -
Watch the http.server log and the worker log.
👍 Expected behavior
The loader skips sitemaps it has already visited, stops at a reasonable nesting depth, stops collecting URLs once limit is reached, and logs and skips a sitemap it cannot parse. The ingest finishes, either with the pages it found or with a clear "no URLs found" result.
👎 Actual Behavior with Screenshots
The loader requests the same sitemap URL again and again until Python's recursion limit is hit (489 requests in my run, at the default limit of 1000). The resulting RecursionError is caught by the broad except Exception in _extract_urls and printed as an ordinary fetch failure. load_data then returns [], so the ingest finishes with no documents and no clear error. The only sign is the misleading "No URLs found in the sitemap" message.
With a real 30s timeout per request, a slow host could keep a worker busy for a long time before it gives up.
💻 Operating system
Linux
What browsers are you seeing the problem on?
No response
🤖 What development environment are you experiencing this bug on?
Docker
🔒 Did you set the correct environment variables in the right path? List the environment variable names (not values please!)
No response
📃 Provide any additional context for the Bug.
No response
📖 Relevant log output
Failed to fetch sitemap: http://127.0.0.1:8765/sitemap.xml. Error: maximum recursion depth exceeded
No URLs found in the sitemap: http://127.0.0.1:8765/sitemap.xml
HTTP requests made for the same sitemap URL: 489
👀 Have you spent some time to check if this bug has been raised before?
- [x] I checked and didn't find similar issue
🔗 Are you willing to submit PR?
None
🧑⚖️ Code of Conduct
- [x] I agree to follow this project's Code of Conduct
Hi, @arc53-machine ,
I'd like to work on this. Could you please assign it to me?
Planned fix:
- Track visited sitemap URLs and cap the nesting depth in
_extract_urls/_parse_sitemap - Stop collecting URLs once
limitis reached - Catch
ET.ParseErrorso one malformed sitemap doesn't fail the ingest - Replace the
printcalls withlogging - Add tests for the self-referencing, mutual-reference and malformed-XML cases
I'll also keep it from conflicting with #2793, which edits the same file.
You're assigned, @INEcodes.
- Open a PR or post progress within 14 days; otherwise the issue goes back to other contributors.
- Read
CONTRIBUTING.mdbefore submitting your PR. - Include regression tests and a screenshot or short recording showing the changed behavior.
Automated triage. A maintainer will follow up.