本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
AWS WAF 標籤相符範例
本節提供標籤比對規則陳述式的比對規格範例。
注意
這些 JSON 清單是在主控台中建立的,方法是在具有標籤比對規格的 Web ACL 中新增規則,然後編輯規則並切換至規則 JSON 編輯器。您也可以透過 API 或命令列介面取得規則群組或 Web ACL 的 JSON。
符合本機標籤
下列 JSON 清單會在與此規則相同的內容中,針對已在本機新增至 Web 要求的標籤顯示標籤比對陳述式。
Rule: { Name: "match_rule", Statement: { LabelMatchStatement: { Scope: "LABEL", Key: "header:encoding:utf8" } }, RuleLabels: [ ...generate_more_labels... ], Action: { Block: {} } }
如果您在帳戶 111122223333 中使用此比對陳述式,在您為網頁 ACL 定義的規則中testWebACL
,它會符合下列標籤。
awswaf:111122223333:webacl:testWebACL:header:encoding:utf8
awswaf:111122223333:webacl:testWebACL:testNS1:testNS2:header:encoding:utf8
它不匹配以下標籤,因為標籤字符串不是完全匹配。
awswaf:111122223333:webacl:testWebACL:header:encoding2:utf8
它不匹配以下標籤,因為上下文不相同,所以前綴不匹配。即使您已productionRules
將規則群組新增至定義規則的 Web ACLtestWebACL
,也是如此。
awswaf:111122223333:rulegroup:productionRules:header:encoding:utf8
匹配來自另一個上下文的標籤
下列 JSON 清單顯示標籤比對規則,該規則與使用者建立規則群組內的規則中的標籤相符。在 Web ACL 中執行且不屬於具名規則群組一部分的所有規則,規格中都需要前置字元。此範例標籤規格僅符合確切的標籤。
Rule: { Name: "match_rule", Statement: { LabelMatchStatement: { Scope: "LABEL", Key: "awswaf:111122223333:rulegroup:testRules:header:encoding:utf8" } }, RuleLabels: [ ...generate_more_labels... ], Action: { Block: {} } }
比對受管規則群組標籤
這是比對來自另一個前後關聯而不是比對規則的標籤的特殊情況。下列 JSON 清單顯示受管規則群組標籤的標籤比對陳述式。這只匹配在 label match 語句的密鑰設置中指定的確切標籤。
Rule: { Name: "match_rule", Statement: { LabelMatchStatement: { Scope: "LABEL", Key: "awswaf:managed:aws:managed-rule-set:header:encoding:utf8" } }, RuleLabels: [ ...generate_more_labels... ], Action: { Block: {} } }
匹配本地命名空間
下列 JSON 清單會顯示本機命名空間的標籤比對陳述式。
Rule: { Name: "match_rule", Statement: { LabelMatchStatement: { Scope: "NAMESPACE", Key: "header:encoding:" } }, Labels: [ ...generate_more_labels... ], Action: { Block: {} } }
與本機相Label
符項目類似,如果您在帳戶 111122223333 中使用此陳述式,在您為 Web ACL 定義的規則中testWebACL
,它會符合下列標籤。
awswaf:111122223333:webacl:testWebACL:header:encoding:utf8
它不匹配以下標籤,因為帳戶不相同,因此前綴不匹配。
awswaf:444455556666:webacl:testWebACL:header:encoding:utf8
前置詞也不符合受管規則群組套用的任何標籤,如下所示。
awswaf:managed:aws:managed-rule-set:header:encoding:utf8
符合受管規則群組命名空間
下列 JSON 清單顯示受管規則群組命名空間的標籤比對陳述式。對於您擁有的規則群組,您也必須提供前置詞,才能符合規則內容之外的命名空間。
Rule: { Name: "match_rule", Statement: { LabelMatchStatement: { Scope: "NAMESPACE", Key: "awswaf:managed:aws:managed-rule-set:header:" } }, RuleLabels: [ ...generate_more_labels... ], Action: { Block: {} } }
此規格與下列範例標籤相符。
awswaf:managed:aws:managed-rule-set:header:encoding:utf8
awswaf:managed:aws:managed-rule-set:header:encoding:unicode
它不匹配以下標籤。
awswaf:managed:aws:managed-rule-set:query:badstring