Skip to content
Open
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
3 changes: 3 additions & 0 deletions internal/models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,9 @@ func findUser(tx *storage.Connection, query string, args ...interface{}) (*User,
func FindUserByEmailAndAudience(tx *storage.Connection, email, aud string) (*User, error) {
return findUser(tx, "instance_id = ? and LOWER(email) = ? and aud = ? and is_sso_user = false", uuid.Nil, strings.ToLower(email), aud)
}
func FindUserByEmail(tx *storage.Connection, email string) (*User, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

🟡 Severity: MEDIUM

Missing Audience (aud) Check: This function searches users without validating the aud (audience) field, unlike the existing FindUserByEmailAndAudience. In multi-tenant systems, the aud field isolates users between different tenants/applications. Omitting this check allows one tenant to potentially access users from another tenant's database. The function also omits the is_sso_user = false filter, which could return SSO users that should be handled differently.
Helpful? Add 👍 / 👎

💡 Fix Suggestion

Suggestion: Add the 'aud' (audience) parameter and include the 'is_sso_user = false' filter to prevent cross-tenant data access and exclude SSO users. The function signature should be: func FindUserByEmail(tx *storage.Connection, email, aud string) (*User, error) and the query should include: aud = ? and is_sso_user = false. This ensures tenant isolation in multi-tenant environments. If this function is strictly intended for admin-only cross-tenant operations, document this clearly and ensure it's only called from properly authorized admin endpoints.

⚠️ Experimental Feature: This code suggestion is automatically generated. Please review carefully.

Suggested change
func FindUserByEmail(tx *storage.Connection, email string) (*User, error) {
func FindUserByEmail(tx *storage.Connection, email, aud string) (*User, error) {
return findUser(tx, "instance_id = ? and LOWER(email) = ? and aud = ? and is_sso_user = false", uuid.Nil, strings.ToLower(email), aud)
}

return findUser(tx, "instance_id = ? and LOWER(email) = ?", uuid.Nil, strings.ToLower(email))
}

// FindUserByPhoneAndAudience finds a user with the matching email and audience.
func FindUserByPhoneAndAudience(tx *storage.Connection, phone, aud string) (*User, error) {
Expand Down