oliver-zehentleitner / maity
clean-up: rendering and stored public pages: frame inputs, render.py and landing helpers
tsk-tnetc5fgr7pm Open
From the clean-up audit tsk-hgnbapyw7hnh, area 11 (Rendering and stored public pages), read at 80647565. Numbers are the audit's. Behaviour stays the same except where an item says otherwise.
1. The frame's inputs are read in 8 places; one helper exists but is private (duplication)
- The same three reads
landing.stored(conn),legal.public(legal.stored(conn)),landing_stats.for_frame(conn, setting)are repeated in: link_frame.py:31-38, public_pages.py:211-214 (_in_frame), maintenance.py:204-215 (frame_of), routes/pages.py:184-186 (explore) and 252-259 (legal_html), routes/joins.py:832-834, routes/landing.py:118 and 166-169, routes/legal.py:107. routes/register_page.py:58-68 has its ownFrameNamedTuple and_frame(conn)for exactly this;maintenance.frame_ofreturns it as a dict. - Proposal: one public
frame_inputs(conn) -> Frame(render.py or landing.py) used by every caller;door_document/framed_document/stored_in_framecan then take aFrameinstead of three keyword arguments. - Effort M. Risk low (pure reads; the maintenance path must keep reading off-request).
2. register_page re-implements link_frame.page (duplication)
- link_frame.py:21-41
page()=render.door_document+DOOR_CSP+Referrer-Policy: no-referrer. routes/register_page.py:76-100_htmlbuilds the same response by hand (plusCache-Control: no-store); register_page.py:55 re-exportsCSP = render.DOOR_CSP. - Proposal: an optional
headers/no_storeargument onlink_frame.page(or alwaysno-store, which fits a page with a token in its path), used by register_page. - Effort S. Risk low (header set must stay identical).
4. Constants defined twice (duplication)
- render.py:253
LEGAL_ADDRESScopies legal.py:27ADDRESS. - public_pages.py:42-45
FRAMED_CSPis byte-identical to routes/pages.py:44-47LEGAL_CSP. public, max-age=60: public_pages.py:46CACHEand 47READ_CACHE(same value, same file), routes/pages.py:48PUBLIC, routes/badges.py:21CACHE, landing.py:811 inline.- Proposal: render uses
legal.ADDRESS(check for an import cycle); oneFRAMED_CSPimported by routes/pages; dropREAD_CACHE; one cache constant. - Effort S. Risk very low.
5. Sign-in links say the language: implemented twice, plus regex rewrites of finished HTML (design)
- render.py:764-773
_carry(href, lang)works on a URL (frame model, also handed to the dashboard by /site/chrome); render.py:293-308_carry_languagedoes the same rule as a regex over the whole body inside_document(render.py:331). They detect an existinglang=with different patterns. render.py:583-602carry_originand_SWITCH(577) are two more regex passes over the finished landing HTML. - Proposal:
_carry_languagecalls_carryon each unescapedhref, so one rule decides. Optional later step: decorate links where they are built (_link,report_link) instead of re-parsing HTML. - Effort S (first step). Risk low-medium (landing tests cover carry_origin and the language carry).
6. landing._control is dead and duplicates landing._control_in (debt)
- landing.py:142-143
_controlhas no caller; landing.py:452-453_control_inhas the same body and is used (379, 521). - Proposal: delete
_control. - Effort S. Risk none.
15. type: ignore because refusal_page is typed -> Any (debt)
- maintenance.py:218-222
refusal_page(...) -> Anyalways returns anHTMLResponse; public_pages.py:146 and routes/pages.py:142 carry# type: ignore[no-any-return]for it. - Proposal: annotate
-> HTMLResponseand drop both ignores. - Effort S. Risk none.
16. render.py docstring is wrong, and the module has outgrown it (docs drift / design)
- render.py:1-10 says the legal pages carry one
<style>element and no script (default-src 'none'; style-src 'unsafe-inline'). Since §16.7.5 they load landing.css/public-pages.css through the frame (render.py:942-946, 1004) under routes/pages.py:44-47LEGAL_CSP. - The 1216-line module also holds Accept-Language negotiation used outside pages (registration_mail.py:38, routes/email_sign_in.py:293, routes/register_page.py:114), the Markdown renderer, the frame model behind GET /site/chrome, door/join/stored-page documents and the public page document.
- Proposal: fix the docstring here (S). Open question for the lead: split
languages,markdownandframeout of render.py (M, no behaviour change) in this card or later. - Effort S (docstring). Risk low.
Order
- After tsk-8mkezms3h9xh (in progress: language row and theme switch on stored pages), which changes
stored_in_frame/public_framein render.py; rebase these items on it. - Item 4's CSP constants: check against tsk-gk1kgz4gwpqe (shell security headers), which touches the same header constants.
Left out
- Audit item 3 (If-None-Match matching copied 9 times,
landing.cached_jsonwithout*/ weak tags) and item 19 (Worker loop copied per module) are cross-area; the coordinator files them on one shared card.