Skip to content

Commit d141595

Browse files
committed
fix(autopilot): validate profile names early
Add a shared Autopilot profile name validator and use it in both the HTTP endpoint and default deployment profile flow. This catches unsupported Intune characters before submission so the API returns a clear bad request or logged error instead of an opaque service-side 500.
1 parent 096abcf commit d141595

3 files changed

Lines changed: 48 additions & 0 deletions

File tree

Modules/CIPPCore/Public/Set-CIPPDefaultAPDeploymentProfile.ps1

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ function Set-CIPPDefaultAPDeploymentProfile {
1919
$APIName = 'Add Default Autopilot Deployment Profile'
2020
)
2121

22+
# Checked before the try so the clean message is thrown as-is rather than wrapped by the catch below.
23+
$NameCheck = Test-CIPPAutopilotProfileName -DisplayName $DisplayName
24+
if (-not $NameCheck.IsValid) {
25+
Write-LogMessage -Headers $Headers -API $APIName -tenant $TenantFilter -message $NameCheck.Message -Sev 'Error'
26+
throw $NameCheck.Message
27+
}
28+
2229
try {
2330
# Map language selection to Graph API locale values:
2431
# 'user-select' -> empty string (lets user choose during OOBE)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
function Test-CIPPAutopilotProfileName {
2+
<#
3+
.SYNOPSIS
4+
Validates an Autopilot deployment profile name against the character set Intune accepts.
5+
.DESCRIPTION
6+
Intune only accepts letters, numbers, spaces and the special characters : " ? . @ $ & _ [ ] { } | \
7+
in a deployment profile name. Anything else (a hyphen being the common one) is rejected by the
8+
service with a generic 500 that carries no reason, so we check up front to return a usable error.
9+
Leading and trailing spaces are allowed.
10+
.OUTPUTS
11+
PSCustomObject with IsValid and Message properties. Message is empty when the name is valid.
12+
#>
13+
[CmdletBinding()]
14+
param(
15+
[string]$DisplayName
16+
)
17+
18+
$AllowedPattern = '^[\p{L}\p{N} :"?.@$&_\[\]{}|\\]+$'
19+
20+
if ([string]::IsNullOrWhiteSpace($DisplayName)) {
21+
$Message = 'Autopilot profile name is required.'
22+
} elseif ($DisplayName -notmatch $AllowedPattern) {
23+
$Message = 'Autopilot profile name contains characters Intune does not accept. Only letters, numbers, spaces and : " ? . @ $ & _ [ ] { } | \ are allowed.'
24+
} else {
25+
$Message = ''
26+
}
27+
28+
return [PSCustomObject]@{
29+
IsValid = [string]::IsNullOrEmpty($Message)
30+
Message = $Message
31+
}
32+
}

Modules/CIPPHTTP/Public/Entrypoints/HTTP Functions/Endpoint/Autopilot/Invoke-AddAutopilotConfig.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ function Invoke-AddAutopilotConfig {
1212
$Headers = $Request.Headers
1313
$Tenants = $Request.Body.selectedTenants.value
1414
$Profbod = [pscustomobject]$Request.Body
15+
16+
$NameCheck = Test-CIPPAutopilotProfileName -DisplayName $Request.Body.DisplayName
17+
if (-not $NameCheck.IsValid) {
18+
return ([HttpResponseContext]@{
19+
StatusCode = [HttpStatusCode]::BadRequest
20+
Body = @{'Results' = $NameCheck.Message }
21+
})
22+
}
23+
1524
$UserType = if ($Profbod.NotLocalAdmin -eq 'true') { 'standard' } else { 'administrator' }
1625
$DeploymentMode = if ($Profbod.DeploymentMode -eq 'true') { 'shared' } else { 'singleUser' }
1726

0 commit comments

Comments
 (0)