oliver-zehentleitner / maity

clean-up: limits and abuse: one asset-directory constant, serving.md and second-factor docs drift

Sign in to report

tsk-dr68ad0te5r9 Open

From the clean-up audit tsk-hgnbapyw7hnh, Area 2 (Limits and abuse), read at 80647565. Line numbers are at 80647565; check each one against current main before changing it. Finding numbers are the audit's (A2-n).

One duplicated set of constants around compression and caching, plus two small docs fixes. All S, one PR.

1. The dashboard's asset directories and the landing prefix are written by hand three times each (A2-9, duplication)

  • Asset directories: shell.py:38 ASSET_DIRS = {"brand", "css", "js", "vendor"}, compression.py:35-37 OWN_ENCODING (its comment points at shell.ASSET_DIRS but copies the list), and middleware.py:109 DASHBOARD_FILES = re.compile(r"/assets/(?:brand|css|js|vendor)/.+").
  • Landing prefix: landing_files.py:29 PREFIX = "/assets/landing/", middleware.py:105 LANDING_FILES, routes/seo.py:29 LANDING_FILES.
  • A fifth asset directory added to shell.py would be gzipped twice (the middleware would wrap AssetFiles' own gzip form) and would get the wrong cache header.
  • Proposal: derive OWN_ENCODING and DASHBOARD_FILES from one constant, and the landing patterns from landing_files.PREFIX. shell.py already imports compression, so put the constant in a small module both can import (or in compression.py) to avoid a cycle.
  • Effort: S. Risk: low.

2. hub/context/serving.md misses the /bootstrap exclusion from gzip (A2-10, docs drift)

  • compression.py:29-34 leaves /api/v1/bootstrap uncompressed ("its session part holds the CSRF token"), and docs/api.md:147 says the same. hub/context/serving.md:559-562 lists what is never compressed without it, and its Reason (serving.md:570-572) says "Every place the hub answers a secret ... is a write or under /api/v1/auth/", which /bootstrap contradicts.
  • Proposal: add /api/v1/bootstrap to the list and the reason, as a dated addendum to the 5cfd29b6 entry.
  • Effort: S. Risk: none.

3. "The session's five minutes" for wrong second-factor codes, while the window is 15 (A2-11, docs drift)

  • auth/second_factor.py:37 SESSION_LIFE = mail_factor.LIFETIME, which is 15 minutes (mail_factor.py:30); the comment at 35-36 says so too. The comments at second_factor.py:49-50 ("pruned once a session's five minutes are over") and :496-497 ("the session's five minutes"), and hub/context/replicas.md:312-313 ("of the session's five minutes"), still say five.
  • Proposal: say "a second-factor session's life (SESSION_LIFE, 15 minutes for mail)" in all three places.
  • Effort: S. Risk: none.

Order

  • Item 1: middleware.py is also edited by tsk-j967n09yz6ps (items 7 and 9) and shell.py headers by tsk-gk1kgz4gwpqe; rebase rather than conflict.
  • Item 3: auth/second_factor.py is being changed by tsk-8mgb85ne0nrq; if the A2-3 counter work (sibling card) lands first, these comments move with it.

Covered elsewhere

  • None. Searched: ASSET_DIRS, LANDING_FILES, serving.md, bootstrap, SESSION_LIFE.

Effort sum: 3S.