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)
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 oflegal_versionfor a page, with itslanguagesJSON), :145-167 (storedcalls it for each set page), :214-223 (publickeeps 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 overlegal_pagejoined to the currentlegal_versionrows (at most three), returning whatpublicneeds.publicuses it;storedstays for the admin GET and the preview. tsk-tnetc5fgr7pm item 1 (oneframe_inputshelper for the same callers) is the natural place to switch them. - Effort: S. Risk: low; the output of
publicmust 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 indexedpublic_pagerow), :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 fromenabled, the set legal pages and oneEXISTSon indexedpublic_page;get_robotsand_entriesshare the reads oflanding.storedandlegal(with item 1'sserved). - 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, thenpartis checked for digits and range. - What is wrong: any
/sitemap-x.xml,/sitemap-01.xmlor/sitemap-999.xmlcosts a full build before its 404; a valid part still builds all parts to send one. - Proposal: check
partfirst; 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_ADDRESScopyinglegal.ADDRESS: tsk-tnetc5fgr7pm item 4.routes/seo.py:29LANDING_FILES: tsk-dr68ad0te5r9 item 1.routes/legal.py:22-24_require_admin: tsk-hbpjgp03esez item 1.landing.cached_jsonused byGET /legal(routes/legal.py:53): tsk-k25qqhygend8 item 1.
Effort: 3S.