@@ -12,6 +12,8 @@ function Test-CIPPAccess {
1212 # Check help for role
1313 $APIRole = $Help.Role
1414
15+ $AnyTenantAllowedFunctions = @ (' ListTenants' , ' ListUserSettings' , ' ListUserPhoto' , ' GetCippAlerts' , ' GetVersion' )
16+
1517 if ($Request.Headers .' x-ms-client-principal-idp' -eq ' aad' -and $Request.Headers .' x-ms-client-principal-name' -match ' ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$' ) {
1618 # Direct API Access
1719 $ForwardedFor = $Request.Headers .' x-forwarded-for' -split ' ,' | Select-Object - First 1
@@ -106,13 +108,14 @@ function Test-CIPPAccess {
106108 }
107109
108110 if ($APIAllowed ) {
111+ $TenantFilter = $Request.Query.tenantFilter ?? $Request.Body.tenantFilter ?? $env: TenantID
109112 # Check tenant level access
110113 if (($Role.BlockedTenants | Measure-Object ).Count -eq 0 -and $Role.AllowedTenants -contains ' AllTenants' ) {
111114 $TenantAllowed = $true
112- } elseif ($Request .Query.TenantFilter -eq ' AllTenants ' -or $Request .Body. TenantFilter -eq ' AllTenants' ) {
115+ } elseif ($TenantFilter -eq ' AllTenants' ) {
113116 $TenantAllowed = $false
114117 } else {
115- $Tenant = ($Tenants | Where-Object { $Request .Query. TenantFilter -eq $_.customerId -or $Request .Body.TenantFilter -eq $_ .customerId -or $Request .Query.TenantFilter -eq $_ .defaultDomainName -or $Request .Body. TenantFilter -eq $_.defaultDomainName }).customerId
118+ $Tenant = ($Tenants | Where-Object { $TenantFilter -eq $_.customerId -or $TenantFilter -eq $_.defaultDomainName }).customerId
116119 if ($Role.AllowedTenants -contains ' AllTenants' ) {
117120 $AllowedTenants = $Tenants.customerId
118121 } else {
@@ -132,7 +135,7 @@ function Test-CIPPAccess {
132135 if (! $APIAllowed ) {
133136 throw " Access to this CIPP API endpoint is not allowed, the '$ ( $Role.Role ) ' custom role does not have the required permission: $APIRole "
134137 }
135- if (! $TenantAllowed ) {
138+ if (! $TenantAllowed -and $AnyTenantAllowedFunctions -notcontains $Request .Params.CIPPEndpoint ) {
136139 throw ' Access to this tenant is not allowed'
137140 } else {
138141 return $true
0 commit comments