mirror of
https://github.com/minio/minio.git
synced 2024-12-24 22:25:54 -05:00
utils: BucketNames with double periods and ip address should be rejected. (#2213)
Fixes #2212
This commit is contained in:
parent
cbb6b48b94
commit
2d38046a5a
@ -39,6 +39,7 @@ const (
|
||||
|
||||
// validBucket regexp.
|
||||
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
|
||||
// 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] == '.' {
|
||||
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
|
||||
|
@ -42,6 +42,8 @@ func TestIsValidBucketName(t *testing.T) {
|
||||
// cases for which test should fail.
|
||||
// passing invalid bucket names.
|
||||
{"------", false},
|
||||
{"my..bucket", false},
|
||||
{"192.168.1.1", false},
|
||||
{"$this-is-not-valid-too", false},
|
||||
{"contains-$-dollar", false},
|
||||
{"contains-^-carrot", false},
|
||||
|
Loading…
Reference in New Issue
Block a user