Skip to content

FIX: Refactor logging, state handling, input validation in CIPP standards and add AntiSpamSafeList standard #1311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ function Invoke-CIPPStandardActivityBasedTimeout {
CAT
Global Standards
TAG
"mediumimpact"
"CIS"
"spo_idle_session_timeout"
ADDEDCOMPONENT
{"type":"select","multiple":false,"label":"Select value","name":"standards.ActivityBasedTimeout.timeout","options":[{"label":"1 Hour","value":"01:00:00"},{"label":"3 Hours","value":"03:00:00"},{"label":"6 Hours","value":"06:00:00"},{"label":"12 Hours","value":"12:00:00"},{"label":"24 Hours","value":"1.00:00:00"}]}
{"type":"autoComplete","multiple":false,"creatable":false,"label":"Select value","name":"standards.ActivityBasedTimeout.timeout","options":[{"label":"1 Hour","value":"01:00:00"},{"label":"3 Hours","value":"03:00:00"},{"label":"6 Hours","value":"06:00:00"},{"label":"12 Hours","value":"12:00:00"},{"label":"24 Hours","value":"1.00:00:00"}]}
IMPACT
Medium Impact
POWERSHELLEQUIVALENT
Expand All @@ -33,28 +32,31 @@ function Invoke-CIPPStandardActivityBasedTimeout {
param($Tenant, $Settings)
#$Rerun -Type Standard -Tenant $Tenant -API 'ActivityBasedTimeout' -Settings $Settings

# Get timeout value using null-coalescing operator
$timeout = $Settings.timeout.value ?? $Settings.timeout

# Input validation
if ([string]::IsNullOrWhiteSpace($Settings.timeout) -or $Settings.timeout -eq 'Select a value' ) {
Write-LogMessage -API 'Standards' -tenant $tenant -message 'ActivityBasedTimeout: Invalid timeout parameter set' -sev Error
if ([string]::IsNullOrWhiteSpace($timeout) -or $timeout -eq 'Select a value' ) {
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'ActivityBasedTimeout: Invalid timeout parameter set' -sev Error
Return
}

# Backwards compatibility for v5.7.0 and older
if ($null -eq $Settings.timeout ) { $Settings.timeout = '01:00:00' }
if ($null -eq $timeout ) { $timeout = '01:00:00' }

$CurrentState = New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/policies/activityBasedTimeoutPolicies' -tenantid $tenant
$StateIsCorrect = if ($CurrentState.definition -like "*$($Settings.timeout)*") { $true } else { $false }
$CurrentState = New-GraphGetRequest -Uri 'https://graph.microsoft.com/beta/policies/activityBasedTimeoutPolicies' -tenantid $Tenant
$StateIsCorrect = if ($CurrentState.definition -like "*$timeout*") { $true } else { $false }

If ($Settings.remediate -eq $true) {
try {
if ($StateIsCorrect -eq $true) {
Write-LogMessage -API 'Standards' -tenant $tenant -message "Activity Based Timeout is already enabled and set to $($Settings.timeout)" -sev Info
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Activity Based Timeout is already enabled and set to $timeout" -sev Info
} else {
$PolicyTemplate = @{
displayName = 'DefaultTimeoutPolicy'
isOrganizationDefault = $true
definition = @(
"{`"ActivityBasedTimeoutPolicy`":{`"Version`":1,`"ApplicationPolicies`":[{`"ApplicationId`":`"default`",`"WebSessionIdleTimeout`":`"$($Settings.timeout)`"}]}}"
"{`"ActivityBasedTimeoutPolicy`":{`"Version`":1,`"ApplicationPolicies`":[{`"ApplicationId`":`"default`",`"WebSessionIdleTimeout`":`"$timeout`"}]}}"
)
}
$body = ConvertTo-Json -InputObject $PolicyTemplate -Depth 10 -Compress
Expand All @@ -67,26 +69,26 @@ function Invoke-CIPPStandardActivityBasedTimeout {
$RequestType = 'PATCH'
$URI = "https://graph.microsoft.com/beta/policies/activityBasedTimeoutPolicies/$($CurrentState.id)"
}
New-GraphPostRequest -tenantid $tenant -Uri $URI -Type $RequestType -Body $body -ContentType 'application/json'
Write-LogMessage -API 'Standards' -tenant $tenant -message "Enabled Activity Based Timeout with a value of $($Settings.timeout)" -sev Info
New-GraphPostRequest -tenantid $Tenant -Uri $URI -Type $RequestType -Body $body -ContentType 'application/json'
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Enabled Activity Based Timeout with a value of $timeout" -sev Info
}
} catch {
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to enable Activity Based Timeout a value of $($Settings.timeout)." -sev Error -LogData $_
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Failed to enable Activity Based Timeout a value of $timeout." -sev Error -LogData $_
}
}

if ($Settings.alert -eq $true) {

if ($StateIsCorrect -eq $true) {
Write-LogMessage -API 'Standards' -tenant $tenant -message "Activity Based Timeout is enabled and set to $($Settings.timeout)" -sev Info
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Activity Based Timeout is enabled and set to $timeout" -sev Info
} else {
Write-LogMessage -API 'Standards' -tenant $tenant -message "Activity Based Timeout is not set to $($Settings.timeout)" -sev Alert
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Activity Based Timeout is not set to $timeout" -sev Alert
}
}

if ($Settings.report -eq $true) {

Add-CIPPBPAField -FieldName 'ActivityBasedTimeout' -FieldValue $StateIsCorrect -StoreAs bool -Tenant $tenant
Add-CIPPBPAField -FieldName 'ActivityBasedTimeout' -FieldValue $StateIsCorrect -StoreAs bool -Tenant $Tenant
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ function Invoke-CIPPStandardAddDKIM {
CAT
Exchange Standards
TAG
"lowimpact"
"CIS"
ADDEDCOMPONENT
IMPACT
Expand All @@ -22,6 +21,7 @@ function Invoke-CIPPStandardAddDKIM {
New-DkimSigningConfig and Set-DkimSigningConfig
RECOMMENDEDBY
"CIS"
"CIPP"
UPDATECOMMENTBLOCK
Run the Tools\Update-StandardsComments.ps1 script to update this comment block
.LINK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ function Invoke-CIPPStandardAnonReportDisable {
CAT
Global Standards
TAG
"lowimpact"
ADDEDCOMPONENT
IMPACT
Low Impact
POWERSHELLEQUIVALENT
Update-MgBetaAdminReportSetting -BodyParameter @{displayConcealedNames = \$true}
RECOMMENDEDBY
"CIPP"
UPDATECOMMENTBLOCK
Run the Tools\Update-StandardsComments.ps1 script to update this comment block
.LINK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ function Invoke-CIPPStandardAntiPhishPolicy {
CAT
Defender Standards
TAG
"lowimpact"
"CIS"
"mdo_safeattachments"
"mdo_highconfidencespamaction"
Expand Down
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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ function Invoke-CIPPStandardAppDeploy {
CAT
Entra (AAD) Standards
TAG
"lowimpact"
ADDEDCOMPONENT
{"type":"textField","name":"standards.AppDeploy.appids","label":"Application IDs, comma separated"}
IMPACT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ function Invoke-CIPPStandardAtpPolicyForO365 {
CAT
Defender Standards
TAG
"lowimpact"
"CIS"
ADDEDCOMPONENT
{"type":"switch","label":"Allow people to click through Protected View even if Safe Documents identified the file as malicious","name":"standards.AtpPolicyForO365.AllowSafeDocsOpen","default":false,"required":false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ function Invoke-CIPPStandardAuditLog {
CAT
Global Standards
TAG
"lowimpact"
"CIS"
"mip_search_auditlog"
ADDEDCOMPONENT
Expand All @@ -23,6 +22,7 @@ function Invoke-CIPPStandardAuditLog {
Enable-OrganizationCustomization
RECOMMENDEDBY
"CIS"
"CIPP"
UPDATECOMMENTBLOCK
Run the Tools\Update-StandardsComments.ps1 script to update this comment block
.LINK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,24 @@ function Invoke-CIPPStandardAuthMethodsSettings {
.SYNOPSIS
(Label) Configure Authentication Methods Policy Settings
.DESCRIPTION
(Helptext) Configures the report suspicious activity settings and system credential preferences in the authentication methods policy
(DocsDescription) This standard allows you to configure the reportSuspiciousActivitySettings and systemCredentialPreferences properties within the authentication methods policy.
(Helptext) Configures the report suspicious activity settings and system credential preferences in the authentication methods policy.
(DocsDescription) Controls the authentication methods policy settings for reporting suspicious activity and system credential preferences. These settings help enhance the security of authentication in your organization.
.NOTES
CAT
Entra Standards
Entra (AAD) Standards
TAG
"lowimpact"
ADDEDCOMPONENT
{"type":"autoComplete","multiple":false,"name":"standards.AuthMethodsSettings.ReportSuspiciousActivity","label":"Report Suspicious Activity Settings","options":[{"label":"Default","value":"default"},{"label":"Enabled","value":"enabled"},{"label":"Disabled","value":"disabled"}]}
{"type":"autoComplete","multiple":false,"name":"standards.AuthMethodsSettings.SystemCredential","label":"System Credential Preferences","options":[{"label":"Default","value":"default"},{"label":"Enabled","value":"enabled"},{"label":"Disabled","value":"disabled"}]}
{"type":"autoComplete","multiple":false,"creatable":false,"required":false,"name":"standards.AuthMethodsSettings.ReportSuspiciousActivity","label":"Report Suspicious Activity Settings","options":[{"label":"Microsoft managed","value":"default"},{"label":"Enabled","value":"enabled"},{"label":"Disabled","value":"disabled"}]}
{"type":"autoComplete","multiple":false,"creatable":false,"required":false,"name":"standards.AuthMethodsSettings.SystemCredential","label":"System Credential Preferences","options":[{"label":"Microsoft managed","value":"default"},{"label":"Enabled","value":"enabled"},{"label":"Disabled","value":"disabled"}]}
IMPACT
Low Impact
POWERSHELLEQUIVALENT
Update-MgBetaPolicyAuthenticationMethodPolicy
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/global-standards#low-impact
https://docs.cipp.app/user-documentation/tenant/standards/list-standards/entra-aad-standards#low-impact
#>

param($Tenant, $Settings)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@
function Invoke-CIPPStandardAutoAddProxy {
<#
.FUNCTIONALITY
Internal
.COMPONENT
(APIName) AutoAddProxy
.SYNOPSIS
(Label) Automatically deploy proxy addresses
.DESCRIPTION
(Helptext) Automatically adds all available domains as a proxy address.
(DocsDescription) Automatically finds all available domain names in the tenant, and tries to add proxy addresses based on the user's UPN to each of these.
.NOTES
CAT
Exchange Standards
TAG
"CIS"
ADDEDCOMPONENT
IMPACT
Medium Impact
POWERSHELLEQUIVALENT
Set-Mailbox -EmailAddresses @{add=\$EmailAddress}
RECOMMENDEDBY
DISABLEDFEATURES
UPDATECOMMENTBLOCK
Run the Tools\Update-StandardsComments.ps1 script to update this comment block
.LINK
https://docs.cipp.app/user-documentation/tenant/standards/list-standards/exchange-standards#medium-impact
#>
param(
$Tenant,
$Settings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ function Invoke-CIPPStandardAutoExpandArchive {
CAT
Exchange Standards
TAG
"lowimpact"
ADDEDCOMPONENT
IMPACT
Low Impact
Expand Down
Loading