DocsGPT icon indicating copy to clipboard operation
DocsGPT copied to clipboard

🐛 Bug Report: Sitemap loader follows nested sitemaps with no cycle detection or depth limit

Open INEcodes opened this issue 1 month ago • 2 comments

📜 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:

  1. 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 RecursionError is then swallowed by the except Exception in _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.

  2. limit doesn't limit the sitemap stage. limit=20 only applies to page fetches in load_data. A sitemap index with thousands of child sitemaps still has every child fetched and parsed before the limit takes effect.

  3. Malformed XML is uncaught. ET.fromstring(...) (line 108) raises ParseError on a broken or truncated sitemap. The error propagates and fails the whole ingest instead of skipping that one sitemap.

👟 Reproduction steps

  1. Serve a self-referencing sitemap index. For example, save this as sitemap.xml and run python -m http.server 8000 (on a host the SSRF guard allows):

    http://:8000/sitemap.xml
  2. In DocsGPT, add a new source of type Sitemap pointing at http://<host>:8000/sitemap.xml.

  3. 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.

Image

💻 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

INEcodes avatar Oct 09 '26 02:10 INEcodes

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 limit is reached
  • Catch ET.ParseError so one malformed sitemap doesn't fail the ingest
  • Replace the print calls with logging
  • 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.

INEcodes avatar Oct 09 '26 02:10 INEcodes

You're assigned, @INEcodes.

  • Open a PR or post progress within 14 days; otherwise the issue goes back to other contributors.
  • Read CONTRIBUTING.md before submitting your PR.
  • Include regression tests and a screenshot or short recording showing the changed behavior.

Automated triage. A maintainer will follow up.

arc53-machine avatar Oct 09 '26 02:10 arc53-machine