Skip to content

Commit

Permalink
Fix endpoint matcher host label validation
Browse files Browse the repository at this point in the history
  • Loading branch information
mullermp committed Sep 13, 2023
1 parent 714584d commit 765babd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
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.match?(/\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.match?(/\A(?!-)[a-z0-9-]{3,63}(?<!-)\z/) &&
# not an IP address
value !~ /(\d+\.){3}\d+/
end
end
end
Expand Down

0 comments on commit 765babd

Please sign in to comment.