Skip to content

added WAF tests to CDK unit tests - #238

Open
michael-fleming-nih wants to merge 1 commit into
mainfrom
cdk-waf-tests
Open

added WAF tests to CDK unit tests#238
michael-fleming-nih wants to merge 1 commit into
mainfrom
cdk-waf-tests

Conversation

@michael-fleming-nih

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the existing CDK security unit test suite to validate AWS WAFv2 (WebACL) security posture when a WebACL is present in the synthesized template.

Changes:

  • Added helper logic to extract WAFv2 WebACL rules from the synthesized CloudFormation template.
  • Added WAF-focused unit tests covering default action, allow-rule scoping, rate limiting, payload size constraints, rule priority ordering, and WebACL attachment.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

rules_by_name maps rule Name -> rule dict (Priority/Statement/Action/...), pooled
across all WebACLs found, since a stack is expected to define at most one ACL.
"""
web_acls = template.find_resources("AWS::WAFv2::WebACL")
Comment on lines +647 to +661
for rule in allow_rules:
statement = rule.get("Statement", {})
# The allow rule(s) must scope to specific URI paths (byte match / regex / or-statement
# of paths) rather than an unconditional match, so unknown/unlisted endpoints remain
# blocked by the WebACL's default action.
scopes_to_paths = (
"ByteMatchStatement" in statement
or "RegexMatchStatement" in statement
or "RegexPatternSetReferenceStatement" in statement
or "OrStatement" in statement
)
assert scopes_to_paths, (
f"Allow rule '{rule.get('Name')}' does not scope to specific accepted endpoints "
"(expected a ByteMatch/Regex/Or statement matching the URI path)"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants