aws / aws/aws-cdk

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

Open Beginner friendly
#38,475 1 comment 0 reactions 0 assignees View on GitHub
@aws-cdk/aws-events bug p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### 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

```ts
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

Contributor guide

Open the contributing guide

Research direction

Start at events.Match.cidr() and inspect the IPv6 validation regex in aws-events/lib/event-pattern.ts, then compare the duplicated regex in aws-ec2/lib/prefix-list.ts. Verify the stated IPv4-embedded IPv6 examples: valid addresses should be accepted and the malformed address should be rejected.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cloud, infrastructure
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.