This repository was archived by the owner on Sep 17, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 192
Expand file tree
/
Copy pathTest-Assessment.25415.ps1
More file actions
234 lines (205 loc) · 12 KB
/
Copy pathTest-Assessment.25415.ps1
File metadata and controls
234 lines (205 loc) · 12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<#
.SYNOPSIS
Enterprise generative AI applications are protected from prompt injection attacks through AI Gateway.
.DESCRIPTION
Verifies that Prompt Shield (AI Gateway) is properly configured to protect against prompt injection attacks.
The test passes if prompt policies exist and are enforced either through the Baseline Profile or through
Security Profiles assigned to Conditional Access policies.
#>
function Test-Assessment-25415 {
[ZtTest(
Category = 'Global Secure Access',
ImplementationCost = 'Medium',
Service = ('Graph'),
MinimumLicense = ('Entra_Premium_Internet_Access'),
CompatibleLicense = ('Entra_Premium_Internet_Access'),
Pillar = ('Network', 'AI'),
RiskLevel = 'High',
SfiPillar = 'Protect networks',
TenantType = ('Workforce'),
TestId = 25415,
Title = 'AI Gateway protects enterprise generative AI applications from prompt injection attacks',
UserImpact = 'Low'
)]
[CmdletBinding()]
param()
# Define constants
[int]$BASELINE_PROFILE_PRIORITY = 65000
#region Data Collection
Write-PSFMessage '🟦 Start Prompt Shield evaluation' -Tag Test -Level VeryVerbose
$activity = 'Checking Prompt Shield configuration for AI Gateway protection'
Write-ZtProgress -Activity $activity -Status 'Querying prompt policies'
# Q1: Get prompt policies
$promptPolicies = Invoke-ZtGraphRequest -RelativeUri 'networkAccess/promptPolicies' -QueryParameters @{
'$expand' = 'policyRules'
} -ApiVersion beta
# Q2: Get filtering profiles with linked policies and Conditional Access policies
Write-ZtProgress -Activity $activity -Status 'Querying security profiles and linked policies'
$filteringProfiles = Invoke-ZtGraphRequest -RelativeUri 'networkAccess/filteringProfiles' -QueryParameters @{
'$expand' = 'policies($expand=policy),conditionalAccessPolicies'
} -ApiVersion beta
# Get all Conditional Access policies
Write-ZtProgress -Activity $activity -Status 'Querying Conditional Access policies'
$allCAPolicies = Get-ZtConditionalAccessPolicy
#endregion Data Collection
#region Assessment Logic
$enabledSecurityProfiles = @()
$enabledBaselineProfiles = @()
$allPromptPolicyIds = @()
# Collect all prompt policy IDs from Q1
if ($promptPolicies) {
$allPromptPolicyIds = $promptPolicies | ForEach-Object { $_.id }
}
# Find profiles linked to each prompt policy
foreach ($promptPolicy in $promptPolicies) {
$findParams = @{
PolicyId = $promptPolicy.id
FilteringProfiles = $filteringProfiles
CAPolicies = $allCAPolicies
BaselinePriority = $BASELINE_PROFILE_PRIORITY
PolicyLinkType = 'promptPolicyLink'
PolicyRules = $promptPolicy.policyRules
}
$linkedProfiles = Find-ZtProfilesLinkedToPolicy @findParams
foreach ($profileLink in $linkedProfiles) {
if ($profileLink.ProfileType -eq 'Baseline Profile' -and $profileLink.PassesCriteria -and $profileLink.ProfileState -eq 'enabled') {
$enabledBaselineProfiles += [PSCustomObject]@{
ProfileId = $profileLink.ProfileId
ProfileName = $profileLink.ProfileName
ProfileState = $profileLink.ProfileState
ProfilePriority = $profileLink.ProfilePriority
PromptPolicyId = $promptPolicy.id
PromptPolicyName = $promptPolicy.name
PromptPolicyAction = $promptPolicy.action
RulesCount = if ($promptPolicy.policyRules) { @($promptPolicy.policyRules).Count } else { 0 }
LastModified = $promptPolicy.lastModifiedDateTime
PromptPolicyLinkState = $profileLink.PolicyLinkState
}
}
elseif ($profileLink.ProfileType -eq 'Security Profile' -and $profileLink.PassesCriteria -and $profileLink.ProfileState -eq 'enabled') {
$matchedCAPolicies = @()
if ($null -ne $profileLink.CAPolicy) {
$matchedCAPolicies = @($profileLink.CAPolicy)
}
$enabledSecurityProfiles += [PSCustomObject]@{
ProfileId = $profileLink.ProfileId
ProfileName = $profileLink.ProfileName
ProfileState = $profileLink.ProfileState
ProfilePriority = $profileLink.ProfilePriority
PromptPolicyId = $promptPolicy.id
PromptPolicyName = $promptPolicy.name
PromptPolicyAction = $promptPolicy.action
RulesCount = if ($promptPolicy.policyRules) { @($promptPolicy.policyRules).Count } else { 0 }
LastModified = $promptPolicy.lastModifiedDateTime
PromptPolicyLinkState = $profileLink.PolicyLinkState
MatchedCAPolicies = $matchedCAPolicies
CAPolicyCount = $matchedCAPolicies.Count
}
}
}
}
$testResultMarkdown = ''
$passed = $false
$mdInfo = ''
# Evaluation logic per spec
if ($null -eq $promptPolicies -or $promptPolicies.Count -eq 0) {
# No prompt policies configured
$testResultMarkdown = "❌ Prompt Shield is not properly configured - no prompt policies exist.`n`n%TestResult%"
$passed = $false
}
elseif ($enabledBaselineProfiles.Count -gt 0) {
# Condition B: Baseline Profile has prompt policies (applies to all traffic)
$testResultMarkdown = "✅ Prompt Shield policies are configured and enforced through the Baseline Profile which applies to all internet traffic.`n`n%TestResult%"
$passed = $true
}
elseif ($enabledSecurityProfiles.Count -gt 0) {
# Condition A: Security profiles with prompt policies AND CA policy assignment
$testResultMarkdown = "✅ Prompt Shield policies are configured and enforced through security profiles assigned to Conditional Access policies.`n`n%TestResult%"
$passed = $true
}
else {
# Prompt policies exist but are not enforced
$testResultMarkdown = "❌ Prompt Shield is not properly configured - policies are not linked to security profiles, or security profiles with prompt policies are not enforced (no CA policy assignment and not using Baseline Profile).`n`n%TestResult%"
$passed = $false
}
#endregion Assessment Logic
#region Report Generation
if ($passed) {
# Build detailed report only when test passes
$formatTemplate = @'
## Prompt Policies (AI Gateway)
| Policy Name | Action | Rules Count | Last Modified |
| :---------- | :----- | :---------- | :------------ |
{0}
{1}
{2}
'@
# Table 1: Prompt Policies
$promptPoliciesRows = ''
if ($promptPolicies -and $promptPolicies.Count -gt 0) {
foreach ($policy in $promptPolicies) {
$policyPortalLink = "https://entra.microsoft.com/#view/Microsoft_Azure_Network_Access/EditPromptPolicyMenuBlade.MenuView/~/basics/policyId/$($policy.id)"
$policyName = Get-SafeMarkdown -Text $policy.name
$action = if ($policy.action) { $policy.action } else { 'Not specified' }
$rulesCount = if ($policy.policyRules) { @($policy.policyRules).Count } else { 0 }
$lastModified = if ($policy.lastModifiedDateTime) { $policy.lastModifiedDateTime } else { 'N/A' }
$promptPoliciesRows += "| [$policyName]($policyPortalLink) | $action | $rulesCount | $lastModified |`n"
}
}
# Table 2: Baseline Profiles with Prompt Policies
$baselineProfilesSection = ''
if ($enabledBaselineProfiles.Count -gt 0) {
$baselineProfilesSection += "`n## Prompt Policies Linked to Baseline Profile`n`n"
$baselineProfilesSection += "| Profile Name | Priority | State | Prompt Policy | Policy Link State | Rules Count |`n"
$baselineProfilesSection += "| :----------- | :------- | :---- | :------------ | :---------------- | :---------- |`n"
foreach ($profile in $enabledBaselineProfiles) {
$profilePortalLink = "https://entra.microsoft.com/#view/Microsoft_Azure_Network_Access/EditProfileMenuBlade.MenuView/~/basics/profileId/$($profile.ProfileId)"
$policyPortalLink = "https://entra.microsoft.com/#view/Microsoft_Azure_Network_Access/EditPromptPolicyMenuBlade.MenuView/~/basics/policyId/$($profile.PromptPolicyId)"
$profileName = Get-SafeMarkdown -Text $profile.ProfileName
$policyName = Get-SafeMarkdown -Text $profile.PromptPolicyName
$baselineProfilesSection += "| [$profileName]($profilePortalLink) | $($profile.ProfilePriority) | $($profile.ProfileState) | [$policyName]($policyPortalLink) | $($profile.PromptPolicyLinkState) | $($profile.RulesCount) |`n"
}
}
# Table 3: Security Profiles with Prompt Policies and CA Assignments
$securityProfilesSection = ''
if ($enabledSecurityProfiles.Count -gt 0) {
$securityProfilesSection += "`n## Security Profiles with Linked Policies`n`n"
$securityProfilesSection += "| Profile Name | State | Priority | Prompt Policy | CA Policies Assigned | Is Baseline |`n"
$securityProfilesSection += "| :----------- | :---- | :------- | :------------ | :------------------- | :---------- |`n"
foreach ($profile in $enabledSecurityProfiles) {
$profilePortalLink = "https://entra.microsoft.com/#view/Microsoft_Azure_Network_Access/EditProfileMenuBlade.MenuView/~/basics/profileId/$($profile.ProfileId)"
$policyPortalLink = "https://entra.microsoft.com/#view/Microsoft_Azure_Network_Access/EditPromptPolicyMenuBlade.MenuView/~/basics/policyId/$($profile.PromptPolicyId)"
$profileName = Get-SafeMarkdown -Text $profile.ProfileName
$policyName = Get-SafeMarkdown -Text $profile.PromptPolicyName
$isBaseline = if ($profile.ProfilePriority -eq $BASELINE_PROFILE_PRIORITY) { 'Yes' } else { 'No' }
$caCount = $profile.CAPolicyCount
$securityProfilesSection += "| [$profileName]($profilePortalLink) | $($profile.ProfileState) | $($profile.ProfilePriority) | [$policyName]($policyPortalLink) | $caCount | $isBaseline |`n"
}
# Table 4: Conditional Access Policies
$securityProfilesSection += "`n## Conditional Access Policies Assigned to Security Profiles`n`n"
$securityProfilesSection += "| CA Policy Name | Security Profile | CA Policy ID |`n"
$securityProfilesSection += "| :------------- | :--------------- | :----------- |`n"
foreach ($profile in $enabledSecurityProfiles) {
foreach ($caPolicy in $profile.MatchedCAPolicies) {
$caPolicyPortalLink = "https://entra.microsoft.com/#view/Microsoft_AAD_ConditionalAccess/PolicyBlade/policyId/$($caPolicy.Id)"
$profileName = Get-SafeMarkdown -Text $profile.ProfileName
$caPolicyName = Get-SafeMarkdown -Text $caPolicy.DisplayName
$securityProfilesSection += "| [$caPolicyName]($caPolicyPortalLink) | $profileName | $($caPolicy.Id) |`n"
}
}
}
$mdInfo = $formatTemplate -f $promptPoliciesRows, $baselineProfilesSection, $securityProfilesSection
}
else {
# For failed states, just show the portal link
$mdInfo = "[View Prompt Shield Configuration](https://entra.microsoft.com/#view/Microsoft_Azure_Network_Access/PromptPolicy.ReactView)`n"
}
$testResultMarkdown = $testResultMarkdown -replace '%TestResult%', $mdInfo
#endregion Report Generation
$params = @{
TestId = '25415'
Status = $passed
Result = $testResultMarkdown
}
Add-ZtTestResultDetail @params
}