oliver-zehentleitner / maity

clean-up: rendering and stored public pages: frame inputs, render.py and landing helpers

Sign in to report

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 own Frame NamedTuple and _frame(conn) for exactly this; maintenance.frame_of returns 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_frame can then take a Frame instead 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 _html builds the same response by hand (plus Cache-Control: no-store); register_page.py:55 re-exports CSP = render.DOOR_CSP.
  • Proposal: an optional headers / no_store argument on link_frame.page (or always no-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_ADDRESS copies legal.py:27 ADDRESS.
  • public_pages.py:42-45 FRAMED_CSP is byte-identical to routes/pages.py:44-47 LEGAL_CSP.
  • public, max-age=60: public_pages.py:46 CACHE and 47 READ_CACHE (same value, same file), routes/pages.py:48 PUBLIC, routes/badges.py:21 CACHE, landing.py:811 inline.
  • Proposal: render uses legal.ADDRESS (check for an import cycle); one FRAMED_CSP imported by routes/pages; drop READ_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_language does the same rule as a regex over the whole body inside _document (render.py:331). They detect an existing lang= with different patterns. render.py:583-602 carry_origin and _SWITCH (577) are two more regex passes over the finished landing HTML.
  • Proposal: _carry_language calls _carry on each unescaped href, 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 _control has no caller; landing.py:452-453 _control_in has 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(...) -> Any always returns an HTMLResponse; public_pages.py:146 and routes/pages.py:142 carry # type: ignore[no-any-return] for it.
  • Proposal: annotate -> HTMLResponse and 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-47 LEGAL_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, markdown and frame out 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_frame in 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_json without * / weak tags) and item 19 (Worker loop copied per module) are cross-area; the coordinator files them on one shared card.