Help Center> Web Application Firewall> User Guide> Rule Configuration> Configuring a Precise Protection Rule

Configuring a Precise Protection Rule

WAF allows you to customize protection rules by combining HTTP headers, cookies, URLs, request parameters, and client IP addresses.

You can combine common HTTP fields, such as IP, Path, Referer, User Agent, and Params in a protection rule to let WAF allow or block the requests that match the combined conditions.

A reference table can be added to a precise protection rule. The reference table takes effect for all protected domain names.

If you have enabled enterprise projects, you can select your enterprise project from the Enterprise Project drop-down list and add protection policies for the domain names in the project.

Prerequisites

A website has been added to WAF.

Specification Limitations

This function is unavailable in the detection edition.

Constraints

  • Full Detection is not included in the standard (former professional) edition.
  • The Response field cannot be configured in the standard (former professional) edition.
  • Managing reference tables is not included in the standard (former professional) edition.
  • It takes several minutes for a new rule to take effect. After the rule takes effect, protection events triggered by the rule will be displayed on the Events page.
  • If you set Protective Action to Block for a precise protection rule, you can configure a known attack source rule. WAF can then block requests matching the configured IP, Cookie, or Params for a length of time that configured in the known attack source rule. For details, see Configuring a Known Attack Source Rule.

Application Scenarios

Precise protection rules are used for anti-leeching and website management background protection.

Procedure

  1. Log in to the management console.
  2. Go to the protection policy configuration page by following the steps shown in Figure 1.

    Figure 1 Access to the protection policy configuration page

  3. In the Precise Protection configuration area, change Status if needed and click Customize Rule to go to the Precise Protection page. Figure 2 shows an example.

    Figure 2 Precise Protection configuration area

  4. On the Precise Protection page, set Detection Mode. Figure 3 shows an example.

    Two detection modes are available:
    • Instant Detection: If a request matches a configured precise protection rule, WAF immediately ends threat detection and blocks the request.
    • Full Detection: If a request matches a configured precise protection rule, WAF finishes its scan first and then blocks all requests that match the configured precise protection rule.
      Figure 3 Setting Detection Mode

  5. Click Add Rule.
  6. In the displayed dialog box, add a rule by referring to Table 1 and Example Configuration.

    The settings shown in Figure 4 are used as an example. If a visitor tries to access a URL containing /admin, WAF will block the request.

    Figure 4 Add Precise Protection Rule
    Table 1 Rule parameters

    Parameter

    Description

    Example Value

    Protective Action

    You can select Block, Allow, or Log only. Default value: Block

    Block

    Known Attack Source

    If you set Protective Action to Block, you can select a blocking type for a known attack source rule. Then, WAF blocks requests matching the configured IP, Cookie, or Params for a length of time that depends on the selected blocking type.

    Long-term IP address blocking

    Effective Date

    Select Immediate to enable the rule immediately, or select Custom to configure when you wish the rule to be enabled.

    Immediate

    Condition List

    Click Add to add conditions. At least one condition needs to be added. You can add up to 30 conditions to a protection rule. If more than one condition is added, all of the conditions must be met for the rule to be applied. A condition includes the following parameters:

    Parameters for configuring a condition are described as follows:
    • Field
    • Subfield: Configure this field only when Params, Cookie, or Header is selected for Field.
      NOTICE:

      The length of a subfield cannot exceed 2,048 bytes. Only digits, letters, underscores (_), and hyphens (-) are allowed.

    • Logic: Select a logical relationship from the drop-down list.
      NOTE:
      • If Include any value, Exclude any value, Equal to any value, Not equal to any value, Prefix is any value, Prefix is not any of them, Suffix is any value, or Suffix is not any of them is selected, select an existing reference table in the Content drop-down list. For details, see Adding a Reference Table.
      • Exclude any value, Not equal to any value, Prefix is not any of them, and Suffix is not any of them indicates, respectively, that WAF performs the protection action (block, allow, or log only) when the field in the access request does not contain, is not equal to, or the prefix or suffix is not any value set in the reference table. For example, assume that Path field is set to Exclude any value and the test reference table is selected. If test1, test2, and test3 are set in the test reference table, WAF performs the protection action when the path of the access request does not contain test1, test2, or test3.
    • Content: Enter or select the content of condition matching.
    NOTE:

    For more details about the configurations in general, see Table 2.

    • Path Include /admin
    • User Agent Prefix is not mozilla/5.0
    • IP Equal to 192.168.2.3
    • Cookie key1 Prefix is not Nessus

    Priority

    Rule priority. If you have added multiple rules, rules are matched by priority. The smaller the value you set, the higher the priority

    5

    Rule Description

    A brief description of the rule. This parameter is optional.

    None

    Table 2 Condition list configurations

    Field

    Example Subfield

    Logic

    Example Content

    Path: Part of a URL that does not include a domain name. This value supports exact matches only. For example, if the path to be protected is /admin, Path must be set to /admin.

    None

    Select a logical relationship from the drop-down list.

    /buy/phone/

    User Agent: A user agent of the scanner to be checked.

    None

    Mozilla/5.0 (Windows NT 6.1)

    IP: An IP address of the visitor for the protection.

    IPv4 and IPv6 addresses are supported.

    NOTICE:

    IPv6 protection is available in the professional (former enterprise) and platinum (former premium) editions only. Currently, IPv4/IPv6 dual stack and NAT64 are supported only in East China and North China regions.

    None

    • IPv4 address, such as 192.168.1.1
    • IPv6 address, such as 1050:0:0:0:5:600:300c:326b

    Params: A request parameter.

    sttl

    201901150929

    Referer: A user-defined request resource.

    For example, if the protected path is /admin/xxx and you do not want visitors to access the page from www.test.com, set Content to http://www.test.com.

    None

    http://www.test.com

    Cookie: A small piece of data to identify web visitors.

    name

    Nessus

    Header: A user-defined HTTP header.

    Accept

    text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8

    Method: the user-defined request method.

    None

    GET, POST, PUT, DELETE, and PATCH

    Request Line: Length of a user-defined request line.

    None

    50

    Request: Length of a user-defined request. It includes the request header, request line, and request body.

    None

    None

    Protocol: the protocol of the request.

    None

    http

    Response Code: Status code returned to the request.

    None

    • Equal to
    • Not equal to
    • Equal to any value
    • Not equal to any value

    404

    Response Length: the length of the response to the request.

    None

    • Subfield length equal to
    • Subfield length not equal to
    • Subfield length greater than
    • Subfield length less than

    None

    Response Time: time to respond the request.

    None

    • Subfield length equal to
    • Subfield length not equal to
    • Subfield length greater than
    • Subfield length less than

    None

    Response Header: response header.

    None

    • Include
    • Exclude
    • Equal to
    • Not equal to

    None

    Response Body: response message body

    None

    • Include
    • Exclude
    • Include any value
    • Exclude any value

    None

    Response Code, Response Length, Response Time, Response Header, and Response Body are supported by the professional (former enterprise) and platinum (former premium) editions and dedicated and ELB modes in the following regions:

    • CN North-Beijing1
    • CN North-Beijing4
    • CN East-Shanghai1
    • CN South-Guangzhou
    • CN East-Shanghai2
    • CN-Hong Kong
    • AP-Bangkok
    • RU-Moscow

  7. Click OK. You can then view the added precise protection rule in the protection rule list.

    Figure 5 Protection rules
    • To disable a rule, click Disable in the Operation column of the rule. The default Rule Status is Enabled.
    • To modify a rule, click Modify in the row containing the rule.
    • To delete a rule, click Delete in the row containing the rule.

Protection Effect

If you have configured a precise protection rule as shown in Figure 4 for your domain name, to verify WAF is protecting your website (www.example.com) against the rule:

  1. Clear the browser cache and enter the domain name in the address bar to check whether the website is accessible.

  2. Clear the browser cache and enter http://www.example.com/admin (or any page containing /admin) in the address bar. Normally, WAF blocks the requests that meet the conditions and returns the block page.
  3. Return to the WAF console. In the navigation pane, click Events. On the displayed page, view or download events data.

Example Configuration

A precise protection rule is a combination of multiple fields. Some example rules below are for your reference.

  • Blocking specific attack requests

    Analysis of a specific type of WordPress pingback attack shows that the User Agent field contains WordPress. See Figure 6.

    Figure 6 WordPress pingback attack

    A precise rule as shown in the figure can block this type of attack.

    Figure 7 User Agent configuration
  • Blocking specific URL requests

    If a large number of IP addresses are accessing a URL that does not exist, configure the following protection rule to block such requests to reduce resource usage on the origin server. Figure 8 shows the rule configuration.

    Figure 8 Blocking a specific URL
  • Preventing hotlinking

    You can configure a protection rule based on the Referer field to enable WAF to block hotlinking from a specific website. If you find out that, for example, requests from https://abc.blog.com are stealing images from your site, you can configure a rule to block such requests.

    Figure 9 Hotlinking prevention
  • Allowing the access of a specified IP address

    You can configure two precise protection rules, one to block all requests, as shown in Figure 10, but then another one to allow the access from a specific IP address, as shown in Figure 11.

    Figure 10 Blocking all requests
    Figure 11 Allowing the access of a specified IP address