Skip to content

fix(models): guard nil authentication_method in IsAAL2Claim - #2814

Open
suvvvv wants to merge 1 commit into
supabase:masterfrom
suvvvv:fix/amr-nil-authentication-method
Open

suvvvv wants to merge 1 commit into
supabase:masterfrom
suvvvv:fix/amr-nil-authentication-method

Conversation

@suvvvv

@suvvvv suvvvv commented Sep 16, 2026

Copy link
Copy Markdown

What

AMRClaim.IsAAL2Claim dereferences AuthenticationMethod without a nil check:

func (cl *AMRClaim) IsAAL2Claim() bool {
	return *cl.AuthenticationMethod == TOTPSignIn.String() || ...
}

AuthenticationMethod is a *string mapped to the nullable authentication_method column. The sibling accessor GetAuthenticationMethod right below already guards the same field with if a.AuthenticationMethod == nil, so the pointer is known to be nullable.

A mfa_amr_claims row with a NULL authentication_method therefore panics here. IsAAL2Claim is called from Session.CalculateAALAndAMR, which runs on hot paths (token refresh, MFA verification, session AAL computation), so the panic surfaces as a 500.

Fix

Guard the pointer (mirroring GetAuthenticationMethod) and treat a nil method as "not AAL2".

Testing

Extended TestAMRClaimIsAAL2 with a nil case asserting IsAAL2Claim() returns false without panicking. go vet and gofmt are clean; the models test passes.

AMRClaim.IsAAL2Claim dereferenced AuthenticationMethod (a *string mapped to
the nullable authentication_method column) without a nil check, while the
sibling GetAuthenticationMethod guards the same field. A mfa_amr_claims row
with a NULL authentication_method would panic in Session.CalculateAALAndAMR
— a hot path during token refresh, MFA verification and session AAL
computation — turning it into a 500.

Treat a nil method as not AAL2 and add a regression test for the nil case.
@suvvvv
suvvvv requested a review from a team as a code owner September 16, 2026 13:15

This branch has not been deployed

No deployments
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