Skip to content

RegexPatternSet

Source: src/AWS/WAFv2/RegexPatternSet.ts

An AWS WAFv2 regex pattern set — a named collection of regular expressions referenced from web ACL and rule group rules via RegexPatternSetReferenceStatement.

Block Requests Matching Bad Path Patterns

const badPaths = yield* AWS.WAFv2.RegexPatternSet("BadPaths", {
regularExpressions: ["^/wp-admin", "\\.php$"],
});

Reference from a Web ACL Rule

const acl = yield* AWS.WAFv2.WebACL("Firewall", {
rules: [
{
Name: "block-bad-paths",
Priority: 0,
Statement: {
RegexPatternSetReferenceStatement: {
ARN: badPaths.regexPatternSetArn,
FieldToMatch: { UriPath: {} },
TextTransformations: [{ Priority: 0, Type: "NONE" }],
},
},
Action: { Block: {} },
VisibilityConfig: {
SampledRequestsEnabled: true,
CloudWatchMetricsEnabled: true,
MetricName: "block-bad-paths",
},
},
],
});