-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1311 from kris6673/standards
FIX: Refactor logging, state handling, input validation in CIPP standards and add AntiSpamSafeList standard
- Loading branch information
Showing
118 changed files
with
745 additions
and
593 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardAntiSpamSafeList.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
function Invoke-CIPPStandardAntiSpamSafeList { | ||
<# | ||
.FUNCTIONALITY | ||
Internal | ||
.COMPONENT | ||
(APIName) AntiSpamSafeList | ||
.SYNOPSIS | ||
(Label) Set Anti-Spam Connection Filter Safe List | ||
.DESCRIPTION | ||
(Helptext) Sets the anti-spam connection filter policy option 'safe list' in Defender. | ||
(DocsDescription) Sets [Microsoft's built-in 'safe list'](https://learn.microsoft.com/en-us/powershell/module/exchange/set-hostedconnectionfilterpolicy?view=exchange-ps#-enablesafelist) in the anti-spam connection filter policy, rather than setting a custom safe/block list of IPs. | ||
.NOTES | ||
CAT | ||
Defender Standards | ||
TAG | ||
ADDEDCOMPONENT | ||
{"type":"switch","name":"standards.AntiSpamSafeList.EnableSafeList","label":"Enable Safe List"} | ||
IMPACT | ||
Medium Impact | ||
POWERSHELLEQUIVALENT | ||
Set-HostedConnectionFilterPolicy "Default" -EnableSafeList \$true | ||
RECOMMENDEDBY | ||
UPDATECOMMENTBLOCK | ||
Run the Tools\Update-StandardsComments.ps1 script to update this comment block | ||
.LINK | ||
https://docs.cipp.app/user-documentation/tenant/standards/list-standards/defender-standards#medium-impact | ||
#> | ||
|
||
param($Tenant, $Settings) | ||
##$Rerun -Type Standard -Tenant $Tenant -Settings $Settings 'AntiSpamSafeList' | ||
|
||
try { | ||
$State = [System.Convert]::ToBoolean($Settings.EnableSafeList) | ||
} catch { | ||
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'AntiSpamSafeList: Failed to convert the EnableSafeList parameter to a boolean' -sev Error | ||
Return | ||
} | ||
|
||
try { | ||
$CurrentState = (New-ExoRequest -tenantid $Tenant -cmdlet 'Get-HostedConnectionFilterPolicy' -cmdParams @{Identity = 'Default' }).EnableSafeList | ||
} catch { | ||
$ErrorMessage = Get-CippException -Exception $_ | ||
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Failed to get the Anti-Spam Connection Filter Safe List. Error: $($ErrorMessage.NormalizedError)" -sev Error -LogData $ErrorMessage | ||
Return | ||
} | ||
$WantedState = $State -eq $true ? $true : $false | ||
$StateIsCorrect = if ($CurrentState -eq $WantedState) { $true } else { $false } | ||
|
||
if ($Settings.report -eq $true) { | ||
Add-CIPPBPAField -FieldName 'AntiSpamSafeList' -FieldValue $CurrentState -StoreAs bool -Tenant $Tenant | ||
} | ||
|
||
if ($Settings.remediate -eq $true) { | ||
Write-Host 'Time to remediate' | ||
if ($StateIsCorrect -eq $false) { | ||
try { | ||
$null = New-ExoRequest -tenantid $Tenant -cmdlet 'Set-HostedConnectionFilterPolicy' -cmdParams @{ | ||
Identity = 'Default' | ||
EnableSafeList = $WantedState | ||
} | ||
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Successfully set the Anti-Spam Connection Filter Safe List to $WantedState" -sev Info | ||
} catch { | ||
$ErrorMessage = Get-CippException -Exception $_ | ||
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Failed to set the Anti-Spam Connection Filter Safe List to $WantedState. Error: $($ErrorMessage.NormalizedError)" -sev Error -LogData $ErrorMessage | ||
} | ||
} else { | ||
Write-LogMessage -API 'Standards' -tenant $Tenant -message "The Anti-Spam Connection Filter Safe List is already set correctly to $WantedState" -sev Info | ||
} | ||
} | ||
|
||
if ($Settings.alert -eq $true) { | ||
if ($StateIsCorrect -eq $true) { | ||
Write-LogMessage -API 'Standards' -tenant $Tenant -message "The Anti-Spam Connection Filter Safe List is set correctly to $WantedState" -sev Info | ||
} else { | ||
Write-LogMessage -API 'Standards' -tenant $Tenant -message "The Anti-Spam Connection Filter Safe List is not set correctly to $WantedState" -sev Alert | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardAutoAddProxy.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.