diff options
| author | Chris Lu <chrislusf@users.noreply.github.com> | 2020-06-24 11:33:44 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-24 11:33:44 -0700 |
| commit | c21f4ebfee1455f29d66fb38c55f12ab7dfa232d (patch) | |
| tree | 9f33e17af043dc3dacdc0e1cf134b76a612f332f | |
| parent | fe60db404acc581dcadf400a9fb8a41cecb4bb09 (diff) | |
| parent | 4eeab2a3793103027767968ca73ae03b2fe51c01 (diff) | |
| download | seaweedfs-c21f4ebfee1455f29d66fb38c55f12ab7dfa232d.tar.xz seaweedfs-c21f4ebfee1455f29d66fb38c55f12ab7dfa232d.zip | |
Merge pull request #1371 from Kimbsen/content_md5_validation
Optional md5 validation of uploads
| -rw-r--r-- | weed/storage/needle/needle_parse_upload.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/weed/storage/needle/needle_parse_upload.go b/weed/storage/needle/needle_parse_upload.go index dcbfd3819..a2c881f92 100644 --- a/weed/storage/needle/needle_parse_upload.go +++ b/weed/storage/needle/needle_parse_upload.go @@ -1,6 +1,7 @@ package needle import ( + "crypto/md5" "fmt" "io" "io/ioutil" @@ -79,6 +80,16 @@ func ParseUpload(r *http.Request, sizeLimit int64) (pu *ParsedUpload, e error) { } } } + + if expectedChecksum := r.Header.Get("Content-MD5"); expectedChecksum != "" { + h := md5.New() + h.Write(pu.UncompressedData) + if receivedChecksum := fmt.Sprintf("%x", h.Sum(nil)); expectedChecksum != receivedChecksum { + e = fmt.Errorf("Content-MD5 did not match md5 of file data [%s] != [%s]", expectedChecksum, receivedChecksum) + return + } + } + return } |
