oliver-zehentleitner / maity

clean-up: admin and moderation: one instance-admin guard, maintenance window fields, docs drift

Sign in to report

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 do if caller.principal_id != instance_admin_id(conn): raise forbidden("instance:admin"). Every other admin route calls admin.require_instance_admin (admin.py:46-49; for example routes/reports.py, routes/limits.py, routes/mail_settings.py). routes/maintenance.py:41-42 also wraps it in a one-line _admin helper.
  • Proposal: use require_instance_admin everywhere and drop routes/maintenance._admin. list_users still needs the admin id for its instance_admin field, so it can call the guard and then compare. Optional: a test that every route under /admin/ refuses a non-admin with 403 instance: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), the broadcast payload (maintenance.py:626-633), and routes/maintenance.list_changes (routes/maintenance.py:95-131, the window dict per change row). maintenance.py:226 re-imports escape inside refusal_page, although :19 already 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-13 says a secret is one "an admin may set (today the SMTP password)", but SECRETS also 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:408 sets errors["from"] = "running" when a running window's from changes. docs/api.md:21638 lists the invalid codes as from_after_until, until_past, too_long, too_short only. It describes the rule ("a running window keeps its from") but not the code.
  • Proposal: add running (on from) 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 is routes/members.py:800. The sibling line.needs_consent (line.py:238) has no conn.
  • Proposal: drop the parameter.
  • Effort S. Risk none.

Order

  • tsk-98xq1kme4gd3 (security, open) changes maintenance.check (a past from) and may add an error code next to running. 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.