Browse Source

Merge pull request #1371 from Kimbsen/content_md5_validation

Optional md5 validation of uploads
pull/1377/head
Chris Lu 5 years ago
committed by GitHub
parent
commit
c21f4ebfee
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      weed/storage/needle/needle_parse_upload.go

11
weed/storage/needle/needle_parse_upload.go

@ -1,6 +1,7 @@
package needle package needle
import ( import (
"crypto/md5"
"fmt" "fmt"
"io" "io"
"io/ioutil" "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 return
} }

Loading…
Cancel
Save