oliver-zehentleitner / maity

clean-up: G6 public pages: slow paths on public routes (every legal version read per page; robots.txt and sitemap parts build the whole sitemap)

Sign in to report

tsk-mp1tx7q6stm8 Open

From the clean-up audit tsk-hgnbapyw7hnh (uncovered files, G6: CLI leftovers, public-page leftovers, tools and scripts), read at 9dfd4b65.

This may concern the security team: all three paths are unauthenticated GETs. Their cost grows with stored data (legal versions, indexed public pages), and items 2 and 3 can be repeated by anyone. Not verified: whether the route limits cover /robots.txt and /sitemap-*.xml (middleware.py:102 only sets their cache header).

1. Every framed page reads every version of every legal text, to show which pages exist (slow path)

  • Files: hub/src/maity_hub/legal.py:135-142 (_versions: every row of legal_version for a page, with its languages JSON), :145-167 (stored calls it for each set page), :214-223 (public keeps only version and language tags). One text may be 64 KiB per language (:31), and a page may get 20 new versions a day (:33); old versions are never pruned.
  • Callers of legal.public(legal.stored(conn)), all on public pages: routes/pages.py:76 (the landing page /), :185 (explore), :230; link_frame.py:37; public_pages.py:213; routes/joins.py:833 (the join page); routes/landing.py:118, :169; routes/register_page.py:68; maintenance.py:213.
  • What is wrong: each render loads the full text of all versions and drops it. The cost grows with the version history, not with what is shown.
  • Proposal: legal.served(conn), one query over legal_page joined to the current legal_version rows (at most three), returning what public needs. public uses it; stored stays for the admin GET and the preview. tsk-tnetc5fgr7pm item 1 (one frame_inputs helper for the same callers) is the natural place to switch them.
  • Effort: S. Risk: low; the output of public must stay identical (test_landing, test_seo and the legal page tests cover it).

2. /robots.txt builds the whole sitemap to learn whether it has one line (slow path, duplication)

  • Files: hub/src/maity_hub/routes/seo.py:158-167 (get_robots), :83-103 (urls: one XML entry per indexed public_page row), :166 (bool(found)); :142-155 (_entries, the same three reads written once more).
  • What is wrong: with public pages on, every robots.txt request reads and formats every indexed public page (up to the 50,000 per file and beyond) only to decide whether to print the Sitemap: line.
  • Proposal: a has_urls(conn, enabled, pages, public_pages) that answers from enabled, the set legal pages and one EXISTS on indexed public_page; get_robots and _entries share the reads of landing.stored and legal (with item 1's served).
  • Effort: S. Risk: low (test_seo covers the robots text).

3. /sitemap-<part>.xml builds the whole sitemap before it checks part (slow path)

  • Files: hub/src/maity_hub/routes/seo.py:179-190: _entries(request) runs first, then part is checked for digits and range.
  • What is wrong: any /sitemap-x.xml, /sitemap-01.xml or /sitemap-999.xml costs a full build before its 404; a valid part still builds all parts to send one.
  • Proposal: check part first; for a valid part read only its slice (offset (n-1) * MAX_URLS, after the root and legal entries), or keep the chunked list for a short time.
  • Effort: S. Risk: low; the byte limit per file (MAX_BYTES) has to stay checked if the slice is read by offset.

Order

Item 1 together with tsk-tnetc5fgr7pm item 1 if that card is taken first; otherwise item 1 first and that card builds on served.

Covered elsewhere

  • The repeated frame reads at the same callers: tsk-tnetc5fgr7pm item 1. render.LEGAL_ADDRESS copying legal.ADDRESS: tsk-tnetc5fgr7pm item 4. routes/seo.py:29 LANDING_FILES: tsk-dr68ad0te5r9 item 1. routes/legal.py:22-24 _require_admin: tsk-hbpjgp03esez item 1. landing.cached_json used by GET /legal (routes/legal.py:53): tsk-k25qqhygend8 item 1.

Effort: 3S.