|
| 1 | +--- |
| 2 | +title: Method and Route Validator |
| 3 | +description: >- |
| 4 | + This function can be used to protect an application by blocking requests based on the URI and method used. |
| 5 | +meta_tags: API, website, security, URI, method, route, validator |
| 6 | +namespace: docs_use_case_method_and_route_validator |
| 7 | +permalink: /documentation/products/guides/method-and-route-validator/ |
| 8 | +--- |
| 9 | + |
| 10 | +import Tag from 'primevue/tag'; |
| 11 | + |
| 12 | +<Tag severity="info" client:only="vue"> |
| 13 | +Preview |
| 14 | +</Tag> |
| 15 | + |
| 16 | +The **Method and Route Validator** integration can be used to protect your application by blocking requests based on the URI and method used. It works by validating the arguments received by the function and checking if the request matches the patterns defined in any of the values. |
| 17 | + |
| 18 | +With this integration, you can define a list of routes and which method each route expects. Each time the function is executed, it'll perform the following steps: |
| 19 | + |
| 20 | +1. Validate the arguments passed to the function. |
| 21 | +2. Check if the request matches the patterns defined for the routes. |
| 22 | + - If there is a match, the function will perform a user-defined blocking action. |
| 23 | + - If there is no match, the function can be configured to continue the request or block it. |
| 24 | +3. If the arguments are invalid, it'll write a log message and continue the request. |
| 25 | + |
| 26 | +--- |
| 27 | + |
| 28 | +## Getting the integration |
| 29 | + |
| 30 | +To install this integration: |
| 31 | + |
| 32 | +1. Access [Azion Console](/en/documentation/products/guides/how-to-access-azion-console/) > **Marketplace**. |
| 33 | +2. On the Marketplace homepage, select the **Method and Route Validator** card. |
| 34 | +3. On the integration page, click the **Install** button. |
| 35 | + |
| 36 | +You'll see a message indicating that your integration was successfully installed. |
| 37 | + |
| 38 | +:::tip |
| 39 | +You can search any integration by browsing through the cards, using the filters, or typing a keyword in the search bar. |
| 40 | +::: |
| 41 | + |
| 42 | +--- |
| 43 | + |
| 44 | +## Configuring the integration |
| 45 | + |
| 46 | +Once you've installed the **Method and Route Validator** integration, you'll need to complete the steps explained below to configure it. |
| 47 | + |
| 48 | +### Setting up an edge firewall |
| 49 | + |
| 50 | +Follow the steps: |
| 51 | + |
| 52 | +1. On the upper-left corner, open the **Products menu** and select **Edge Firewall** in the **Secure** section. |
| 53 | +2. Click the **+ Edge Firewall** button. |
| 54 | +3. Give an easy-to-remember name to your edge firewall. |
| 55 | +4. Enable the **Edge Functions** switch in the **Modules** section. |
| 56 | + - This action gives access to edge functions on your edge firewall. |
| 57 | +5. Click the **Save** button. |
| 58 | + |
| 59 | +Done. Now you've instantiated the edge firewall for your function and have access to edge functions on your edge firewall. |
| 60 | + |
| 61 | +:::caution[Warning] |
| 62 | +If a product or module is activated, it could generate usage-related costs. Check the [pricing page](/en/documentation/products/pricing/) for more information. |
| 63 | +::: |
| 64 | + |
| 65 | +### Setting up the Edge Firewall function |
| 66 | + |
| 67 | +While still on the **Edge Firewall** page: |
| 68 | + |
| 69 | +1. Select the **Functions Instances** tab. |
| 70 | +2. Click the **+ Function Instance** button. |
| 71 | +3. Give an easy-to-remember name to your instance. |
| 72 | +4. On the dropdown menu, select the **Method and Route Validator** function. |
| 73 | + - This action will load the **Arguments** tab. |
| 74 | +5. In the **Arguments** tab, you'll pass the arguments for your function as in the following example: |
| 75 | + |
| 76 | +```json |
| 77 | +{ |
| 78 | + "restricted_mode": false, |
| 79 | + "action": "deny", |
| 80 | + "routes": [ |
| 81 | + { |
| 82 | + "match_type": "equals", |
| 83 | + "path": "/my/route/", |
| 84 | + "methods": ["GET", "POST"] |
| 85 | + }, |
| 86 | + { |
| 87 | + "match_type": "contains", |
| 88 | + "path": "/something/", |
| 89 | + "methods": ["POST"] |
| 90 | + }, |
| 91 | + { |
| 92 | + "match_type": "regex", |
| 93 | + "path": "^.test.*", |
| 94 | + "methods": ["GET", "POST", "PATCH", "DELETE"] |
| 95 | + } |
| 96 | + ] |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +Where: |
| 101 | + |
| 102 | +| Property | Type | Required | Description | |
| 103 | +| --- | --- | --- | --- | |
| 104 | +| `restricted_mode` | Boolean | No | Indicates if the function should operate in restricted mode. Default value: `false`. | |
| 105 | +| `action` | String | Yes | Defines which action to take when the function identifies the request as invalid. | |
| 106 | +| `routes` | Array | Yes | Contains all the URIs that the protected application expects to handle. | |
| 107 | +| `routes.match_type` | String | Yes | String specifying the type of match to be performed on the path. | |
| 108 | +| `routes.path` | String | Yes | Defines the argument to be used to validate the request URI. | |
| 109 | +| `routes.methods` | Array | Yes | Array of strings specifying which methods can be used when making a request to the given path. | |
| 110 | +| `redirect_to` | String | Only when `action` is `redirect` | URL to which the request should be redirected when the `redirect` action is triggered. Can be a complete request URL or a relative path. | |
| 111 | +| `custom_response_body` | String | Only when `action` is `custom_response` | Custom response body to be sent when the `custom_response` action is triggered. | |
| 112 | +| `custom_response_status` | Number | No | Status code of the response to be sent when the `custom_response` action is triggered. Default value: `400`. | |
| 113 | +| `custom_response_content_type` | String | No | Content type of the response to be sent when the `custom_response` action is triggered. Default value: `plain/text`. | |
| 114 | + |
| 115 | +:::caution |
| 116 | +If `restricted_mode` is enabled, the function will block every request whose URI does not match any of the possible routes listed in the `routes` array. |
| 117 | +::: |
| 118 | + |
| 119 | +The possible values for the `action` argument are: |
| 120 | + |
| 121 | +| Action | Description | |
| 122 | +| --- | --- | |
| 123 | +| `deny` | Closes the request with an HTTP 403 Forbidden response. | |
| 124 | +| `drop` | Closes the request without sending any response to the client. | |
| 125 | +| `redirect` | Redirects the request to another location. | |
| 126 | +| `custom_response` | Closes the request with a static response to it. | |
| 127 | + |
| 128 | +The possible values for the `match_type` argument are: |
| 129 | + |
| 130 | +| Match Type | Description | |
| 131 | +| --- | --- | |
| 132 | +| `equals` | The path must be equal to the one defined in the `path` argument. | |
| 133 | +| `contains` | The path must contain the one defined in the `path` argument. | |
| 134 | +| `regex` | The path must match the regular expression defined in the `path` argument. | |
| 135 | + |
| 136 | +:::note |
| 137 | +The `routes.methods` argument expects values in uppercase. Example: `["GET", "POST"]`. |
| 138 | +::: |
| 139 | + |
| 140 | +6. Click the **Save** button. |
| 141 | + |
| 142 | +### Setting up the Rules Engine |
| 143 | + |
| 144 | +To finish, you have to set up a rule in **Rules Engine** to configure the **criteria** and the **behavior** to run the function. |
| 145 | + |
| 146 | +Still in the **Edge Firewall** page: |
| 147 | + |
| 148 | +1. Select the **Rules Engine** tab. |
| 149 | +2. Click the **+ Rule Engine** button. |
| 150 | +3. Give a name to the rule. |
| 151 | +4. Select a *criteria* to run and catch the domains that you want to run the integration on. |
| 152 | + - Example: if `Host` *matches* `yourdomain.com`. |
| 153 | +5. Below, select a *behavior* to the *criteria*. In this case, it'll be **Run Function**. |
| 154 | + - Select the adequate function according to the name you gave it during the instantiation step. |
| 155 | +6. Click the **Save** button. |
| 156 | + |
| 157 | +On the Console, you must now configure your domain so your edge firewall protects it. |
| 158 | + |
| 159 | +7. On the **Products menu**, select **Domains**. |
| 160 | +8. Click on the domain you want to protect with your **Method and Route Validator** function. |
| 161 | +9. In the **Settings** section, click on the `Edge Firewall` selector and choose the edge firewall you created. |
| 162 | +10. Click the **Save** button. |
| 163 | + |
| 164 | +Done. Now **Method and Route Validator** is running and protecting your domains. |
0 commit comments