Avoid object names with '//' to avoid hash inconsistencies (#8946)

This is to fix a situation where an object name incorrectly
is sent with '//' in its path heirarchy, we should reject
such object names because they may be hashed to a set where
the object might not originally belong because, this can
cause situations where once object is uploaded we cannot
delete it anymore.

Fixes #8873
This commit is contained in:
Harshavardhana
2020-02-06 08:29:38 +05:30
committed by GitHub
parent 086fbb745e
commit c2c5b09bb1
4 changed files with 11 additions and 3 deletions

View File

@@ -162,6 +162,7 @@ func checkObjectArgs(ctx context.Context, bucket, object string, obj ObjectLayer
if err := checkObjectNameForLengthAndSlash(bucket, object); err != nil {
return err
}
// Validates object name validity after bucket exists.
if !IsValidObjectName(object) {
return ObjectNameInvalid{

View File

@@ -166,7 +166,10 @@ func IsValidObjectPrefix(object string) bool {
return false
}
// Reject unsupported characters in object name.
if strings.ContainsAny(object, "\\") {
if strings.ContainsAny(object, `\`) {
return false
}
if strings.Contains(object, `//`) {
return false
}
return true

View File

@@ -122,7 +122,9 @@ func TestIsValidObjectName(t *testing.T) {
{" ../etc", false},
{"./././", false},
{"./etc", false},
{"contains-\\-backslash", false},
{`contains-\-backslash`, false},
{`contains//double/forwardslash`, false},
{`//contains/double-forwardslash-prefix`, false},
{string([]byte{0xff, 0xfe, 0xfd}), false},
}