1

When I try to delete an Object on my Bucket with Chrome it works perfectly. When I try with Safari, I get this error: The Content-MD5 you specified did not match what we received.

This is the curl string from Chrome:

curl 'https://mybucket.s3.cloud/?delete' -H 'Connection: keep-alive' -H 'Pragma: no-cache' -H 'Cache-Control: no-cache' -H 'X-Amz-User-Agent: aws-sdk-js/2.631.0 promise' -H 'Content-MD5: b0reU5O4x/fCQnk/W2oH4w==' -H 'Authorization: OK_STRING, SignedHeaders=content-md5;host;x-amz-content-sha256;x-amz-date;x-amz-user-agent, Signature=OK_STRING' -H 'Content-Type: application/octet-stream; charset=UTF-8' -H 'X-Amz-Content-Sha256: UNSIGNED-PAYLOAD' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36' -H 'Sec-Fetch-Dest: empty' -H 'X-Amz-Date: 20200304T171137Z' -H 'Accept: */*' -H 'Origin: http://localhost:9000' -H 'Sec-Fetch-Site: cross-site' -H 'Sec-Fetch-Mode: cors' -H 'Referer: http://localhost:9000/myurl/explorer' -H 'Accept-Language: fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7' --data-binary '<Delete xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Object><Key>Capture d’écran 2020-03-03 à 17.46.22.png</Key></Object></Delete>' --compressed

This is now the same file and same action with Safari:

curl 'https://mybucket.s3.cloud/?delete' \
-XPOST \
-H 'Content-Type: application/octet-stream; charset=UTF-8' \
-H 'Accept: */*' \
-H 'Authorization: OK_STRING, SignedHeaders=content-md5;host;x-amz-content-sha256;x-amz-date;x-amz-user-agent, Signature=OK_STRING' \
-H 'Accept-Language: fr-fr' \
-H 'Accept-Encoding: gzip, deflate, br' \
-H 'Host: mybucket.s3.cloud' \
-H 'Origin: http://localhost:9000' \
-H 'Content-Length: 138' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15' \
-H 'Referer: http://localhost:9000/' \
-H 'Connection: keep-alive' \
-H 'Content-MD5: b0reU5O4x/fCQnk/W2oH4w==' \
-H 'X-Amz-Date: 20200304T170853Z' \
-H 'X-Amz-User-Agent: aws-sdk-js/2.631.0 promise' \
-H 'X-Amz-Content-Sha256: UNSIGNED-PAYLOAD' \
--data-binary $'<Delete xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Object><Key>Capture d\u2019\xe9cran 2020-03-03 \xe0 17.46.22.png</Key></Object></Delete>'

The code generating these calls is:

s3({
      method: 'deleteObject',
      region: bucket.region,
      params: {
        Bucket: bucket.id,
        Key: file.Key,
        VersionId: file.VersionId,
      },
    })

s3 being an instance 'aws-sdk/clients/s3'

Anyone has an idea of what could go wrong? It looks like Safari is encoding my filename according to the data-binary. Why? How can I prevent this? or force it everywhere else?

Vincent Audebert
  • 1,846
  • 2
  • 15
  • 28

1 Answers1

0

I couldn't find a way to fix it properly. But this was linked to some special chars present in the object key. Here is the AWS guideline https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html#object-key-guidelines

I realised I wasn't checking object keys. So I created a regex test to filter out all the problematic object keys.

Vincent Audebert
  • 1,846
  • 2
  • 15
  • 28