From a5ac780e66a9a21af1af69e94f86251a9d30c3c8 Mon Sep 17 00:00:00 2001 From: "user.email" Date: Sat, 24 Oct 2026 09:52:12 -0700 Subject: [PATCH] filer: verify the media part Content-Md5 during format ingest A supplied checksum that mismatches now rejects with BadDigest and the uploaded chunks are deleted, matching the normal upload path. --- weed/server/filer_server_format.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/weed/server/filer_server_format.go b/weed/server/filer_server_format.go index eccabb1171..d983939331 100644 --- a/weed/server/filer_server_format.go +++ b/weed/server/filer_server_format.go @@ -26,6 +26,7 @@ import ( "github.com/seaweedfs/seaweedfs/weed/storage/needle" "github.com/seaweedfs/seaweedfs/weed/util" "github.com/seaweedfs/seaweedfs/weed/util/chunk_cache" + "github.com/seaweedfs/seaweedfs/weed/util/constants" ) const ( @@ -199,6 +200,13 @@ func (fs *FilerServer) formatIngest(ctx context.Context, w http.ResponseWriter, writeJsonError(w, r, http.StatusInternalServerError, uploadErr) return } + if expectedMd5 := mediaPart.Header.Get("Content-Md5"); expectedMd5 != "" { + if md5bytes := md5Hash.Sum(nil); util.Base64Encode(md5bytes) != expectedMd5 && fmt.Sprintf("%x", md5bytes) != expectedMd5 { + cleanup() + writeJsonError(w, r, http.StatusBadRequest, errors.New(constants.ErrMsgBadDigest)) + return + } + } if total := layout.TotalSize(); written != total { cleanup() writeJsonError(w, r, http.StatusBadRequest, fmt.Errorf("media is %d bytes but the index describes %d", written, total))