All Products
Search
Document Center

Web Application Firewall:CreateDefenseRule

Last Updated:Sep 09, 2026

Creates a Web core protection rule.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

yundun-waf:CreateDefenseRule

create

*All Resource

*

  • acs:ResourceGroupId
None

Request parameters

Parameter

Type

Required

Description

Example

InstanceId

string

Yes

Instance ID of the WAF instance.

Note

You can call the DescribeInstance operation to query instance ID of your current WAF instance.

waf_v2_public_cn-****

TemplateId

integer

No

The ID of the protection template for the protection rule to be created.

Note

This parameter is required only when DefenseType is set to template. There is an upper limit on the number of rules that can be created within the same protection template. For specific limits, refer to Rule quantity limits. When the rule quantity has reached the upper limit, you can call the CreateDefenseTemplate operation to create a new protection template. You can also call the ModifyDefenseRule operation to modify an existing rule.

1122

DefenseScene

string

Yes

The WAF protection scenario to create.

When the protection rule type DefenseType is set to template, valid values:

  • waf_group: basic protection.

  • waf_base: new version of Web Core Protection.

  • antiscan: Scan Protection.

  • ip_blacklist: IP Blacklist.

  • custom_acl: Custom Rule.

  • whitelist: Whitelist.

  • region_block: Location Blacklist.

  • custom_response: legacy Custom Response.

  • cc: HTTP Flood Protection.

  • tamperproof: web tamper proofing.

  • dlp: Information Leak Prevention.

  • spike_throttle: peak traffic throttling.

  • bot_manager: BOT Management.

When the protection rule type DefenseType is set to resource, valid values:

  • account_identifier: Account Extraction.

  • custom_response: new version of Custom Response.

  • waf_codec: Decoding.

  • websdk: WebSDK Integration.

When the protection rule type DefenseType is set to global, valid values:

  • regular_custom: Custom Regex.

  • address_book: Address Book.

  • custom_response: new version of Custom Response.

Note

For the custom response in global configuration, users can reference it at the protected object or rule level. When custom response rules are referenced at different dimensions, the actual effective logic is: rule level > protected object level > default page.

waf_group

Rules

string

Yes

The rule configuration content, which is a string converted from a JSON-formatted array of parameters.

Note

The specific parameters vary depending on the specified protection rule type (DefenseScene). For more information, refer to Protection rule parameter descriptions.

waf_group

ResourceManagerResourceGroupId

string

No

Specifies whether to enable the dry run mode. If you do not specify this parameter, a normal request is sent. Valid values:

  • true: A dry run request is sent. The system only checks whether the request meets the execution conditions without performing the specified operation. If the dry run fails, the corresponding error code is returned. If the dry run succeeds, the error code Defense.Control.DryRunOperation is returned.

  • false: A normal request is sent. The specified operation is performed after the request passes the check.

false

DefenseType

string

No

The ID of the Alibaba Cloud resource group.

Valid values:

  • template :

    (Default) template protection rule.

  • resource :

    protection object-level rule.

  • global :

    global-level rule.

rg-acfm***q

RegionId

string

No

The type of the protection rule.

Valid values:

  • template :

    (Default) Template-based protection rule.

  • resource :

    Protected object-level rule.

  • global :

    Global-level rule.

template

Resource

string

No

The region where the WAF instance resides. Valid values:

  • cn-hangzhou: the Chinese mainland.

  • ap-southeast-1: outside the Chinese mainland.

cn-hangzhou

No

The protected object associated with the rule to be created.

Note

This parameter is required only when DefenseType is set to resource.

sec****-waf

Protection rule parameter descriptions

Rule quantity limits

Within the same protection template, there is an upper limit on the number of rules that can be created for basic protection scenario (DefenseScene). The following scenarios have fixed limits. The limits for other scenarios depend on the WAF instance edition. For more information, refer to Feature comparison across editions.

Protection scenarioDefenseSceneRule quantity limitDescription
Basic Web Protectionwaf_group3One rule for basic protection rule type (protectionType).
New version of Web Core Protectionwaf_base1
Scan Protectionantiscan3One rule for each scan protection subtype (protectionType): high-frequency scan blocking, directory traversal blocking, and scan tool blocking.
Location Blacklistregion_block1
Legacy Custom Responsecustom_response1This limit applies to the legacy custom response when DefenseType is set to template. For the new version of custom response, refer to Feature comparison across editions.
HTTP Flood Protectioncc1
BOT Managementbot_manager—One rule for each rule tag (botRuleDetail.ruleKey) in scenario-based rules.
Decodingwaf_codec1
Account Extractionaccount_identifier1
WebSDK Integrationwebsdk1
Note

When the protection rule type DefenseType is set to template and the number of rules for the target scenario in the target template has reached the upper limit, the creation fails. In this case, you can call the CreateDefenseTemplate operation to create a new protection template. You can also call the ModifyDefenseRule operation to modify an existing rule.

Template-based protection rules (template)

When the protection rule type DefenseType is set to template, the specific rule configuration content is as follows.

Basic protection rules (waf_group)

Parameter descriptions

NameTypeRequiredExampleDescription
statusIntegerYes1The status of basic protection rule. This parameter is used only for creating protection rules. To modify the status of a protection rule, use the RuleStatus parameter of the ModifyDefenseRuleStatus operation. Valid values:
- 0: Disabled.
- 1 (default): Enabled.




actionStringYesblockThe action of basic protection rule. Valid values:
- block: Block.
- monitor: Monitor.




policyIdLongNo1012The ID of basic protection rule group. Default value: 1012 (medium rule group).
protectionTypeStringNosemaThe type of basic protection rule. Valid values:
- regular (default): Regex-based protection.
- sema: Semantic-based protection.




configStringNo{"nonInjectionSql":1}The custom configuration in JSON string format. For more information, refer to config detailed configuration.

config detailed configuration

  • When protectionType is set to sema (Basic Web Protection rule configured as semantic-based protection)

NameTypeRequiredExampleDescription
nonInjectionSqlIntegerYes1The status of non-injection attack detection. Valid values:
- 0: Disabled.
- 1 (default): Enabled.




Example

{
    "DefenseScene": "waf_group",
    "TemplateId": 322,
    "InstaneId": "waf_cn****",
    "Rules": "[{\"status\":1,\"policyId\":1012,\"action\":\"block\"},{\"status\":1,\"action\":\"block\",\"protectionType\":\"sema\",\"config\":\"{\\\"nonInjectionSql\\\":1}\"}]"
}

New version of Web Core Protection rules (waf_base)

Parameter descriptions

NameTypeRequiredExampleDescription
autoUpdateBooleanYestrueSpecifies whether to enable automatic updates. Valid values:
- true: Enable automatic updates.
- false: Disable automatic updates.




configArrayYes[{"ruleType":"system","ruleDetail":[{"ruleId":13000412,"ruleStatus":1,"ruleAction":"block"}]}]The rule configuration to modify. For more information, refer to config detailed configuration.
Important You can call the DescribeBaseSystemRules operation to query the system protection rule configuration of this template, and call the DescribeDefenseRules operation to query the custom regex rule configuration of this template.

config detailed configuration

NameTypeRequiredExampleDescription
ruleTypeStringYessystemThe rule type. Valid values:
- system: System rules in Basic Basic protection.
- custom: Custom regex rules in Basic Basic protection.




ruleBatchOperationConfigStringNodefaultThe batch rule modification operation. When this field is not empty, the RuleDetail field must be empty. Valid values:
- default: Restore to default.
- all_on: Enable all rules.
- all_off: Disable all rules.
- all_block: Set all rule actions to block.
- all_monitor: Set all rule actions to monitor.













ruleDetailArrayNo[{"ruleId":13000412,"ruleStatus":1,"ruleAction":"block"}]]The rule configuration to modify. Fields:
- ruleId: The rule ID.
- ruleStatus: The rule status.
- ruleAction: The rule action.







Example

{
    "DefenseScene": "waf_base",
    "TemplateId": 322,
    "InstaneId": "waf_cn****",
    "Rules": "[{\"autoUpdate\":true,\"config\":[{\"ruleType\":\"system\",\"ruleDetail\":[{\"ruleId\":13000412,\"ruleStatus\":1,\"ruleAction\":\"block\"}]}]}]"
}

Scan Protection rules (antiscan)

Parameter descriptions

NameTypeRequiredExampleDescription
protectionTypeStringYeshighfreqThe subtype of the scan protection rule. Valid values:
- highfreq: High-frequency scan blocking.
- dirscan: Directory traversal blocking.
- scantools: Scan tool blocking.







statusIntegerYes1The status of the protection rule. This parameter is used only for creating protection rules. To modify the status of a protection rule, use the RuleStatus parameter of the ModifyDefenseRuleStatus operation. Valid values:
- 0: Disabled.
- 1 (default): Enabled.




actionStringYesblockThe action of the protection rule. Valid values:
- block: Block.
- monitor: Monitor.




actionExternalJSONNo{"responseRuleId":123444}The extended configuration of the protection rule action. Only the new version of custom response supports this configuration. When action is set to block, you can specify a custom block page.
configStringNo{"target":"remote_addr","interval":60,"ttl":180,"count":20}The custom configuration in JSON string format. For more information, refer to config detailed configuration.

config detailed configuration

  • When protectionType is set to highfreq (scan protection rule configured as high-frequency scan blocking)

NameTypeRequiredExampleDescription
targetStringYesremote_addrThe object type for statistics. Valid values:
- remote_addr (default): IP address.
- cookie.acw_tc: Session.
- header: Custom Header. When you select Custom Header, you must specify the header content to be counted in the subkey parameter.
- queryarg: Custom parameter. When you select Custom parameter, you must specify the custom parameter name to be counted in the subkey parameter.
- cookie: Custom Cookie. When you select Custom Cookie, you must specify the cookie content to be counted in the subkey parameter.













subKeyStringNoabcThe sub-feature of the statistical object. This parameter is required when the target parameter is set to cookie, header, or queryarg.
intervalIntegerNo60The detection period, in seconds. Default value: 60.
Valid values: 5 to 1800.

ttlIntegerNo1800The blocking duration, in seconds. Default value: 1800.
Valid values: 60 to 86400.

countIntegerNo20The maximum number of times the basic protection rule is triggered. Default value: 20.
Valid values: 3 to 50000.

ruleIdCountIntegerNo2The maximum number of triggered rules. Default value: 2.
Valid values: 1 to 50.

  • When protectionType is set to dirscan (scan protection rule configured as directory traversal blocking)

NameTypeRequiredExampleDescription
targetStringYesremote_addrThe statistical and blocking object. Valid values:
- remote_addr (default): IP address.
- cookie.acw_tc: Session.
- header: Custom Header.
- queryarg: Custom parameter.
- cookie: Custom Cookie.













subKeyStringNo1The sub-feature of the statistical and blocking object. Configure this parameter only when target is set to header, queryarg, or cookie.
intervalIntegerNo60The detection period, in seconds. Default value: 60.
Valid values: 5 to 1800.

ttlIntegerNo1800The blocking duration, in seconds. Default value: 1800.
Valid values: 60 to 86400.

countIntegerNo20The maximum number of times the basic protection rule is triggered. Default value: 20.
Valid values: 3 to 50000.

weightFloatNo2The percentage of 404 response codes. Default value: 0.7.
Valid values: 0.01 to 1.0, accurate to two decimal places.

uriNumIntegerNo2The maximum number of non-existent directories. Default value: 50.
Valid values: 2 to 50000.

Example

{
    "InstanceId": "waf_v2_public_****",
    "TemplateId": 2222,
    "DefenseScene": "antiscan",
    "Rules": "[{\"protectionType\":\"scantools\",\"action\":\"block\",\"status\":1},{\"protectionType\":\"dirscan\",\"status\":1,\"action\":\"block\",\"config\":\"{\\\"target\\\":\\\"remote_addr\\\",\\\"interval\\\":10,\\\"ttl\\\":1800,\\\"weight\\\":0.7,\\\"uriNum\\\":50,\\\"count\\\":50}\"},{\"protectionType\":\"highfreq\",\"status\":1,\"action\":\"block\",\"config\":\"{\\\"target\\\":\\\"remote_addr\\\",\\\"interval\\\":60,\\\"ttl\\\":1800,\\\"count\\\":20,\\\"ruleIdCount\\\":2}\"}]"
}

IP Blacklist rules (ip_blacklist)

Parameter descriptions

NameTypeRequiredExampleDescription
nameStringYesiptestThe name of the IP blacklist rule. The name must be 1 to 255 characters in length and can contain Chinese characters, letters, digits, underscores (_), periods (.), or hyphens (-).
statusIntegerYes1The status of the protection rule. This parameter is used only for creating protection rules. To modify the status of a protection rule, use the RuleStatus parameter of the ModifyDefenseRuleStatus operation. Valid values:
- 0: Disabled.
- 1 (default): Enabled.




actionStringYesblockThe action of the protection rule. Valid values:
- block: Block.
- monitor: Monitor.




actionExternalJSONNo{"responseRuleId":123444}The extended configuration of the protection rule action. Only the new version of custom response supports this configuration. When action is set to block, you can specify a custom block page.
remoteAddrArrayYes["1.1.XX.XX", "3.1.XX.XX/24"]The list of IP addresses to add to the blacklist, in the format of ["ip1","ip2",...].

Example

{
    "InstanceId": "waf_v2_public_****",
    "TemplateId": 2222,
    "DefenseScene": "ip_blacklist",
    "Rules": "[{\"name\":\"iptest1\",\"remoteAddr\":[\"1.1.1.2\",\"3.3.3.3/24\"],\"action\":\"monitor\",\"status\":1},{\"name\":\"iptest2\",\"remoteAddr\":[\"4.4.4.4\",\"5.5.5.5/32\"],\"action\":\"block\",\"status\":1}]"
}

Custom rules (custom_acl)

Parameter descriptions

NameTypeRequiredExampleDescription
nameStringYesiptestThe name of the custom ACL rule. The name must be 1 to 255 characters in length and can contain Chinese characters, letters, digits, underscores (_), periods (.), or hyphens (-).
statusIntegerYes1The status of the protection rule. This parameter is used only for creating protection rules. To modify the status of a protection rule, use the RuleStatus parameter of the ModifyDefenseRuleStatus operation. Valid values:
- 0: Disabled.
- 1 (default): Enabled.




actionStringYesblockThe action of the protection rule. Valid values:
- block: Block.
- monitor: Monitor.
- js: JavaScript challenge.
- captcha: Slider CAPTCHA.
- captcha_strict: Strict slider CAPTCHA.
Note The supported protection rule actions for custom ACL rules are subject to the custom rule actions displayed in the WAF console.
















actionExternalJSONNo{"responseRuleId":123444}The extended configuration of the protection rule action. Only the new version of custom response supports this configuration. When action is set to block, you can specify a custom block page. When action is set to captcha or captcha_strict, you can specify a custom slider CAPTCHA page.
conditionsArrayYes[{"key":"IP","opValue":"eq","values":"11.XX.XX.1"},{"key":"Header","subKey":"abc","opValue":"contains","values":"test"}]The traffic characteristics of the ACL rule, described in JSON string format. A maximum of five match conditions are supported. For more information, refer to the conditions configuration description in Protection rule parameter settings.
ccStatusIntegerYes1Specifies whether to enable rate limiting. Valid values:
- 0: Disable rate limiting.
- 1: Enable rate limiting.




ratelimitJSONNo{"target":"remote_addr","interval":5,"threshold":2,"ttl":1800,"status":{"code":404,"count":2}}The detailed rate limiting configuration, described in JSON string format. Configure this parameter only when ccStatus is set to 1. For more information, refer to the ratelimit detailed configuration in Protection rule parameter settings.
effectStringNoruleThe scope of the rate limiting. Configure this parameter only when ccStatus is set to 1. Valid values:
- service: The rate limiting takes effect on the protected object.
- rule: The rate limiting takes effect on a single rule.




grayStatusIntegerNo1Specifies whether to enable canary release for the rule. Valid values:
- 0 (default): Disable canary release.
- 1: Enable canary release.




grayConfigJSONNo{"grayTarget":"header","grayRate":80,"graySubKey":"test"}The canary release environment configuration for the rule, described in JSON string format. Configure this parameter only when grayStatus is set to 1. For more information, refer to the grayConfig detailed configuration in Protection rule parameter settings.
timeConfigJSONNo{"timeScope":"period","timeZone":8,"timePeriods":[{"start":1758771729787,"end":1758816000000}]}The scheduled configuration for the rule, described in JSON string format. For more information, refer to the timeConfig detailed configuration in Protection rule parameter settings.

Example

{
    "InstanceId": "waf_v2_public_****",
    "TemplateId": 6242,
    "DefenseScene": "custom_acl",
    "Rules":"[{\"name\":\"acl_test\",\"action\":\"block\",\"conditions\":[{\"key\":\"URL\",\"opValue\":\"contain\",\"values\":\"abc\"}],\"ratelimit\":{\"target\":\"remote_addr\",\"interval\":5,\"threshold\":2,\"ttl\":1800,\"status\":{\"code\":404,\"count\":2}},\"ccStatus\":1,\"effect\":\"rule\",\"status\":1,\"origin\":\"custom\",\"timeConfig\":{\"timeScope\":\"cycle\",\"timeZone\":8,\"weekTimePeriods\":[{\"day\":\"1\",\"dayPeriods\":[{\"start\":0,\"end\":51644084}]},{\"day\":\"1,2,5\",\"dayPeriods\":[{\"start\":0,\"end\":42928908}]}]},\"grayStatus\":1,\"grayConfig\":{\"grayRate\":80,\"graySubKey\":\"test\",\"grayTarget\":\"header\"}}]"
}

Whitelist rules (whitelist)

Parameter descriptions

NameTypeRequiredExampleDescription
nameStringYeswhitelistTestThe name of the whitelist rule. The name must be 1 to 255 characters in length and can contain Chinese characters, letters, digits, underscores (_), periods (.), or hyphens (-).
statusIntegerYes1The status of the protection rule. This parameter is used only for creating protection rules. To modify the status of a protection rule, use the RuleStatus parameter of the ModifyDefenseRuleStatus operation. Valid values:
- 0: Disabled.
- 1 (default): Enabled.




conditionsArrayYes[{"key":"IP","opValue":"eq","values":"11.XX.XX.1"},{"key":"Header","subKey":"abc","opValue":"contains","values":"test"}]The traffic characteristics of the whitelist, described in JSON string format. A maximum of five match conditions are supported. For more information, refer to the conditions configuration description in Protection rule parameter settings.
tagsArrayYes["waf", "regular"]The list of modules to which the whitelist applies, in the format of ["XX1", "XX2",...]. Valid values:
- waf: All modules.
- customrule_rule: Specific custom rules.
- customrule: Custom rules.
- blacklist: IP Blacklist.
- blacklist_rule: Specific IP blacklist rules.
- antiscan: Scan Protection.
- regular: Basic protection rules.
- regular_rule: Specific basic protection regex rules.
- regular_type: Specific basic protection regex rule types.
- regular_field: Specific basic protection fields.
- major_protection: Major Event Protection.
- cc: HTTP Flood Protection.
- region_block: Location Blacklist.
- antibot_scene: BOT Scenario Protection.
- antibot_scene_rule: Specific BOT scenario protection rule IDs.
- antibot_scene_label: Specific BOT scenario protection rule types.
- dlp: Information Leak Prevention.
- tamperproof: web tamper proofing.
- spike_throttle: throttling protection for peak traffic.























































regularRulesArrayNo[ "111111", "222222" ]The list of regex rule IDs to skip, in the format of ["XX1", "XX2",...]. Configure this parameter only when the whitelist module is set to specific basic protection regex rules (the tags parameter is set to regular_rule).
regularTypesArrayNo[ "xss", "css" ]The list of regex rule types to skip, in the format of ["XX1", "XX2",...]. Configure this parameter only when the whitelist module is set to Web application regex types (the tags parameter is set to regular_type). Valid values:
- sqli: SQL injection.
- xss: Cross-site scripting.
- code_exec: Code execution.
- crlf: CRLF.
- lfilei: Local file inclusion.
- rfilei: Remote file inclusion.
- webshell: WebShell.
- csrf: CSRF.
- other: Other.

























regularFieldsArrayNo[{"key":"URL"},{"key":"Header","subKey":"abc"}]The list of basic protection fields to skip, described in JSON string format. A maximum of five match conditions are supported. For more information, refer to regularFields detailed configuration. Configure this parameter only when the whitelist module is set to specific basic protection fields (the tags parameter is set to regular_field).
customRulesArrayNo[ "111111", "222222" ]The list of custom rule IDs to skip, in the format of ["XX1", "XX2",...]. Configure this parameter only when the whitelist module is set to specific custom rules (the tags parameter is set to customrule_rule).
blacklistRulesArrayNo[ "111111", "222222" ]The list of IP blacklist rule IDs to skip, in the format of ["XX1", "XX2",...]. Configure this parameter only when the whitelist module is set to specific IP blacklist rules (the tags parameter is set to blacklist_rule).
botRulesArrayNo[ "111111", "222222" ]The list of BOT scenario protection rule IDs to skip, in the format of ["XX1", "XX2",...]. Configure this parameter only when the whitelist module is set to specific BOT scenario protection rule IDs (the tags parameter is set to antibot_scene_rule).
botLablesArrayNo[ "abc", "cdcc" ]The list of BOT scenario protection rule types to skip, in the format of ["XX1", "XX2",...]. Configure this parameter only when the whitelist module is set to specific BOT scenario protection rule types (the tags parameter is set to antibot_scene_label). You can call the DescribeBotRuleLabels operation to query the BOT rule type information.

regularFields detailed configuration

NameTypeRequiredExampleDescription
keyStringYesURLThe field to skip. Valid values:
- URL-All: All URI-related fields.
- URL: Specified URI field.
- URLPath: URI Path.
- Query-All: All Query-related fields.
- Query-Arg: Specified Query parameter.
- Cookie-All: All Cookie-related fields.
- Cookie-Exact: Specified Cookie Name.
- Header-All: All Header-related fields.
- Header: Specified Header field.
- Body-All: All Body parameters.




























subKeyStringNoabcThe specified field. Configure this parameter when the field to skip (key) is set to URLPath, Query-Arg, Cookie-Exact, or Header.

Example

{
    "InstanceId": "waf_v2_public_****",
    "TemplateId": 9242,
    "DefenseScene": "whitelist",
    "Rules":"[{\"name\":\"whitelistTest\",\"tags\":[\"regular_rule\",\"customrule\"],\"status\":1,\"origin\":\"custom\",\"conditions\":[{\"key\":\"URL\",\"opValue\":\"contain\",\"values\":\"/test\"},{\"key\":\"Header\",\"opValue\":\"eq\",\"values\":\"ffff\",\"subKey\":\"abc\"}],\"regularRules\":[\"123444\",\"444444\"]}]"
}

Custom Response rules (custom_response)

Parameter description

NameTypeRequiredExampleDescription
responseTypeStringRequiredresponse_blockThe type of the custom response. Set the value to response_block, which indicates a block response.
statusIntegerRequired1The status of the protection rule. This parameter is used only when you create a protection rule. To modify the status of a protection rule, use the RuleStatus parameter of the ModifyDefenseRuleStatus operation. Valid values:
- 0: Disabled.
- 1 (default): Enabled.




configStringRequired{"responseCode":400,"responseHeaders":[{"key":"custom","value":"123"},{"key":"aaa","value":"2223"}],"responseContent":"HelloWorld"}The custom configuration information, described as a JSON string. For more information, see Detailed config configuration.

Detailed config configuration

NameTypeRequiredExampleDescription
responseCodeIntegerRequired400The response code.
responseHeadersArrayOptional[{"key":"custom","value":"123"},{"key":"aaaa","value":"2223"}]The list of custom response headers, described as a JSON string. key specifies the header field, and value specifies the header value.
responseContentStringRequiredhelloworldThe content of the custom response.

Example

{
  "name": "ruleTest",
  "detectType": "sqli",
  "riskLevel": "strict",
  "condition": [{"key": "FileName","opValue": "eq","values": "test"}]
}

Address book (address_book)

Parameter description

NameTypeRequiredExampleDescription
nameStringRequiredbookTestThe name of the address book. The name must be 1 to 255 characters in length and can contain letters, digits, underscores (_), periods (.), and hyphens (-).
valueTypeStringRequiredipThe type of the address book. Valid values:
- ip: IP address type.

descriptionStringOptionaladdressbookTestThe description of the address book.

Example

{
  "name": "bookTest",
  "valueType": "ip",
  "description": "addressbookTest"
}

Custom response rule (custom_response)

Parameter description

NameTypeRequiredExampleDescription
nameStringRequiredtestThe name of the custom response rule. The name must be 1 to 255 characters in length and can contain letters, digits, underscores (_), periods (.), and hyphens (-).
actionStringRequiredblockThe action of the protection rule. Valid values:
- block: block.
- captcha: slider CAPTCHA.




responseCodeIntegerOptional400The custom response code.
- This parameter is required for custom block page rules.
- Custom slider CAPTCHA page rules do not support custom response codes. The default value is 200.




responseHeadersArrayOptional[{"key":"custom","value":"123"},{"key":"aaaa","value":"2223"}]The list of custom response headers, described in JSON string format. key specifies the header field, and value specifies the header value.
designTypeStringOptionalcustomThe response configuration type. This parameter is required only for custom slider CAPTCHA page rules, that is, when action is set to captcha. Valid values:
- custom: custom configuration.
- preDefine: predefined configuration.




responseContentStringOptionalhelloworldThe content of the custom response. This parameter is required for custom slider CAPTCHA or block pages.
preDefineContentArrayOptional[{"language":"cn","title":"test","description":"desc","captchaColor":"#FFFF","showTraceId":false},{"language":"en","title":"titel","description":"desc","captchaColor":"#FFFF","showTraceId":false}]The predefined configuration content. This parameter is required when designType is set to preDefine. Otherwise, do not specify this parameter. For more information, see Predefined configuration details.

Predefined configuration details

NameTypeRequiredExampleDescription
languageStringRequiredenThe language configuration. Valid values:
- en: English.
- cn: Chinese.




iconStringRequiredhttps://img.alicdn.com/imgextra/i1/O1CN01L12MaQ1ZwfYKk7Yrc_!!6000000003259-2-tps-900-594.pngThe icon. Specify a publicly accessible URL.
titleStringRequiredtest_titleThe title of the custom slider CAPTCHA page.
descriptionStringRequiredFor better experience, please slide to complete the verification process before accessing the web page.The description of the custom slider CAPTCHA page.
captchaColorStringRequired#ff6a00The color of the slider CAPTCHA.
showTraceIdbooleanRequiredtrueSpecifies whether to display the log ID. Valid values:
- true: The log ID is displayed on the slider CAPTCHA page.
- false: The log ID is not displayed on the slider CAPTCHA page.




Custom block page configuration example

{
  "name": "test",
  "action": "block",
  "responseContent": "helloworld",
  "responseCode": 401,
  "responseHeaders": [{"key":"t1","value":"v1"}],
}

Predefined slider CAPTCHA page configuration example

{
"name": "test",
"designType": "preDefine",
"action": "captcha",
"responseHeaders": [
    {
    "key": "Content-Type",
    "value": "text/html"
    }
],
"preDefineContent": [
    {
    "language": "en",
    "icon": "https://img.alicdn.com/imgextra/i1/O1CN01L12MaQ1ZwfYKk7Yrc_!!6000000003259-2-tps-900-594.png",
    "title": "Access Verification-custom",
    "description": "For better experience, please slide to complete the verification process before accessing the web page.",
    "captchaColor": "#ff6a00",
    "showTraceId": true
    }
]
}

Response elements

Element

Type

Description

Example

object

The response struct.

RequestId

string

The ID of the request.

26E46541-7AAB-5565-801D-F14DBDC5****

RuleIds

string

The IDs of the created protection rules. Multiple protection rule IDs are separated by commas (,).

22215,23354,462165

Examples

Success response

JSON format

{
  "RequestId": "26E46541-7AAB-5565-801D-F14DBDC5****",
  "RuleIds": "22215,23354,462165"
}

Error codes

HTTP status code

Error code

Error message

Description

400 Defense.Control.DefenseWhitelistBypassRuleNotExist The whitelist protection rule does not exist. The whitelist protection rule does not exist. Rule ID:%s.
400 Defense.Control.DefenseWhitelistConfigInvalid The whitelist rule is misconfigured. Error configuring whitelist rule: %s.
400 Defense.Control.DefenseBookTypeInvalid The address book type is illegal. The address book type is illegal.
400 Defense.Control.DefenseThreatIntelligenceConfigInvalid Threat Intelligence Rule configuration error. Threat Intelligence Rule configuration error. %s
400 Defense.Control.DefenseIpCountOversize The number of IPs exceeds the limit. The number of IPs exceeds the limit.
400 Defense.Control.InvalidDefenseRuleConfig Invalid protection rule configuration. %s. Invalid protection rule configuration.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.