utils: BucketNames with double periods and ip address should be rejected. (#2213)

Fixes #2212
master
Harshavardhana 8 years ago committed by GitHub
parent cbb6b48b94
commit 2d38046a5a
  1. 5
      object-utils.go
  2. 2
      object-utils_test.go

@ -39,6 +39,7 @@ const (
// validBucket regexp. // validBucket regexp.
var validBucket = regexp.MustCompile(`^[a-z0-9][a-z0-9\.\-]{1,61}[a-z0-9]$`) var validBucket = regexp.MustCompile(`^[a-z0-9][a-z0-9\.\-]{1,61}[a-z0-9]$`)
var isIPAddress = regexp.MustCompile(`^(\d+\.){3}\d+$`)
// IsValidBucketName verifies a bucket name in accordance with Amazon's // IsValidBucketName verifies a bucket name in accordance with Amazon's
// requirements. It must be 3-63 characters long, can contain dashes // requirements. It must be 3-63 characters long, can contain dashes
@ -51,7 +52,9 @@ func IsValidBucketName(bucket string) bool {
if bucket[0] == '.' || bucket[len(bucket)-1] == '.' { if bucket[0] == '.' || bucket[len(bucket)-1] == '.' {
return false return false
} }
return validBucket.MatchString(bucket) return (validBucket.MatchString(bucket) &&
!isIPAddress.MatchString(bucket) &&
!strings.Contains(bucket, ".."))
} }
// IsValidObjectName verifies an object name in accordance with Amazon's // IsValidObjectName verifies an object name in accordance with Amazon's

@ -42,6 +42,8 @@ func TestIsValidBucketName(t *testing.T) {
// cases for which test should fail. // cases for which test should fail.
// passing invalid bucket names. // passing invalid bucket names.
{"------", false}, {"------", false},
{"my..bucket", false},
{"192.168.1.1", false},
{"$this-is-not-valid-too", false}, {"$this-is-not-valid-too", false},
{"contains-$-dollar", false}, {"contains-$-dollar", false},
{"contains-^-carrot", false}, {"contains-^-carrot", false},

Loading…
Cancel
Save