Skip to content

Commit 5c013e0

Browse files
committed
fix ip address regex
1 parent 1d1166a commit 5c013e0

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Modules/CIPPCore/Public/Webhooks/Test-CIPPAuditLogRules.ps1

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ function Test-CIPPAuditLogRules {
9898
$HasLocationData = $false
9999
if (![string]::IsNullOrEmpty($Data.clientip) -and $Data.clientip -notmatch '[X]+') {
100100
# Ignore IP addresses that have been redacted
101-
if ($Data.clientip -match '^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+$') {
102-
$Data.clientip = $Data.clientip -replace ':\d+$', '' # Remove the port number if present
103-
}
101+
102+
$IPRegex = '^(?<IP>(?:\d{1,3}(?:\.\d{1,3}){3}|\[[0-9a-fA-F:]+\]|[0-9a-fA-F:]+))(?::\d+)?$'
103+
$Data.clientip = $Data.clientip -replace $IPRegex, '$1' -replace '[\[\]]', ''
104+
104105
# Check if IP is on trusted IP list
105106
$TrustedIP = Get-CIPPAzDataTableEntity @TrustedIPTable -Filter "((PartitionKey eq '$TenantFilter') or (PartitionKey eq 'AllTenants')) and RowKey eq '$($Data.clientip)' and state eq 'Trusted'"
106107
if ($TrustedIP) {

0 commit comments

Comments
 (0)