# ################################### ## Rule Specification ## ##################################### # # Rule Identifier: # waf_global_rule_not_empty_check # # Description: # This control checks whether an AWS WAF Classic global rule contains any conditions. # # Reports on: # AWS::WAF::Rule # # Evaluates: # AWS CloudFormation, AWS CloudFormation Hook # # Rule Parameters: # None # # Scenarios: # Scenario: 1 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document does not contain any WAF Classic global rule resources # Then: SKIP # Scenario: 2 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains a WAF Classic global rule resource # And: 'Predicates' has not been provided # Then: FAIL # Scenario: 3 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains a WAF Classic global rule resource # And: 'Predicates' has been provided as an empty list # Then: FAIL # Scenario: 4 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains a WAF Classic global rule resource # And: 'Predicates' has been provided as a non-empty list # Then: PASS # # Constants # let WAF_GLOBAL_RULE_TYPE = "AWS::WAF::Rule" let INPUT_DOCUMENT = this # # Assignments # let waf_global_rules = Resources.*[ Type == %WAF_GLOBAL_RULE_TYPE ] # # Primary Rules # rule waf_global_rule_not_empty_check when is_cfn_template(%INPUT_DOCUMENT) %waf_global_rules not empty { check(%waf_global_rules.Properties) << [CT.WAF.PR.1]: Require any AWS WAF Classic global rule to have a condition [FIX]: Provide one or more AWS WAF Classic rule conditions within the 'Predicates' property. >> } rule waf_global_rule_not_empty_check when is_cfn_hook(%INPUT_DOCUMENT, %WAF_GLOBAL_RULE_TYPE) { check(%INPUT_DOCUMENT.%WAF_GLOBAL_RULE_TYPE.resourceProperties) << [CT.WAF.PR.1]: Require any AWS WAF Classic global rule to have a condition [FIX]: Provide one or more AWS WAF Classic rule conditions within the 'Predicates' property. >> } # # Parameterized Rules # rule check(waf_global_rule) { %waf_global_rule { # Scenario 2, 3 and 4 Predicates exists Predicates is_list Predicates not empty } } # # Utility Rules # rule is_cfn_template(doc) { %doc { AWSTemplateFormatVersion exists or Resources exists } } rule is_cfn_hook(doc, RESOURCE_TYPE) { %doc.%RESOURCE_TYPE.resourceProperties exists }