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:
Feng Ruohang
2026-11-11 14:44:50 +08:00
parent 2f228284f3
commit 4a9bdb5407
2 changed files with 78 additions and 2 deletions
+6
View File
@@ -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
}