oliver-zehentleitner / maity
clean-up: admin and moderation: one instance-admin guard, maintenance window fields, docs drift
tsk-hbpjgp03esez Open
From the clean-up audit tsk-hgnbapyw7hnh, Area 8 (Admin and moderation), read at 80647565. Every line number is at that SHA; check it against current main first. Numbers are the audit's finding numbers. Paths are under hub/src/maity_hub/ unless they start with hub/ or docs/.
This card holds the admin, maintenance and instance-settings clean-ups. All are S. The moderation.py items of this area are on tsk-cnyz6bb2vhkx.
Item 1 may also concern the security team: it is an access check. Today all six copies do the same test as the shared guard, so nothing is open, but a hand-written admin check is easy to get wrong in the next route. No security card covers it (searched: require_instance_admin, instance_admin_id, instance:admin).
1. Duplication: the instance-admin guard is written inline 6 times
- Files:
routes/admin.py:36-38,:134-135,:152-153;routes/landing.py:24-25;routes/legal.py:23-24;routes/registration.py:302-303. All of them doif caller.principal_id != instance_admin_id(conn): raise forbidden("instance:admin"). Every other admin route callsadmin.require_instance_admin(admin.py:46-49; for exampleroutes/reports.py,routes/limits.py,routes/mail_settings.py).routes/maintenance.py:41-42also wraps it in a one-line_adminhelper. - Proposal: use
require_instance_admineverywhere and droproutes/maintenance._admin.list_usersstill needs the admin id for itsinstance_adminfield, so it can call the guard and then compare. Optional: a test that every route under/admin/refuses a non-admin with 403instance:admin. - Effort S. Risk low: same check, same error.
8. Duplication: the maintenance window's {from, until, text} is built in three places; plus a doubled import
- Files:
maintenance.view(maintenance.py:69-87), thebroadcastpayload (maintenance.py:626-633), androutes/maintenance.list_changes(routes/maintenance.py:95-131, thewindowdict per change row).maintenance.py:226re-importsescapeinsiderefusal_page, although:19already imports it at module level. - Proposal: one
_window_fields(starts_at, ends_at, text)used by all three, and drop the inner import. - Effort S. Risk none: same output.
9 (docstring part). The instance_settings docstring is out of date
- Files:
instance_settings.py:11-13says a secret is one "an admin may set (today the SMTP password)", butSECRETSalso holds the address-lock pepper and the position key, which the hub generates itself. - Proposal: fix the docstring. (The duplicated key derivation in the same finding is covered elsewhere, see below.)
- Effort S. Risk none.
12. Docs drift: the PUT /admin/maintenance error code running is undocumented
- Files:
maintenance.py:408setserrors["from"] = "running"when a running window'sfromchanges.docs/api.md:21638lists theinvalidcodes asfrom_after_until,until_past,too_long,too_shortonly. It describes the rule ("a running window keeps itsfrom") but not the code. - Proposal: add
running(onfrom) to that list. - Effort S. Risk none.
13. Debt: admin_agents.needs_consent takes conn only to delete it
- Files:
admin_agents.py:141-151(del conn); the only caller isroutes/members.py:800. The siblingline.needs_consent(line.py:238) has noconn. - Proposal: drop the parameter.
- Effort S. Risk none.
Order
- tsk-98xq1kme4gd3 (security, open) changes
maintenance.check(a pastfrom) and may add an error code next torunning. Do item 12 after it, so the docs list both codes at once. Item 8 touches the same module; rebase rather than conflict.
Left out (hub-wide patterns, filed on shared cards by the lead)
- Audit 6, 7 and 10 are listed on tsk-cnyz6bb2vhkx (agent-to-owner lookup, private
_handle, Worker loop).
Covered elsewhere
- Audit 9, the duplicated "derive from the instance key, else a stored random secret" (
mail/address.py:67-93,notifications/positions.py:59-82,instance_settings.add_sealed): tsk-8vdegd61y70v item 4. That card also asks whether the fallback key is wiped when an instance key arrives.
Effort: 5S.