Skip to content

Commit 528bc6c

Browse files
committed
update screnshot and ps section
1 parent 549a451 commit 528bc6c

File tree

2 files changed

+32
-60
lines changed

2 files changed

+32
-60
lines changed

articles/web-application-firewall/afds/waf-front-door-configure-custom-response-code.md

Lines changed: 32 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ author: halkazwini
55
ms.author: halkazwini
66
ms.service: azure-web-application-firewall
77
ms.topic: how-to
8-
ms.date: 05/05/2025
8+
ms.date: 05/08/2025
99
ms.custom: devx-track-azurepowershell
1010
---
1111

@@ -15,97 +15,69 @@ In this article, you learn how to configure a custom response page when Azure We
1515

1616
By default, when Azure Web Application Firewall blocks a request because of a matched rule, it returns a 403 status code with the message "The request is blocked." The default message also includes the tracking reference string that's used to link to [log entries](./waf-front-door-monitor.md) for the request. You can configure a custom response status code and a custom message with a reference string for your use case.
1717

18-
## Configure a custom response status code and message
18+
## Prerequisites
1919

2020
# [**Portal**](#tab/portal)
2121

22-
You can configure a custom response status code and body under **Policy settings** on the Azure Web Application Firewall portal.
23-
24-
:::image type="content" source="../media/waf-front-door-configure-custom-response-code/custom-response-settings.png" alt-text="Screenshot that shows Azure Web Application Firewall Policy settings." lightbox="../media/waf-front-door-configure-custom-response-code/custom-response-settings.png":::
22+
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
2523

26-
In the preceding example, we kept the response code as 403 and configured a short "Please contact us" message, as shown in the following image:
27-
28-
:::image type="content" source="../media/waf-front-door-configure-custom-response-code/custom-response.png" alt-text="Screenshot that shows a custom response example.":::
24+
- Sign in to the [Azure portal](https://portal.azure.com) with your Azure account.
2925

3026
# [**PowerShell**](#tab/powershell)
3127

32-
Follow these steps to configure a custom response status code and message by using PowerShell.
28+
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
3329

34-
### Set up your PowerShell environment
30+
- Azure Cloud Shell or Azure PowerShell.
3531

36-
Azure PowerShell provides a set of cmdlets that use the [Azure Resource Manager](../../azure-resource-manager/management/overview.md) model for managing your Azure resources.
32+
The steps in this article run the Azure PowerShell cmdlets interactively in [Azure Cloud Shell](/azure/cloud-shell/overview). To run the cmdlets in the Cloud Shell, select **Open Cloud Shell** at the upper-right corner of a code block. Select **Copy** to copy the code and then paste it into Cloud Shell to run it. You can also run the Cloud Shell from within the Azure portal.
3733

38-
You can install [Azure PowerShell](/powershell/azure/) on your local machine and use it in any PowerShell session. Follow the instructions on the page to sign in with your Azure credentials. Then install the Az PowerShell module.
34+
You can also [install Azure PowerShell locally](/powershell/azure/install-azure-powershell) to run the cmdlets. This article requires the Azure PowerShell module. If you run PowerShell locally, sign in to Azure using the [Connect-AzAccount](/powershell/module/az.accounts/connect-azaccount) cmdlet.
3935

40-
### Connect to Azure with an interactive dialog for sign-in
36+
---
4137

42-
```
43-
Connect-AzAccount
44-
Install-Module -Name Az
38+
## Configure a custom response status code and message
4539

46-
```
47-
Make sure you have the current version of PowerShellGet installed. Run the following command and reopen PowerShell.
40+
# [**Portal**](#tab/portal)
4841

49-
```
50-
Install-Module PowerShellGet -Force -AllowClobber
51-
```
42+
To customize the response status code and body, follow these steps:
5243

53-
### Install the Az.FrontDoor module
44+
1. Go to your Front Door WAF policy in the Azure portal.
5445

55-
```
56-
Install-Module -Name Az.FrontDoor
57-
```
46+
1. Under **Settings**, select **Policy settings**.
5847

59-
### Create a resource group
48+
1. Enter the custom response status code and response body in **Block response status code** and **Block response body** respectively.
6049

61-
In Azure, you allocate related resources to a resource group. Here, we create a resource group by using [New-AzResourceGroup](/powershell/module/Az.resources/new-Azresourcegroup).
50+
:::image type="content" source="../media/waf-front-door-configure-custom-response-code/custom-response-settings.png" alt-text="Screenshot that shows Azure Web Application Firewall Policy settings." lightbox="../media/waf-front-door-configure-custom-response-code/custom-response-settings.png":::
6251

63-
```azurepowershell-interactive
64-
New-AzResourceGroup -Name myResourceGroupWAF
65-
```
52+
1. Select **Save**.
6653

67-
### Create a new WAF policy with a custom response
54+
In the preceding example, we kept the response code as 403 and configured a short "Please contact us" message, as shown in the following image:
6855

69-
The following example shows how to create a new web application firewall (WAF) policy with a custom response status code set to 405 and a message of "You are blocked" by using
70-
[New-AzFrontDoorWafPolicy](/powershell/module/az.frontdoor/new-azfrontdoorwafpolicy).
56+
:::image type="content" source="../media/waf-front-door-configure-custom-response-code/custom-response.png" alt-text="Screenshot that shows a custom response example.":::
7157

72-
```azurepowershell
73-
# WAF policy setting
74-
New-AzFrontDoorWafPolicy `
75-
-Name myWAFPolicy `
76-
-ResourceGroupName myResourceGroupWAF `
77-
-EnabledState enabled `
78-
-Mode Detection `
79-
-CustomBlockResponseStatusCode 405 `
80-
-CustomBlockResponseBody "<html><head><title>You are blocked.</title></head><body></body></html>"
81-
```
58+
# [**PowerShell**](#tab/powershell)
8259

83-
Modify the custom response code or response body settings of an existing WAF policy by using [Update-AzFrontDoorFireWallPolicy](/powershell/module/az.frontdoor/Update-AzFrontDoorWafPolicy).
60+
To customize the response status code and body, use [Update-AzFrontDoorWafPolicy](/powershell/module/az.frontdoor/Update-AzFrontDoorWafPolicy) cmdlet.
8461

85-
```azurepowershell
86-
# modify WAF response code
87-
Update-AzFrontDoorFireWallPolicy `
88-
-Name myWAFPolicy `
89-
-ResourceGroupName myResourceGroupWAF `
90-
-EnabledState enabled `
91-
-Mode Detection `
92-
-CustomBlockResponseStatusCode 403
93-
```
9462

95-
```azurepowershell
63+
```azurepowershell-interactive
9664
# modify WAF response body
97-
Update-AzFrontDoorFireWallPolicy `
98-
-Name myWAFPolicy `
99-
-ResourceGroupName myResourceGroupWAF `
100-
-CustomBlockResponseBody "<html><head><title>Forbidden</title></head><body>{{azure-ref}}</body></html>"
65+
Update-AzFrontDoorWafPolicy `
66+
-Name 'myWAFPolicy' `
67+
-ResourceGroupName 'myResourceGroup' `
68+
-RequestBodyCheck 'Enabled' `
69+
-RedirectUrl 'https://learn.microsoft.com/en-us/azure/web-application-firewall/' `
70+
-CustomBlockResponseStatusCode '403' `
71+
-CustomBlockResponseBody '<html><head><title>WAF Demo</title></head><body><p><h1><strong>WAF Custom Response Page</strong></h1></p><p>Please contact us with this information:<br>{{azure-ref}}</p></body></html>'
10172
```
10273

10374
---
10475

10576
> [!NOTE]
106-
> If you leave the block response body blank, the WAF returns a *403 Forbidden* response for normal WAF blocks and a *429 Too many requests* for rate limit blocks.
77+
> `{{azure-ref}}` inserts the unique reference string in the response body. The value matches the TrackingReference field in the `FrontDoorAccessLog` and `FrontDoorWebApplicationFirewallLog` logs.
10778
108-
`{{azure-ref}}` inserts the unique reference string in the response body. The value matches the TrackingReference field in the `FrontDoorAccessLog` and `FrontDoorWebApplicationFirewallLog` logs.
79+
> [!IMPORTANT]
80+
> If you leave the block response body blank, the WAF returns a *403 Forbidden* response for normal WAF blocks and a *429 Too many requests* for rate limit blocks.
10981
11082
## Next step
11183

45 Bytes
Loading

0 commit comments

Comments
 (0)