mirror of
https://github.com/pgsty/minio.git
synced 2026-11-12 02:25:34 +03:00
fix(batch): reject invalid UTF-8 before KMS context rotation
Reject contexts whose JSON serialization could change associated data or collapse distinct keys. Validate both submissions and persisted jobs before changing an object key; retain valid Unicode, including replacement characters. Exercise malformed-key collisions, invalid values, manifest reload failures and readback with the real builtin KMS. Refs #346. Signed-off-by: Feng Ruohang <rh@vonng.com>
This commit is contained in:
@@ -29,6 +29,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/minio/minio-go/v7/pkg/tags"
|
||||
@@ -99,6 +100,11 @@ func batchKeyRotateContext(encoded string) (kms.Context, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Saving the context replaces invalid UTF-8 and can collapse distinct
|
||||
// keys, changing the associated data required to decrypt the object.
|
||||
if !utf8.Valid(b) {
|
||||
return nil, fmt.Errorf("KMS context must be valid UTF-8: %w", errInvalidArgument)
|
||||
}
|
||||
if err = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(b, &ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user