added WAF tests to CDK unit tests - #238
Open
michael-fleming-nih wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
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)" | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.