Skip to content
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

Fix endpoint matcher host label validation #2910

Merged
merged 3 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gems/aws-sdk-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Unreleased Changes
------------------

* Issue - Fix host label validation in endpoint matchers.

3.181.0 (2023-08-22)
------------------

Expand Down
22 changes: 13 additions & 9 deletions gems/aws-sdk-core/lib/aws-sdk-core/endpoints/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ def self.valid_host_label?(value, allow_sub_domains = false)
return false if value.empty?

if allow_sub_domains
labels = value.split('.')
labels = value.split('.', -1)
return labels.all? { |l| valid_host_label?(l) }
end

value =~ /\A(?!-)[a-zA-Z0-9-]{1,63}(?<!-)\z/
!!(value =~ /\A(?!-)[a-zA-Z0-9-]{1,63}(?<!-)\z/)
end

# AWS
Expand Down Expand Up @@ -114,13 +114,17 @@ def self.aws_parse_arn(value)

# aws.isVirtualHostableS3Bucket(value: string, allowSubDomains: bool) bool
def self.aws_virtual_hostable_s3_bucket?(value, allow_sub_domains = false)
!!(value.size < 64 &&
# regular naming rules
value =~ /^[a-z0-9][a-z0-9\-#{'.' if allow_sub_domains}]+[a-z0-9]$/ &&
# not IP address
value !~ /(\d+\.){3}\d+/ &&
# no dash and hyphen together
value !~ /[.-]{2}/)
return false if value.empty?

if allow_sub_domains
labels = value.split('.', -1)
return labels.all? { |l| aws_virtual_hostable_s3_bucket?(l) }
end

# must be between 3 and 63 characters long, no uppercase
value =~ /\A(?!-)[a-z0-9-]{3,63}(?<!-)\z/ &&
# not an IP address
value !~ /(\d+\.){3}\d+/
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@
}
}
},
{
"documentation": "bucket--with-multiple-dash: isVirtualHostable",
"params": {
"BucketName": "bucket--with-multiple-dash"
},
"expect": {
"endpoint": {
"url": "https://bucket--with-multiple-dash.s3.amazonaws.com"
}
}
},
{
"documentation": "BucketName: not isVirtualHostable (uppercase characters)",
"params": {
Expand Down Expand Up @@ -143,6 +154,15 @@
"expect": {
"error": "not isVirtualHostableS3Bucket"
}
},
{
"documentation": "bucket..name: not isVirtualHostable (consequetive dots)",
"params": {
"BucketName": "bucket..name"
},
"expect": {
"error": "not isVirtualHostableS3Bucket"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,33 @@
"expect": {
"error": "Invalid hostlabel"
}
},
{
"documentation": "ending with a dot is not a valid hostlabel",
"params": {
"Region": "part1."
},
"expect": {
"error": "Invalid hostlabel"
}
},
{
"documentation": "multiple consecutive dots are not allowed",
"params": {
"Region": "part1..part2"
},
"expect": {
"error": "Invalid hostlabel"
}
},
{
"documentation": "labels cannot start with a dash",
"params": {
"Region": "part1.-part2"
},
"expect": {
"error": "Invalid hostlabel"
}
}
]
}
Loading