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

fix: update aal requirements to update user #1766

Merged
merged 7 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: refactor into dedicated function
  • Loading branch information
J0 committed Sep 11, 2024
commit 00b1d59b32640fd57b96ee7b1873142ed79f08ae
11 changes: 1 addition & 10 deletions internal/api/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ func (a *API) UserUpdate(w http.ResponseWriter, r *http.Request) error {

user := getUser(ctx)
session := getSession(ctx)
// Change to check for verified
// Allow for metadata update

if err := a.validateUserUpdateParams(ctx, params); err != nil {
return err
Expand All @@ -102,14 +100,7 @@ func (a *API) UserUpdate(w http.ResponseWriter, r *http.Request) error {
}
}

numVerifiedFactors := 0
for _, factor := range user.Factors {
if factor.IsVerified() {
numVerifiedFactors++
}
}

if numVerifiedFactors > 0 && !session.IsAAL2() {
if user.HasMFAEnabled() && !session.IsAAL2() {
if (params.Password != nil && *params.Password != "") || params.Email != "" && user.GetEmail() != params.Email {
J0 marked this conversation as resolved.
Show resolved Hide resolved
return httpError(http.StatusUnauthorized, ErrorCodeInsufficientAAL, "AAL2 session is required to update email or password when MFA is enabled.")
}
Expand Down
10 changes: 10 additions & 0 deletions internal/models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,16 @@
return time.Now().Before(*u.BannedUntil)
}

func (u *User) HasMFAEnabled() bool {
for _, factor := range user.Factors {

Check failure on line 776 in internal/models/user.go

View workflow job for this annotation

GitHub Actions / test (1.22.x)

user.Factors undefined (type auditLogType has no field or method Factors)
if factor.IsVerified() {
numVerifiedFactors++

Check failure on line 778 in internal/models/user.go

View workflow job for this annotation

GitHub Actions / test (1.22.x)

undefined: numVerifiedFactors
}
}

return numVerifiedFactors > 0

Check failure on line 782 in internal/models/user.go

View workflow job for this annotation

GitHub Actions / test (1.22.x)

undefined: numVerifiedFactors
}

func (u *User) UpdateBannedUntil(tx *storage.Connection) error {
return tx.UpdateOnly(u, "banned_until")
}
Expand Down
Loading