Skip to content

Commit 9b65093

Browse files
fix(auth): heal excludedPaths drift in EasyAuth config
Refactor required excluded paths into a shared variable and apply them during read-modify-write updates, ensuring older configurations that may be missing entries are healed on each run. Synced from CyberDrain/CIPP@0d475cb
1 parent dfa829d commit 9b65093

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

‎Modules/CIPPCore/Public/Authentication/Set-CIPPSSOEasyAuth.ps1‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ function Set-CIPPSSOEasyAuth {
6161
"https://login.microsoftonline.com/$TenantId/v2.0"
6262
}
6363

64+
# Easy Auth path matching is case-sensitive — cover every casing CIPP has ever emitted
65+
$RequiredExcludedPaths = @(
66+
'/api/Public*'
67+
'/API/Public*'
68+
'/api/public*'
69+
'/api/setup/health'
70+
)
71+
6472
# Read current app settings and merge AUTH_SECRET
6573
$CurrentSettings = Invoke-RestMethod -Uri "$BaseUri/config/appsettings/list?api-version=2024-11-01" -Method Post -Headers @{ Authorization = "Bearer $ArmToken" }
6674
$MergedSettings = @{}
@@ -124,6 +132,15 @@ function Set-CIPPSSOEasyAuth {
124132
$AAD.validation.defaultAuthorizationPolicy.allowedPrincipals = @{}
125133
}
126134

135+
# Ensure all required excludedPaths are present (heals drift from older configs)
136+
if (-not $Current.ContainsKey('globalValidation') -or $null -eq $Current.globalValidation) { $Current.globalValidation = @{} }
137+
$ExistingPaths = [System.Collections.Generic.HashSet[string]]::new([StringComparer]::Ordinal)
138+
if ($Current.globalValidation.excludedPaths) {
139+
foreach ($p in $Current.globalValidation.excludedPaths) { [void]$ExistingPaths.Add($p) }
140+
}
141+
foreach ($p in $RequiredExcludedPaths) { [void]$ExistingPaths.Add($p) }
142+
$Current.globalValidation.excludedPaths = @($ExistingPaths)
143+
127144
$AuthConfig = $ArmPayload | ConvertTo-Json -Depth 20
128145
Write-Information "[SSO-EasyAuth] Read-modify-write: patching issuer to $IssuerUrl (preserving $(($ExistingAudiences).Count) audiences, $(($ExistingApps).Count) allowed apps)"
129146
} else {
@@ -134,12 +151,7 @@ function Set-CIPPSSOEasyAuth {
134151
globalValidation = @{
135152
unauthenticatedClientAction = 'RedirectToLoginPage'
136153
redirectToProvider = 'azureactivedirectory'
137-
excludedPaths = @(
138-
'/api/Public*'
139-
'/API/Public*'
140-
'/api/public*'
141-
'/api/setup/health'
142-
)
154+
excludedPaths = $RequiredExcludedPaths
143155
}
144156
identityProviders = @{
145157
azureActiveDirectory = @{

0 commit comments

Comments
 (0)