Skip to content

fix(ec2): PrefixList rejects IPv6 entries with an embedded IPv4 address - #38474

Open
devteamaegis wants to merge 1 commit into
aws:mainfrom
devteamaegis:fix/ec2-prefixlist-ipv4-mapped-ipv6
Open

fix(ec2): PrefixList rejects IPv6 entries with an embedded IPv4 address#38474
devteamaegis wants to merge 1 commit into
aws:mainfrom
devteamaegis:fix/ec2-prefixlist-ipv4-mapped-ipv6

Conversation

@devteamaegis

@devteamaegis devteamaegis commented Aug 2, 2026

Copy link
Copy Markdown

Issue # (if applicable)

Closes #38476.

Reason for this change

ec2.PrefixList with addressFamily: IP_V6 refuses to synth if any entry embeds an IPv4 address, and accepts a nonsense one.

new ec2.PrefixList(this, 'PL', {
  addressFamily: ec2.AddressFamily.IP_V6,
  entries: [{ cidr: '::ffff:192.168.0.1/128' }],   // IPv4-mapped, RFC 4291 §2.5.5
});
// Error: Invalid IPv6 address range: ::ffff:192.168.0.1/128
entries: [{ cidr: '::ffff:1dd.1dd.1dd.1dd/128' }]  // accepted

Affected: any address written with an embedded IPv4 part — ::ffff:a.b.c.d, 2001:db8::a.b.c.d. Plain IPv6 (2001:db8::/32, 64:ff9b::/96) and IPv4 prefix lists are unaffected.

To be precise about the scope of the claim: this is about client-side validation only. Whether EC2 itself accepts a given embedded-IPv4 range at deploy time is a separate question — and one this regex is not the right place to settle. What is not in question is that the regex as written is broken in both directions: it rejects syntactically valid addresses and accepts ::ffff:1dd.1dd.1dd.1dd.

Description of changes

The regex in the PrefixList constructor lost its backslashes in the embedded-IPv4 alternatives:

(25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}

d matches the literal letter d, not \d, and the separator . matches any character. 192 cannot match [1-9]?d, so every real address is rejected — and 1dd matches literally, so the malformed one passes. s* (for \s*) is wrong the same way.

This restores \d, \. and \s — 14 occurrences, one line, no structural change.

The identical regex is also in aws-events/lib/event-pattern.ts (Match.cidr); that copy is fixed separately in #38473. The two modules cannot share a helper, so both need the correction.

Describe any new or updated permissions being added

None.

Description of how you validated changes

Two unit tests added in aws-ec2/test/prefix-list.test.ts — one asserting the synthesized AWS::EC2::PrefixList entries, one asserting a malformed embedded address is still rejected. Both fail on main:

✕ ipv6 prefixlist accepts entries with an embedded IPv4 address
  «InvalidPvAddressRange» Invalid IPv6 address range: ::ffff:192.168.0.1/128
✕ ipv6 prefixlist rejects a malformed embedded IPv4 address
  Received function did not throw

and pass with the change. jest aws-ec2/test/prefix-list.test.ts: 16 passed. ESLint clean.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

The IPv6 validation regex in the PrefixList constructor lost its
backslashes, so each embedded-IPv4 octet group matches the literal
letter 'd' rather than \d, and the '.' separator matches any character.

An IPv6 prefix list containing '::ffff:192.168.0.1/128' or the NAT64
range '64:ff9b::192.0.2.33/96' therefore failed to synth with 'Invalid
IPv6 address range', while '::ffff:1dd.1dd.1dd.1dd/128' was accepted.
Restore \d, \. and \s in that group.
@github-actions github-actions Bot added beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK p2 labels Aug 2, 2026
@aws-cdk-automation
aws-cdk-automation requested a review from a team August 2, 2026 20:47

@aws-cdk-automation aws-cdk-automation left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The pull request linter fails with the following errors:

❌ Fixes must contain a change to an integration test file and the resulting snapshot.

If you believe this pull request should receive an exemption, please comment and provide a justification. A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed, add Clarification Request to a comment.

✅ A exemption request has been requested. Please wait for a maintainer's review.

@devteamaegis devteamaegis changed the title fix(ec2): PrefixList rejects IPv6 entries with an embedded IPv4 address fix(ec2): PrefixList rejects IPv6 entries with an embedded IPv4 address Aug 2, 2026
@devteamaegis

Copy link
Copy Markdown
Author

Exemption Request

This change is confined to a client-side validation regex in the PrefixList constructor. It does not alter the CloudFormation emitted for any entry that already synthesized — it only changes which entry strings get past validation.

I'd rather be upfront about why I'm asking for the exemption rather than just adding a test file: I have no AWS account to deploy against, so I cannot produce a deploy-backed snapshot. I could generate one from synth alone, but that would assert a deployment I never actually ran, and for this particular change that distinction matters — whether the EC2 API accepts a given embedded-IPv4 range in an IPv6 prefix list is genuinely something I have not verified, and I don't want to imply otherwise by shipping a snapshot.

What is not in question is that the regex is broken in both directions. It reads

(25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}

so d matches the literal letter d instead of \d. 192 cannot match [1-9]?d, so ::ffff:192.168.0.1/128 is rejected — while ::ffff:1dd.1dd.1dd.1dd/128 matches literally and is accepted. Whatever the correct deploy-time policy is, the current behaviour is not it.

The two unit tests in aws-ec2/test/prefix-list.test.ts assert the synthesized AWS::EC2::PrefixList entries and the rejection of the malformed address; both fail on main.

If you'd prefer this gated behind an integration test, I'm glad to write integ.prefix-list-ipv6.ts extending the existing integ.prefix-list.ts — I'd just need someone able to run the deploy to generate the snapshot. Equally, if EC2 turns out to reject these ranges server-side and you'd rather tighten the regex than loosen it, tell me and I'll rework it that way.

@devteamaegis

Copy link
Copy Markdown
Author

Exemption Request

This is a validation-only change: one line in aws-ec2/lib/prefix-list.ts broadens the IPv6 CIDR validation for PrefixList entries (addressFamily: IP_V6) to accept IPv4-mapped / embedded-IPv4 forms (::ffff:192.168.0.1/128 — RFC 4291 §2.5.5) and to reject the malformed ::ffff:1dd.1dd.1dd.1dd/128 case it previously accepted.

It only changes which entry strings are accepted at synth time — for any input that already synthesized, the emitted AWS::EC2::PrefixList is unchanged. There's no new deployable behavior for an integration test to exercise; the fix is pure input validation.

It's fully covered by the unit tests added in aws-ec2/test/prefix-list.test.ts (accepts the IPv4-mapped entry, rejects the malformed one). An integ test would deploy a prefix list solely to re-assert that validation, adding no coverage beyond the unit tests. Happy to add one if you'd prefer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK p2 pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(aws-ec2): PrefixList rejects IPv6 entries with an embedded IPv4 address

2 participants