Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ with it.

## [Unreleased]

### Fixed

- The MFA QR code can be rendered while an account is being walked through
enrolment. `GET /api/v1/auth/mfa/qr` draws the pending secret that
`POST /api/v1/auth/mfa/setup` has just written, but the credential-onboarding
gate listed only `setup` and `enable` as part of the factor step, so the image
the enrolment page requests immediately after `setup` answered 200 was refused
with a 403 from the gate — an administrator held on that page by
`REQUIRE_MFA_FOR_ADMINS` could only type the secret by hand. The route now
belongs to the same step as the two calls it draws from, and a test pins the
QR's reachability for an account with a pending factor.

## [0.2.4] - 2026-11-07

### Added
Expand Down
8 changes: 8 additions & 0 deletions backend/app/api/deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,17 @@
# re-check the password: if a temporary password were still in force, the new
# factor would be bound to the credential its owner is about to replace — and the
# administrator who chose that password would have been present at the enrolment.
#
# The QR belongs to the same step and not to a later one: it renders the pending
# secret `setup` has just written, which is the artefact the enrolment page shows
# beside the manual one. Leaving it out refused the image that the page requests
# immediately after `setup` answered 200 — an administrator forced into enrolment
# by the deployment policy could only ever type the secret by hand, and the
# refusal arrived as a 403 from the gate rather than from the endpoint.
_ONBOARDING_MFA_ALLOWED = frozenset(
{
"/api/v1/auth/mfa/setup",
"/api/v1/auth/mfa/qr",
"/api/v1/auth/mfa/enable",
}
)
Expand Down
26 changes: 26 additions & 0 deletions backend/tests/test_onboarding.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,32 @@ async def test_a_pending_factor_refuses_the_platform_and_opens_its_own_step(
)
assert setup.status_code == 200, setup.text

@pytest.mark.anyio
async def test_the_factor_step_can_show_the_qr_of_the_secret_it_just_issued(
self, client, db_session
):
"""The QR belongs to the enrolment step rather than behind it.

The gate allowed `setup` and `enable` and not `qr`, so the image built from
the pending secret was refused the moment the enrolment page requested it —
an administrator forced into enrolment by the deployment policy could only
type the secret by hand. The endpoint itself never refuses with 403 (it
answers 409 when nothing is pending), which is why the gate is what this
test holds to account.
"""
user = await _user_with_flags(db_session, "qrcode@example.com", mfa=True)
headers = _headers(user)

setup = await client.post(
"/api/v1/auth/mfa/setup", json={"password": PASSWORD}, headers=headers
)
assert setup.status_code == 200, setup.text

qr = await client.get("/api/v1/auth/mfa/qr", headers=headers)
assert qr.status_code == 200, qr.text
assert qr.headers["content-type"].startswith("image/svg+xml")
assert b"<svg" in qr.content[:500]

@pytest.mark.anyio
async def test_the_refusal_is_a_log_line_and_not_an_audit_row(
self, client, db_session, capsys
Expand Down
Loading