soto-project / soto

Swift SDK for AWS that works on Linux, macOS and iOS
https://soto.codes
Apache License 2.0
875 stars 83 forks source link

S3 PutObject fails if request has double whitespaces in content disposition #584

Closed t-ae closed 2 years ago

t-ae commented 2 years ago

Describe the bug

Calling S3.putObject with contentDisposition that specifies filename which contains double white spaces always fails.

To Reproduce

let client: S3

let fileName = "double  whitespace.txt"
let contentDisposition = "inline; filename=\"\(fileName)\""

let resp = try! client.putObject(
    S3.PutObjectRequest(
        body: AWSPayload.data(Data()),
        bucket: bucketName,
        contentDisposition: contentDisposition,
        key: "test/foo.txt"
    )
).wait()
// Fatal error: 'try!' expression unexpectedly raised an error: SignatureDoesNotMatch: The request signature we calculated does not match the signature you provided. Check your key and signing method.

Setup (please complete the following information):

adam-fowler commented 2 years ago

Ok, not totally sure what is going on here. It looks like it is related to all header fields that include a double space.

adam-fowler commented 2 years ago

Found the issue. When building the canonical request for signing I needed to replace sequential spaces with a single space.