Skip to content

(events): Match.cidr rejects IPv6 addresses with an embedded IPv4 address #38475

Description

@devteamaegis

Describe the bug

events.Match.cidr() throws Invalid IP address range at synth time for any IPv6 range that embeds an IPv4 address, and accepts a malformed one.

Regression?

No

Last known working version

n/a

Expected Behavior

Match.cidr('::ffff:192.168.0.1') and Match.cidr('64:ff9b::192.0.2.33/96') should be accepted — both are valid CIDR ranges (RFC 4291 §2.5.5 IPv4-mapped, RFC 6052 NAT64). Match.cidr('::ffff:1dd.1dd.1dd.1dd') should be rejected.

Current Behavior

Error: Invalid IP address range: ::ffff:192.168.0.1
Error: Invalid IP address range: 64:ff9b::192.0.2.33/96

and ::ffff:1dd.1dd.1dd.1dd is accepted.

Reproduction Steps

import { Match } from 'aws-cdk-lib/aws-events';

Match.cidr('2001:db8::/32');        // ok
Match.cidr('::ffff:192.168.0.1');   // throws

Possible Solution

The IPv6 regex in aws-events/lib/event-pattern.ts lost its backslashes in the embedded-IPv4 alternatives — (25[0-5]|2[0-4]d|1dd|[1-9]?d) matches the literal letter d rather than \d, and the . separator matches any character. Restoring \d, \. and \s fixes it.

Additional Information/Context

The same regex is duplicated in aws-ec2/lib/prefix-list.ts and has the same defect.

CDK CLI Version

n/a (synth-time validation)

Framework Version

aws-cdk-lib (current main)

Node.js Version

20.x

OS

macOS

Language

TypeScript

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-eventsRelated to CloudWatch EventsbugThis issue is a bug.p2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions