Skip to content

Commit 178670f

Browse files
authored
fix: broken Content-MD5 header for S3 upload (#527)
fix: remove broken MD5 Content-MD5 header from S3 upload The MD5 hash was computed over an already-exhausted file reader, always producing a hash of empty content. Since Content-MD5 is optional for S3 presigned POST uploads and the signed policy already enforces integrity, remove it entirely.
1 parent 1e9c53e commit 178670f

2 files changed

Lines changed: 0 additions & 13 deletions

File tree

internal/api/s3_upload.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ package api
1717
import (
1818
"bytes"
1919
"context"
20-
"crypto/md5"
21-
"encoding/base64"
2220
"fmt"
2321
"io"
2422
"mime/multipart"
@@ -76,13 +74,6 @@ func (c *Client) UploadPackageToS3(ctx context.Context, fs afero.Fs, appID strin
7674
}
7775
}
7876

79-
md5hash := md5.New()
80-
if _, err := io.Copy(md5hash, archive); err != nil {
81-
return fileName, err
82-
}
83-
84-
md5s := base64.StdEncoding.EncodeToString(md5hash.Sum(nil))
85-
8677
var part io.Writer
8778
h := make(textproto.MIMEHeader)
8879
h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="%s"; filename="%s"`, "file", fileName))
@@ -105,7 +96,6 @@ func (c *Client) UploadPackageToS3(ctx context.Context, fs afero.Fs, appID strin
10596
return fileName, err
10697
}
10798
request.Header.Add("Content-Type", writer.FormDataContentType())
108-
request.Header.Add("Content-MD5", md5s)
10999
cliVersion, err := slackcontext.Version(ctx)
110100
if err != nil {
111101
return fileName, err

internal/api/s3_upload_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ func TestClient_UploadPackageToS3(t *testing.T) {
6767
require.NoError(t, err)
6868
require.Equal(t, "this is the package", string(contentBytes))
6969

70-
md5Header := r.Header["Content-Md5"][0]
71-
require.Equal(t, "1B2M2Y8AsgTpgAmY7PhCfg==", md5Header)
72-
7370
w.WriteHeader(http.StatusNoContent)
7471
}))
7572
defer server.Close()

0 commit comments

Comments
 (0)