oliver-zehentleitner / maity
clean-up: sign-in and accounts: settings read per call, mail readiness, pending good standing, decision mail language
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:confinecallssecond_factor.gateon every authenticated call.auth/second_factor.py:210gatecallsstate(:181), which callspolicy(:184, :89).- That goes to
auth/sign_in_settings.py:191second_factor_policyand:54resolve, then toinstance_settings.stored(instance_settings.py:58-66). storedselects every row ofinstance_settingand 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.%') ininstance_settings.stored, which also helps its other callers. Optionally read onlysign_in.second_factoringate. - 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-61mail_ready(complete, enabled and signing key) andauth/second_factor_reset.py:48-50_mail_ready(identical).registration.py:264-269mail_ready(no key).auth/sign_in_settings.py:68-69and:79-82, inline.mail/outbox.py:139andnotifications/mailer.py:120.routes/notification_settings.py:47-49_mail_readychecks.completeonly.- Proposal: one
mail.settings.ready(conn, hub, *, signing_key: bool)that every place calls. - Open question: should the notification settings ignore
enabled, asroutes/notification_settings.py:47-49does 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-2451says a pending session "is never in good standing, however it was made", and:2455-2457says pending accounts use the rules for sessions not in good standing. - The code:
auth/sessions.py:83-94good_standingignoresaccount_status. A password orregistersession of a pending account therefore showsgood_standing: true(sessions.py:125) and ends sessions under the good-standing rule (sessions.refusal:168, used atroutes/auth.py:333,:341and:416). - Device codes are not affected;
deps._confine_pendingrefuses them. - Open question: which side is right?
- Fix the code: pass the account status into
good_standing.Caller.account_statusis 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.pysends its mails from the catalog sectionregistration_mail, in a language picked bylanguage_of. Theinterface_languageof 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.