Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow limiting lifespan of low-aal sessions #1942

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hf
Copy link
Contributor

@hf hf commented Feb 11, 2025

Adds a new optional config GOTRUE_SESSIONS_ALLOW_LOW_AAL (duration) which when set will prevent the continued refreshing of a user session if the session has not been upgraded to the highest possible AAL level of the user.

For example if you set it to 1h it means that a user who has MFA factors enrolled must step-up the session to the highest AAL level for their account within 1 hour, otherwise future session refreshes will fail with a Invalid Refresh Token: Session Expired (Low AAL: User Needs MFA Verification)) message.

@hf hf requested a review from a team as a code owner February 11, 2025 10:20
@hf
Copy link
Contributor Author

hf commented Feb 11, 2025

Needs tests but please do an initial review.

Comment on lines +166 to +169
if config.AllowLowAAL != nil && *config.AllowLowAAL != 0 && CompareAAL(ParseAAL(s.AAL), userHighestPossibleAAL) < 0 && now.After(s.CreatedAt.Add(*config.AllowLowAAL)) {
return SessionLowAAL
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nit, but a lot here in one line but maybe:

isLowAAL := config.AllowLowAAL != nil && *config.AllowLowAAL != 0
isLowAAL = isLowAAL && CompareAAL(ParseAAL(s.AAL), userHighestPossibleAAL) < 0
isLowAAL = isLowAAL && now.After(s.CreatedAt.Add(*config.AllowLowAAL)
if isLowAAL {
	return SessionLowAAL
}

@@ -34,6 +34,30 @@ func (aal AuthenticatorAssuranceLevel) String() string {
}
}

// CompareAAL returns 0 if both AAL levels are equal, > 0 if A is a higher level than B or < 0 if A is a lower level than B.
func CompareAAL(a, b AuthenticatorAssuranceLevel) int {
Copy link
Contributor

@cstockton cstockton Feb 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nit, b int comparisons like this can be error prone, I think we saw it in the crypto package once. It may be worth adding some helper methods:

func (aal AuthenticatorAssuranceLevel) Above(level AuthenticatorAssuranceLevel) bool
func (aal AuthenticatorAssuranceLevel) Below(level AuthenticatorAssuranceLevel) bool
func (aal AuthenticatorAssuranceLevel) Equal(level AuthenticatorAssuranceLevel) bool
func (aal AuthenticatorAssuranceLevel) Down OR Lower() (level AuthenticatorAssuranceLevel) # To lower a level (can do this instead of (Above() || Equal()) or adding AboveOrEqual() etc.)
func (aal AuthenticatorAssuranceLevel) Up OR Raise() (level AuthenticatorAssuranceLevel) # To raise a level

@coveralls
Copy link

Pull Request Test Coverage Report for Build 13260664998

Details

  • 22 of 44 (50.0%) changed or added relevant lines in 4 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.08%) to 67.419%

Changes Missing Coverage Covered Lines Changed/Added Lines %
internal/api/token_refresh.go 8 10 80.0%
internal/conf/configuration.go 4 7 57.14%
internal/models/sessions.go 4 21 19.05%
Files with Coverage Reduction New Missed Lines %
internal/conf/configuration.go 1 99.3%
Totals Coverage Status
Change from base Build 13205664056: -0.08%
Covered Lines: 10220
Relevant Lines: 15159

💛 - Coveralls

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.

3 participants