From 650c2f14e6103142585a4cbad8cfc9d65f073e93 Mon Sep 17 00:00:00 2001 From: mstgnz Date: Thu, 14 Dec 2023 20:41:17 +0300 Subject: [PATCH 1/2] concurrency security fix for content type closed #1142 --- minio/minio.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/minio/minio.go b/minio/minio.go index ebf65847..8b7493b1 100644 --- a/minio/minio.go +++ b/minio/minio.go @@ -6,6 +6,7 @@ import ( "errors" "log" "net/http" + "sync" "time" "github.com/minio/minio-go/v7" @@ -18,6 +19,7 @@ type Storage struct { minio *minio.Client cfg Config ctx context.Context + mu sync.Mutex } // New creates a new storage @@ -92,7 +94,9 @@ func (s *Storage) Set(key string, val []byte, exp time.Duration) error { file := bytes.NewReader(val) // set content type + s.mu.Lock() s.cfg.PutObjectOptions.ContentType = http.DetectContentType(val) + s.mu.Unlock() // put object _, err := s.minio.PutObject(s.ctx, s.cfg.Bucket, key, file, file.Size(), s.cfg.PutObjectOptions) From 9649b7ab4899a0880bb887c4a747f6e836b498ce Mon Sep 17 00:00:00 2001 From: mstgnz Date: Sun, 17 Dec 2023 08:48:02 +0300 Subject: [PATCH 2/2] fix Minio concurrency issues for PutObject --- minio/minio.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/minio/minio.go b/minio/minio.go index 8b7493b1..84127324 100644 --- a/minio/minio.go +++ b/minio/minio.go @@ -96,10 +96,10 @@ func (s *Storage) Set(key string, val []byte, exp time.Duration) error { // set content type s.mu.Lock() s.cfg.PutObjectOptions.ContentType = http.DetectContentType(val) - s.mu.Unlock() // put object _, err := s.minio.PutObject(s.ctx, s.cfg.Bucket, key, file, file.Size(), s.cfg.PutObjectOptions) + s.mu.Unlock() return err }