

**推出 的新主控台體驗 AWS WAF**

您現在可以使用更新後的體驗，在主控台的任何位置存取 AWS WAF 功能。如需詳細資訊，請參閱[使用 主控台](https://docs.aws.amazon.com/waf/latest/developerguide/working-with-console.html)。

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# AWS WAF 標籤比對範例
<a name="waf-rule-label-match-examples"></a>

本節提供標籤比對規則陳述式的比對規格範例。

**注意**  
這些 JSON 清單是在主控台中建立，方法是使用標籤比對規格將規則新增至保護套件 (Web ACL)，然後編輯規則並切換到**規則 JSON 編輯器**。您也可以透過 APIs JSON。

**Topics**
+ [比對本機標籤](#waf-rule-label-match-examples-local-label)
+ [比對其他內容中的標籤](#waf-rule-label-match-examples-label)
+ [符合受管規則群組標籤](#waf-rule-label-match-examples-mgd-rg-label)
+ [比對本機命名空間](#waf-rule-label-match-examples-local-namespace)
+ [符合受管規則群組命名空間](#waf-rule-label-match-examples-mgd-rg-namespace)

## 比對本機標籤
<a name="waf-rule-label-match-examples-local-label"></a>

下列 JSON 清單顯示已新增至本機 Web 請求之標籤的標籤比對陳述式，其內容與此規則相同。

```
Rule: {
    Name: "match_rule",
    Statement: {
        LabelMatchStatement: {
            Scope: "LABEL",
            Key: "header:encoding:utf8"
        }
    },
    RuleLabels: [
        ...generate_more_labels...
    ],
    Action: { Block: {} }
}
```

如果您在帳戶 111122223333 中使用此比對陳述式，在您為保護套件 (Web 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 ACL)`testWebACL`，也是如此。

```
awswaf:111122223333:rulegroup:productionRules:header:encoding:utf8
```

## 比對其他內容中的標籤
<a name="waf-rule-label-match-examples-label"></a>

下列 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: {} }
}
```

## 符合受管規則群組標籤
<a name="waf-rule-label-match-examples-mgd-rg-label"></a>

這是比對標籤的特殊情況，該標籤來自比對規則以外的其他內容。下列 JSON 清單顯示受管規則群組標籤的標籤比對陳述式。這只會比對標籤比對陳述式金鑰設定中指定的確切標籤。

```
Rule: {
    Name: "match_rule",
    Statement: {
        LabelMatchStatement: {
            Scope: "LABEL",
            Key: "awswaf:managed:aws:managed-rule-set:header:encoding:utf8"
        }
    },
    RuleLabels: [
        ...generate_more_labels...
    ],
    Action: { Block: {} }
}
```

## 比對本機命名空間
<a name="waf-rule-label-match-examples-local-namespace"></a>

下列 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
```

## 符合受管規則群組命名空間
<a name="waf-rule-label-match-examples-mgd-rg-namespace"></a>

下列 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
```