Skip to content

Render the MFA QR for an account whose factor step is pending - #69

Open
dyussekeyev wants to merge 1 commit into
mainfrom
fix/mfa-qr-onboarding-gate
Open

dyussekeyev wants to merge 1 commit into
mainfrom
fix/mfa-qr-onboarding-gate

Conversation

@dyussekeyev

Copy link
Copy Markdown
Contributor

What

GET /api/v1/auth/mfa/qr answered 403 during enrolment, while
POST /api/v1/auth/mfa/setup (200) and POST /api/v1/auth/mfa/enable (200)
worked. The enrolment page asks for the QR immediately after setup, so the
picture never appeared and only manual secret entry remained.

Why

mfa_qr resolves require_self_service, which runs the credential-onboarding
gate in backend/app/api/deps.py. _ONBOARDING_MFA_ALLOWED listed setup and
enable — the two calls that complete the factor step — but not qr, which
merely renders the pending secret setup has just written. The endpoint itself
never answers 403: it returns 409 when nothing is pending or 200 with the SVG.

The practical effect: an administrator forced into enrolment by
REQUIRE_MFA_FOR_ADMINS could not scan a code at all.

Fix

/api/v1/auth/mfa/qr joins _ONBOARDING_MFA_ALLOWED, with the comment saying
why it belongs to the step rather than behind it. No other behaviour changes:
the gate still refuses the rest of the platform, and qr still requires a
pending secret.

Test

tests/test_onboarding.py::TestTheGate::test_the_factor_step_can_show_the_qr_of_the_secret_it_just_issued
— account with must_enrol_mfa, setup 200, then qr 200 and
content-type: image/svg+xml.

Verified red then green: with the route removed from the set the test fails with
assert 403 == 200; with it restored it passes.

Checks

  • pytest tests/test_onboarding.py tests/test_mfa.py tests/test_auth_edges.py — 103 passed
  • ruff check app/api/deps.py tests/test_onboarding.py — All checks passed

The credential-onboarding gate listed `mfa/setup` and `mfa/enable` as part of
the factor step and not `mfa/qr`, so the image the page requests straight after
`setup` answered 200 came back as a 403 from the gate. An administrator the
deployment policy holds on that page could only type the secret by hand.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant