Skip to content

Commit f4bc3cb

Browse files
authored
Merge pull request #1311 from kris6673/standards
FIX: Refactor logging, state handling, input validation in CIPP standards and add AntiSpamSafeList standard
2 parents ab5cf83 + ea5e493 commit f4bc3cb

File tree

118 files changed

+745
-593
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+745
-593
lines changed

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardActivityBasedTimeout.ps1

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ function Invoke-CIPPStandardActivityBasedTimeout {
1313
CAT
1414
Global Standards
1515
TAG
16-
"mediumimpact"
1716
"CIS"
1817
"spo_idle_session_timeout"
1918
ADDEDCOMPONENT
20-
{"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"}]}
19+
{"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"}]}
2120
IMPACT
2221
Medium Impact
2322
POWERSHELLEQUIVALENT
@@ -33,28 +32,31 @@ function Invoke-CIPPStandardActivityBasedTimeout {
3332
param($Tenant, $Settings)
3433
#$Rerun -Type Standard -Tenant $Tenant -API 'ActivityBasedTimeout' -Settings $Settings
3534

35+
# Get timeout value using null-coalescing operator
36+
$timeout = $Settings.timeout.value ?? $Settings.timeout
37+
3638
# Input validation
37-
if ([string]::IsNullOrWhiteSpace($Settings.timeout) -or $Settings.timeout -eq 'Select a value' ) {
38-
Write-LogMessage -API 'Standards' -tenant $tenant -message 'ActivityBasedTimeout: Invalid timeout parameter set' -sev Error
39+
if ([string]::IsNullOrWhiteSpace($timeout) -or $timeout -eq 'Select a value' ) {
40+
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'ActivityBasedTimeout: Invalid timeout parameter set' -sev Error
3941
Return
4042
}
4143

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

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

4850
If ($Settings.remediate -eq $true) {
4951
try {
5052
if ($StateIsCorrect -eq $true) {
51-
Write-LogMessage -API 'Standards' -tenant $tenant -message "Activity Based Timeout is already enabled and set to $($Settings.timeout)" -sev Info
53+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Activity Based Timeout is already enabled and set to $timeout" -sev Info
5254
} else {
5355
$PolicyTemplate = @{
5456
displayName = 'DefaultTimeoutPolicy'
5557
isOrganizationDefault = $true
5658
definition = @(
57-
"{`"ActivityBasedTimeoutPolicy`":{`"Version`":1,`"ApplicationPolicies`":[{`"ApplicationId`":`"default`",`"WebSessionIdleTimeout`":`"$($Settings.timeout)`"}]}}"
59+
"{`"ActivityBasedTimeoutPolicy`":{`"Version`":1,`"ApplicationPolicies`":[{`"ApplicationId`":`"default`",`"WebSessionIdleTimeout`":`"$timeout`"}]}}"
5860
)
5961
}
6062
$body = ConvertTo-Json -InputObject $PolicyTemplate -Depth 10 -Compress
@@ -67,26 +69,26 @@ function Invoke-CIPPStandardActivityBasedTimeout {
6769
$RequestType = 'PATCH'
6870
$URI = "https://graph.microsoft.com/beta/policies/activityBasedTimeoutPolicies/$($CurrentState.id)"
6971
}
70-
New-GraphPostRequest -tenantid $tenant -Uri $URI -Type $RequestType -Body $body -ContentType 'application/json'
71-
Write-LogMessage -API 'Standards' -tenant $tenant -message "Enabled Activity Based Timeout with a value of $($Settings.timeout)" -sev Info
72+
New-GraphPostRequest -tenantid $Tenant -Uri $URI -Type $RequestType -Body $body -ContentType 'application/json'
73+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Enabled Activity Based Timeout with a value of $timeout" -sev Info
7274
}
7375
} catch {
74-
Write-LogMessage -API 'Standards' -tenant $tenant -message "Failed to enable Activity Based Timeout a value of $($Settings.timeout)." -sev Error -LogData $_
76+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Failed to enable Activity Based Timeout a value of $timeout." -sev Error -LogData $_
7577
}
7678
}
7779

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

8082
if ($StateIsCorrect -eq $true) {
81-
Write-LogMessage -API 'Standards' -tenant $tenant -message "Activity Based Timeout is enabled and set to $($Settings.timeout)" -sev Info
83+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Activity Based Timeout is enabled and set to $timeout" -sev Info
8284
} else {
83-
Write-LogMessage -API 'Standards' -tenant $tenant -message "Activity Based Timeout is not set to $($Settings.timeout)" -sev Alert
85+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Activity Based Timeout is not set to $timeout" -sev Alert
8486
}
8587
}
8688

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

89-
Add-CIPPBPAField -FieldName 'ActivityBasedTimeout' -FieldValue $StateIsCorrect -StoreAs bool -Tenant $tenant
91+
Add-CIPPBPAField -FieldName 'ActivityBasedTimeout' -FieldValue $StateIsCorrect -StoreAs bool -Tenant $Tenant
9092
}
9193

9294
}

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardAddDKIM.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ function Invoke-CIPPStandardAddDKIM {
1313
CAT
1414
Exchange Standards
1515
TAG
16-
"lowimpact"
1716
"CIS"
1817
ADDEDCOMPONENT
1918
IMPACT
@@ -22,6 +21,7 @@ function Invoke-CIPPStandardAddDKIM {
2221
New-DkimSigningConfig and Set-DkimSigningConfig
2322
RECOMMENDEDBY
2423
"CIS"
24+
"CIPP"
2525
UPDATECOMMENTBLOCK
2626
Run the Tools\Update-StandardsComments.ps1 script to update this comment block
2727
.LINK

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardAnonReportDisable.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ function Invoke-CIPPStandardAnonReportDisable {
1313
CAT
1414
Global Standards
1515
TAG
16-
"lowimpact"
1716
ADDEDCOMPONENT
1817
IMPACT
1918
Low Impact
2019
POWERSHELLEQUIVALENT
2120
Update-MgBetaAdminReportSetting -BodyParameter @{displayConcealedNames = \$true}
2221
RECOMMENDEDBY
22+
"CIPP"
2323
UPDATECOMMENTBLOCK
2424
Run the Tools\Update-StandardsComments.ps1 script to update this comment block
2525
.LINK

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardAntiPhishPolicy.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ function Invoke-CIPPStandardAntiPhishPolicy {
1313
CAT
1414
Defender Standards
1515
TAG
16-
"lowimpact"
1716
"CIS"
1817
"mdo_safeattachments"
1918
"mdo_highconfidencespamaction"
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
function Invoke-CIPPStandardAntiSpamSafeList {
2+
<#
3+
.FUNCTIONALITY
4+
Internal
5+
.COMPONENT
6+
(APIName) AntiSpamSafeList
7+
.SYNOPSIS
8+
(Label) Set Anti-Spam Connection Filter Safe List
9+
.DESCRIPTION
10+
(Helptext) Sets the anti-spam connection filter policy option 'safe list' in Defender.
11+
(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.
12+
.NOTES
13+
CAT
14+
Defender Standards
15+
TAG
16+
ADDEDCOMPONENT
17+
{"type":"switch","name":"standards.AntiSpamSafeList.EnableSafeList","label":"Enable Safe List"}
18+
IMPACT
19+
Medium Impact
20+
POWERSHELLEQUIVALENT
21+
Set-HostedConnectionFilterPolicy "Default" -EnableSafeList \$true
22+
RECOMMENDEDBY
23+
UPDATECOMMENTBLOCK
24+
Run the Tools\Update-StandardsComments.ps1 script to update this comment block
25+
.LINK
26+
https://docs.cipp.app/user-documentation/tenant/standards/list-standards/defender-standards#medium-impact
27+
#>
28+
29+
param($Tenant, $Settings)
30+
##$Rerun -Type Standard -Tenant $Tenant -Settings $Settings 'AntiSpamSafeList'
31+
32+
try {
33+
$State = [System.Convert]::ToBoolean($Settings.EnableSafeList)
34+
} catch {
35+
Write-LogMessage -API 'Standards' -tenant $Tenant -message 'AntiSpamSafeList: Failed to convert the EnableSafeList parameter to a boolean' -sev Error
36+
Return
37+
}
38+
39+
try {
40+
$CurrentState = (New-ExoRequest -tenantid $Tenant -cmdlet 'Get-HostedConnectionFilterPolicy' -cmdParams @{Identity = 'Default' }).EnableSafeList
41+
} catch {
42+
$ErrorMessage = Get-CippException -Exception $_
43+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Failed to get the Anti-Spam Connection Filter Safe List. Error: $($ErrorMessage.NormalizedError)" -sev Error -LogData $ErrorMessage
44+
Return
45+
}
46+
$WantedState = $State -eq $true ? $true : $false
47+
$StateIsCorrect = if ($CurrentState -eq $WantedState) { $true } else { $false }
48+
49+
if ($Settings.report -eq $true) {
50+
Add-CIPPBPAField -FieldName 'AntiSpamSafeList' -FieldValue $CurrentState -StoreAs bool -Tenant $Tenant
51+
}
52+
53+
if ($Settings.remediate -eq $true) {
54+
Write-Host 'Time to remediate'
55+
if ($StateIsCorrect -eq $false) {
56+
try {
57+
$null = New-ExoRequest -tenantid $Tenant -cmdlet 'Set-HostedConnectionFilterPolicy' -cmdParams @{
58+
Identity = 'Default'
59+
EnableSafeList = $WantedState
60+
}
61+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Successfully set the Anti-Spam Connection Filter Safe List to $WantedState" -sev Info
62+
} catch {
63+
$ErrorMessage = Get-CippException -Exception $_
64+
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
65+
}
66+
} else {
67+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "The Anti-Spam Connection Filter Safe List is already set correctly to $WantedState" -sev Info
68+
}
69+
}
70+
71+
if ($Settings.alert -eq $true) {
72+
if ($StateIsCorrect -eq $true) {
73+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "The Anti-Spam Connection Filter Safe List is set correctly to $WantedState" -sev Info
74+
} else {
75+
Write-LogMessage -API 'Standards' -tenant $Tenant -message "The Anti-Spam Connection Filter Safe List is not set correctly to $WantedState" -sev Alert
76+
}
77+
}
78+
}

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardAppDeploy.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ function Invoke-CIPPStandardAppDeploy {
1313
CAT
1414
Entra (AAD) Standards
1515
TAG
16-
"lowimpact"
1716
ADDEDCOMPONENT
1817
{"type":"textField","name":"standards.AppDeploy.appids","label":"Application IDs, comma separated"}
1918
IMPACT

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardAtpPolicyForO365.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ function Invoke-CIPPStandardAtpPolicyForO365 {
1313
CAT
1414
Defender Standards
1515
TAG
16-
"lowimpact"
1716
"CIS"
1817
ADDEDCOMPONENT
1918
{"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}

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardAuditLog.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ function Invoke-CIPPStandardAuditLog {
1313
CAT
1414
Global Standards
1515
TAG
16-
"lowimpact"
1716
"CIS"
1817
"mip_search_auditlog"
1918
ADDEDCOMPONENT
@@ -23,6 +22,7 @@ function Invoke-CIPPStandardAuditLog {
2322
Enable-OrganizationCustomization
2423
RECOMMENDEDBY
2524
"CIS"
25+
"CIPP"
2626
UPDATECOMMENTBLOCK
2727
Run the Tools\Update-StandardsComments.ps1 script to update this comment block
2828
.LINK

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardAuthMethodsSettings.ps1

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,24 @@ function Invoke-CIPPStandardAuthMethodsSettings {
77
.SYNOPSIS
88
(Label) Configure Authentication Methods Policy Settings
99
.DESCRIPTION
10-
(Helptext) Configures the report suspicious activity settings and system credential preferences in the authentication methods policy
11-
(DocsDescription) This standard allows you to configure the reportSuspiciousActivitySettings and systemCredentialPreferences properties within the authentication methods policy.
10+
(Helptext) Configures the report suspicious activity settings and system credential preferences in the authentication methods policy.
11+
(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.
1212
.NOTES
1313
CAT
14-
Entra Standards
14+
Entra (AAD) Standards
1515
TAG
16-
"lowimpact"
1716
ADDEDCOMPONENT
18-
{"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"}]}
19-
{"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"}]}
17+
{"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"}]}
18+
{"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"}]}
2019
IMPACT
2120
Low Impact
2221
POWERSHELLEQUIVALENT
2322
Update-MgBetaPolicyAuthenticationMethodPolicy
23+
RECOMMENDEDBY
24+
UPDATECOMMENTBLOCK
25+
Run the Tools\Update-StandardsComments.ps1 script to update this comment block
2426
.LINK
25-
https://docs.cipp.app/user-documentation/tenant/standards/list-standards/global-standards#low-impact
27+
https://docs.cipp.app/user-documentation/tenant/standards/list-standards/entra-aad-standards#low-impact
2628
#>
2729

2830
param($Tenant, $Settings)

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardAutoAddProxy.ps1

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,32 @@
11
function Invoke-CIPPStandardAutoAddProxy {
2+
<#
3+
.FUNCTIONALITY
4+
Internal
5+
.COMPONENT
6+
(APIName) AutoAddProxy
7+
.SYNOPSIS
8+
(Label) Automatically deploy proxy addresses
9+
.DESCRIPTION
10+
(Helptext) Automatically adds all available domains as a proxy address.
11+
(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.
12+
.NOTES
13+
CAT
14+
Exchange Standards
15+
TAG
16+
"CIS"
17+
ADDEDCOMPONENT
18+
IMPACT
19+
Medium Impact
20+
POWERSHELLEQUIVALENT
21+
Set-Mailbox -EmailAddresses @{add=\$EmailAddress}
22+
RECOMMENDEDBY
23+
DISABLEDFEATURES
24+
25+
UPDATECOMMENTBLOCK
26+
Run the Tools\Update-StandardsComments.ps1 script to update this comment block
27+
.LINK
28+
https://docs.cipp.app/user-documentation/tenant/standards/list-standards/exchange-standards#medium-impact
29+
#>
230
param(
331
$Tenant,
432
$Settings,

0 commit comments

Comments
 (0)