-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ec2): peer cidr ip validation #3642
Conversation
@@ -112,6 +122,16 @@ class CidrIPv6 implements IPeer { | |||
public readonly uniqueId: string; | |||
|
|||
constructor(private readonly cidrIpv6: string) { | |||
const cidrMatch = cidrIpv6.match(/^([\da-f]{0,4}:){2,7}([\da-f]{0,4})?(\/\d+)?$/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used some fairly loose RegExps, especially for IPv6. The stricter ones tend to become a little crazy
} | ||
|
||
if (!cidrMatch[2]) { | ||
throw new Error(`CIDR mask is missing in IPv4: "${cidrIp}". Did you mean "${cidrIp}/xx"?`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel it makes more sense to replace /xx
with /32
in the error message. If people wrote a single IP address, that's probably what they meant, and if they didn't it's clear enough where to substitute values to make it do what they want.
I considered automatically adding /32
to the IP address, but we should probably make a separate class for single IP addresses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should probably make a separate class for single IP addresses.
I like that idea. We could also deprecate ipv4/v6
and explicitly name them ipv4Cidr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise, done
@@ -77,6 +77,16 @@ class CidrIPv4 implements IPeer { | |||
public readonly uniqueId: string; | |||
|
|||
constructor(private readonly cidrIp: string) { | |||
const cidrMatch = cidrIp.match(/^(\d{1,3}\.){3}\d{1,3}(\/\d+)?$/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess to be safe this needs a if (!cdk.Token.isUnresolved(cidrIp)) { ... }
block around the checks, same for the IPv6 version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
} | ||
|
||
if (!cidrMatch[3]) { | ||
throw new Error(`CIDR mask is missing in IPv6: "${cidrIpv6}". Did you mean "${cidrIpv6}/xx"?`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/128
I suppose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Pull Request Checklist
|
1 similar comment
Pull Request Checklist
|
Thank you for contributing! Your pull request is now being automatically merged. |
Fixes #3639
Please read the contribution guidelines and follow the pull-request checklist.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license