Fix various bad tenant isolation

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
Bryan Frimin
2025-10-30 15:39:38 +01:00
parent a42670d5bd
commit 29917578fc
30 changed files with 1259 additions and 1369 deletions

View File

@@ -103,15 +103,30 @@ func TryAuth(
allowedTenantIDs := make([]gid.TenantID, 0, len(organizations))
authErrors := make(map[gid.TenantID]error)
// Extract organization IDs for batch check
orgIDs := make([]gid.GID, len(organizations))
for i, org := range organizations {
orgIDs[i] = org.ID
}
// Batch check access to all organizations in a single query
accessResults, err := authSvc.CheckOrganizationAccess(ctx, user, orgIDs, session)
if err != nil {
if errorHandler.OnTenantError != nil {
errorHandler.OnTenantError(err)
}
return nil
}
// Process results
for _, org := range organizations {
// Check if user has the required authentication for this organization
err := authSvc.CheckOrganizationAccess(ctx, user, org.ID, session)
if err == nil {
result := accessResults[org.ID]
if result.Allowed {
// User has proper authentication for this org
allowedTenantIDs = append(allowedTenantIDs, org.ID.TenantID())
} else {
// Store the authentication error for later use
authErrors[org.ID.TenantID()] = err
authErrors[org.ID.TenantID()] = result.ToError(authSvc.BaseURL())
}
}