mirror of
https://github.com/versity/versitygw.git
synced 2026-01-08 04:35:15 +00:00
This adds an object name validation util to check if the object path would resolve to a path outside of the bucket directory. S3 returns Bad Request for these type of paths: % aws s3api put-object --bucket mybucket --key test/../../hello An error occurred (400) when calling the PutObject operation: Bad Request
25 lines
762 B
Go
25 lines
762 B
Go
// Copyright 2025 Versity Software
|
|
// This file is licensed under the Apache License, Version 2.0
|
|
// (the "License"); you may not use this file except in compliance
|
|
// with the License. You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing,
|
|
// software distributed under the License is distributed on an
|
|
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
// KIND, either express or implied. See the License for the
|
|
// specific language governing permissions and limitations
|
|
// under the License.
|
|
|
|
package utils
|
|
|
|
func IsObjectNameValid(name string) bool {
|
|
switch clean(name) {
|
|
case "", ".", "..", "/":
|
|
return false
|
|
}
|
|
|
|
return isObjectLocal(name)
|
|
}
|