mirror of
https://github.com/pgsty/minio.git
synced 2026-11-12 10:35:33 +03:00
fix(crypto): return client errors for malformed KMS contexts
Signed-off-by: Feng Ruohang <rh@vonng.com>
This commit is contained in:
@@ -76,9 +76,17 @@ func (ssekms) ParseHTTP(h http.Header) (string, kms.Context, error) {
|
||||
|
||||
var ctx kms.Context
|
||||
if context, ok := h[xhttp.AmzServerSideEncryptionKmsContext]; ok {
|
||||
invalidContext := kms.Error{
|
||||
Code: http.StatusBadRequest,
|
||||
APICode: "InvalidArgument",
|
||||
Err: "KMS context must be valid base64-encoded JSON with string values",
|
||||
}
|
||||
if len(context) == 0 {
|
||||
return "", nil, invalidContext
|
||||
}
|
||||
b, err := base64.StdEncoding.DecodeString(context[0])
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
return "", nil, invalidContext
|
||||
}
|
||||
// Persisting invalid UTF-8 replaces bytes and can collapse distinct
|
||||
// keys, changing the associated data needed to decrypt the object.
|
||||
@@ -92,7 +100,7 @@ func (ssekms) ParseHTTP(h http.Header) (string, kms.Context, error) {
|
||||
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
if err := json.Unmarshal(b, &ctx); err != nil {
|
||||
return "", nil, err
|
||||
return "", nil, invalidContext
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user