You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/web-application-firewall/afds/waf-front-door-configure-custom-response-code.md
+32-60Lines changed: 32 additions & 60 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ author: halkazwini
5
5
ms.author: halkazwini
6
6
ms.service: azure-web-application-firewall
7
7
ms.topic: how-to
8
-
ms.date: 05/05/2025
8
+
ms.date: 05/08/2025
9
9
ms.custom: devx-track-azurepowershell
10
10
---
11
11
@@ -15,97 +15,69 @@ In this article, you learn how to configure a custom response page when Azure We
15
15
16
16
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.
17
17
18
-
## Configure a custom response status code and message
18
+
## Prerequisites
19
19
20
20
# [**Portal**](#tab/portal)
21
21
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).
25
23
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.
29
25
30
26
# [**PowerShell**](#tab/powershell)
31
27
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).
33
29
34
-
### Set up your PowerShell environment
30
+
- Azure Cloud Shell or Azure PowerShell.
35
31
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.
37
33
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.
39
35
40
-
### Connect to Azure with an interactive dialog for sign-in
36
+
---
41
37
42
-
```
43
-
Connect-AzAccount
44
-
Install-Module -Name Az
38
+
## Configure a custom response status code and message
45
39
46
-
```
47
-
Make sure you have the current version of PowerShellGet installed. Run the following command and reopen PowerShell.
40
+
# [**Portal**](#tab/portal)
48
41
49
-
```
50
-
Install-Module PowerShellGet -Force -AllowClobber
51
-
```
42
+
To customize the response status code and body, follow these steps:
52
43
53
-
### Install the Az.FrontDoor module
44
+
1. Go to your Front Door WAF policy in the Azure portal.
54
45
55
-
```
56
-
Install-Module -Name Az.FrontDoor
57
-
```
46
+
1. Under **Settings**, select **Policy settings**.
58
47
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.
60
49
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":::
62
51
63
-
```azurepowershell-interactive
64
-
New-AzResourceGroup -Name myResourceGroupWAF
65
-
```
52
+
1. Select **Save**.
66
53
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:
68
55
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
:::image type="content" source="../media/waf-front-door-configure-custom-response-code/custom-response.png" alt-text="Screenshot that shows a custom response example.":::
71
57
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)
82
59
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.
-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>'
101
72
```
102
73
103
74
---
104
75
105
76
> [!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.
107
78
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.
0 commit comments