oliver-zehentleitner / maity

hub: second_factor.state, session_view and view read the factor row once (up to three reads per gate, and the gate runs once per bootstrap part)

Sign in to report

tsk-b66k55admewq Open

Audit round 3b (tsk-hgnbapyw7hnh), read at 80fef076. Kind: slow path on a hot route.

What is wrong

  • deps.py:80 runs gate on every authenticated call; gate calls state (hub/src/maity_hub/auth/second_factor.py:186-212).
  • At the second step, via() runs at :194 and again inside step_life() (:196 -> :168), each with its own factor_of read.
  • For an enrolment session, asks() (:202, factor_of at :156) and must_enrol() (:207, factor_of at :128) both read the row.
  • For a full session, must_enrol reads factor_of, plus verified_row/ever_had_address under email, or is_instance_admin/owns_a_project under required_admins.
  • GET /bootstrap calls gate for the request (routes/bootstrap.py:168) and again per part (:91, up to 5 parts): up to 6 times per bootstrap.
  • session_view (second_factor.py:254-276) calls state, then step_life and via again (up to 4 factor_of reads); view() (:955-974) calls policy() three times and asks/must_enrol, which read the row again.

Proposal

  • Read the factor once in state, session_view and view and pass it into via, asks, must_enrol, step_life (an optional factor= argument).
  • tsk-fr6hmpdabmgr item 1 covers only the instance_setting read behind policy(); this can also serve tsk-nndcfpwxbd3p (bootstrap statements) as a concrete item.

Effort / risk: S. Low; the two-factor and mail-factor tests pin the states.