Skip to content

Commit a99fedc

Browse files
fix(pwpush): stop stale settings from silently breaking every push
A saved AccountId with bearer auth off, or an out-of-range expiry value, made New-Push throw at parameter binding. New-PwPushLink swallowed the exception into $false, so the extension test reported "PWPush is not enabled" while password flows fell back to plain text passwords in notifications. - Only pass AccountId to New-Push when bearer auth is on and the saved value is non-empty; a placeholder or stale selection no longer kills the push. - Drop ExpireAfterDays/ExpireAfterViews values outside PassPushPosh's accepted ranges (1-90 / 1-100) with a logged warning instead of letting validation throw. - ExecExtensionTest now checks Enabled explicitly and surfaces the real exception via a new -ThrowOnError switch instead of collapsing every failure into "PWPush is not enabled". - Make placeholder dropdown rows with an empty id unselectable in integration settings so the poison value cannot be saved again. Synced from CyberDrain/CIPP@07e0415
1 parent 7357fc8 commit a99fedc

2 files changed

Lines changed: 43 additions & 6 deletions

File tree

Modules/CIPPHTTP/Public/Entrypoints/HTTP Functions/CIPP/Extensions/Invoke-ExecExtensionTest.ps1

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,23 @@ Function Invoke-ExecExtensionTest {
5050
}
5151
}
5252
'PWPush' {
53+
if ($Configuration.PWPush.Enabled -ne $true) {
54+
$Results = [pscustomobject]@{'Results' = 'PWPush is not enabled. Enable the integration and save the configuration, then test again.' }
55+
break
56+
}
5357
$Payload = 'This is a test from CIPP'
54-
$PasswordLink = New-PwPushLink -Payload $Payload
58+
# ThrowOnError: the silent $false fallback exists for the password flows; the
59+
# test's whole job is to show why a push fails, so let the real exception through.
60+
try {
61+
$PasswordLink = New-PwPushLink -Payload $Payload -ThrowOnError
62+
} catch {
63+
$Results = [pscustomobject]@{'Results' = "PWPush is enabled but creating a test push failed: $($_.Exception.Message)" }
64+
break
65+
}
5566
if ($PasswordLink) {
5667
$Results = [pscustomobject]@{Results = @(@{'resultText' = 'Successfully generated PWPush, hit the Copy to Clipboard button to retrieve the test.'; 'copyField' = $PasswordLink; 'state' = 'success' }) }
5768
} else {
58-
$Results = [pscustomobject]@{'Results' = 'PWPush is not enabled' }
69+
$Results = [pscustomobject]@{'Results' = 'PWPush did not return a link. Check the CIPP logbook (API: PwPush) for details.' }
5970
}
6071
}
6172
'Hudu' {

Modules/CippExtensions/Public/PwPush/New-PwPushLink.ps1

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
function New-PwPushLink {
22
[CmdletBinding(SupportsShouldProcess)]
33
Param(
4-
$Payload
4+
$Payload,
5+
# Rethrow creation failures instead of collapsing them into $false. The password flows
6+
# rely on the silent fallback; the extension test uses this to show the real error.
7+
[switch]$ThrowOnError
58
)
69

710
try {
@@ -37,10 +40,31 @@ function New-PwPushLink {
3740
$PushParams = @{
3841
Payload = $Payload
3942
}
40-
if ($Configuration.ExpireAfterDays) { $PushParams.ExpireAfterDays = $Configuration.ExpireAfterDays }
41-
if ($Configuration.ExpireAfterViews) { $PushParams.ExpireAfterViews = $Configuration.ExpireAfterViews }
43+
# New-Push validates ExpireAfterDays as 1-90 and ExpireAfterViews as 1-100 at bind
44+
# time; an out-of-range saved value would throw here and downgrade every caller to
45+
# plain text passwords, so drop the setting and warn instead.
46+
$ExpireAfterDays = $Configuration.ExpireAfterDays -as [int]
47+
if ($ExpireAfterDays) {
48+
if ($ExpireAfterDays -ge 1 -and $ExpireAfterDays -le 90) {
49+
$PushParams.ExpireAfterDays = $ExpireAfterDays
50+
} else {
51+
Write-LogMessage -API PwPush -Message "Ignoring ExpireAfterDays '$($Configuration.ExpireAfterDays)': PWPush accepts 1 to 90 days" -Sev 'Warning'
52+
}
53+
}
54+
$ExpireAfterViews = $Configuration.ExpireAfterViews -as [int]
55+
if ($ExpireAfterViews) {
56+
if ($ExpireAfterViews -ge 1 -and $ExpireAfterViews -le 100) {
57+
$PushParams.ExpireAfterViews = $ExpireAfterViews
58+
} else {
59+
Write-LogMessage -API PwPush -Message "Ignoring ExpireAfterViews '$($Configuration.ExpireAfterViews)': PWPush accepts 1 to 100 views" -Sev 'Warning'
60+
}
61+
}
4262
if ($Configuration.DeletableByViewer) { $PushParams.DeletableByViewer = $Configuration.DeletableByViewer }
43-
if ($Configuration.AccountId) { $PushParams.AccountId = $Configuration.AccountId.value }
63+
# New-Push rejects an account id at bind time when no Authorization header is set, so
64+
# a stale or placeholder selection saved with bearer auth off must not be passed on.
65+
if ($Configuration.UseBearerAuth -eq $true -and -not [string]::IsNullOrEmpty($Configuration.AccountId.value)) {
66+
$PushParams.AccountId = $Configuration.AccountId.value
67+
}
4468
if (![string]::IsNullOrEmpty($Configuration.DefaultPassphrase)) { $PushParams.Passphrase = $Configuration.DefaultPassphrase }
4569

4670
if ($PSCmdlet.ShouldProcess('Create a new PwPush link')) {
@@ -56,11 +80,13 @@ function New-PwPushLink {
5680
'Exception' = Get-CippException -Exception $_
5781
}
5882
Write-LogMessage -API PwPush -Message "Failed to create a new PwPush link: $($_.Exception.Message)" -Sev 'Error' -LogData $LogData
83+
if ($ThrowOnError) { throw }
5984
Write-LogMessage -API PwPush -Message "Continuing without PwPush link due to error" -sev 'Warning'
6085
return $false
6186
}
6287
} catch {
6388
Write-LogMessage -API PwPush -Message "Unexpected error in PwPush configuration handling: $($_.Exception.Message)" -Sev 'Error'
89+
if ($ThrowOnError) { throw }
6490
return $false
6591
}
6692
}

0 commit comments

Comments
 (0)