oliver-zehentleitner / maity

clean-up: sign-in and accounts: settings read per call, mail readiness, pending good standing, decision mail language

Sign in to report

tsk-fr6hmpdabmgr Open

From the clean-up audit tsk-hgnbapyw7hnh, area 14 (sign-in and accounts), read at 80647565. Every line number is at 80647565; check each one against current main before changing it. The "audit #N" numbers are those of the findings sent to the lead (seq 125426 and 125444).

This card groups the items that change observable behaviour or need a decision first: performance, mail readiness, the contract, and mail language. The other area 14 cards are tsk-j967n09yz6ps and tsk-f5sdcgr7vzj0.

1. Every dashboard call reads the whole instance_setting table (audit #14)

  • Call chain:
  • deps.py:76: confine calls second_factor.gate on every authenticated call.
  • auth/second_factor.py:210 gate calls state (:181), which calls policy (:184, :89).
  • That goes to auth/sign_in_settings.py:191 second_factor_policy and :54 resolve, then to instance_settings.stored (instance_settings.py:58-66).
  • stored selects every row of instance_setting and filters by the section prefix in Python.
  • What is wrong: each cookie call fetches every stored setting, including the auth-pages JSON (several KiB per language), mail, limits, registration and site values, to learn one policy value.
  • Proposal: filter by prefix in SQL (name LIKE 'sign_in.%') in instance_settings.stored, which also helps its other callers. Optionally read only sign_in.second_factor in gate.
  • Effort: S
  • Risk: low. Measure before and after on the request stats line.

2. "Mail is ready" decided in seven places, one by a different rule (audit #5)

  • Copies:
  • auth/mail_factor.py:58-61 mail_ready (complete, enabled and signing key) and auth/second_factor_reset.py:48-50 _mail_ready (identical).
  • registration.py:264-269 mail_ready (no key).
  • auth/sign_in_settings.py:68-69 and :79-82, inline.
  • mail/outbox.py:139 and notifications/mailer.py:120.
  • routes/notification_settings.py:47-49 _mail_ready checks .complete only.
  • Proposal: one mail.settings.ready(conn, hub, *, signing_key: bool) that every place calls.
  • Open question: should the notification settings ignore enabled, as routes/notification_settings.py:47-49 does today? Decide before aligning it.
  • Effort: S
  • Risk: low. If that copy is aligned, the dashboard may show a different mail state while mail is disabled.

3. A pending account and good standing: code and contract disagree (audit #15)

  • Files:
  • The contract: docs/api.md:2447-2451 says a pending session "is never in good standing, however it was made", and :2455-2457 says pending accounts use the rules for sessions not in good standing.
  • The code: auth/sessions.py:83-94 good_standing ignores account_status. A password or register session of a pending account therefore shows good_standing: true (sessions.py:125) and ends sessions under the good-standing rule (sessions.refusal :168, used at routes/auth.py:333, :341 and :416).
  • Device codes are not affected; deps._confine_pending refuses them.
  • Open question: which side is right?
  • Fix the code: pass the account status into good_standing. Caller.account_status is already read with the session.
  • Or fix §2.7.5 to match the code.
  • Effort: S
  • Risk: low. It affects only the sessions of a pending account.

4. Registration decision mails in the language of the person (audit #17)

  • Files: registration_accounts.py:342-366 (approve) and :406-426 (_ending, rejected and expired) build subject and body as English literals.
  • What is wrong: registration_mail.py sends its mails from the catalog section registration_mail, in a language picked by language_of. The interface_language of the account is stored at completion, but the decision mails ignore it.
  • Proposal: move the three texts to the catalog and pick the language with preferences.text_language, or the language stored at completion.
  • Effort: M (S to M; the texts need translating)
  • Risk: low.

Order

  • Item 3 needs the decision first. The other items are independent.

Left out

  • None of these four is covered by an existing card.