From 650c2f14e6103142585a4cbad8cfc9d65f073e93 Mon Sep 17 00:00:00 2001 From: mstgnz Date: Thu, 14 Dec 2023 20:41:17 +0300 Subject: [PATCH] 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)