ex-aws/ex_aws_s3

Issues with object name with characters that should be url encoded

Closed this issue · 1 comments

Environment

  • Elixir & Erlang versions (elixir --version):
    Erlang/OTP 22 [erts-10.4.4] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe] [dtrace]

Elixir 1.9.1 (compiled with Erlang/OTP 20)

  • ExAws version mix deps |grep ex_aws

  • ex_aws 2.1.1 (Hex package) (mix)
    locked at 2.1.1 (ex_aws) 1e4de210

  • ex_aws_sqs 2.0.1 (Hex package) (mix)
    locked at 2.0.1 (ex_aws_sqs) 42b19229

  • ex_aws_s3 2.0.2 (Hex package) (mix)
    locked at 2.0.2 (ex_aws_s3) c0258bbd

  • HTTP client version. IE for hackney do mix deps | grep hackney

  • hackney 1.15.1 (Hex package) (rebar3)
    locked at 1.15.1 (hackney) 9f8f471c

Current behavior

I'm trying to perform a head request on an object in a bucket I have access to:

ExAws.S3.head_object("test-bucket", "simples.wav") |> ExAws.request(aws_config)

which returns me the headers just fine.

If the request has a character that should be url encoded:

ExAws.S3.head_object("test-bucket", "b_+22222222_20190726T045247+0000_bf18e58a-0098-99fb-7dbb-be3539d8327a.wav") |> ExAws.request(aws_config)

I get a 404 error

If I url encode the object name

ExAws.S3.head_object("test-bucket", "b_%2B22222222_20190726T045247%2B0000_bf18e58a-0098-99fb-7dbb-be3539d8327a.wav") |> ExAws.request(aws_config)

I then get a 403 error

Expected behavior

I should get a 200 ok with the header details

{:ok, %{ headers: [ {"x-amz-id-2", "B9cWAN2B0szSy+Z4kw52gtzdqCxi70LmCN+g7nw/KNZtLWDv2CyU1MHdrdpzMpbiFk7pGv7RiU4="}, {"x-amz-request-id", "AF68FC0E0BBE2125"}, {"Date", "Fri, 26 Jul 2019 07:54:50 GMT"}, {"Last-Modified", "Fri, 26 Jul 2019 06:43:11 GMT"}, {"ETag", "\"8d754d4e52dbb4e6613446f0d9832d91\""}, {"x-amz-server-side-encryption", "AES256"}, {"Accept-Ranges", "bytes"}, {"Content-Type", "audio/x-wav"}, {"Content-Length", "1918444"}, {"Server", "AmazonS3"} ], status_code: 200 }}

I think I've located the issue, and it's more in the core ex-aws code:

  1. ExAws.Auth.Utils.uri_encode replaces the '+' that are in the filename with a space. This is having the impact of producing an invalid signature. I think this is being done for query params at the end of the path, but is having an impact on the path itself

  2. ExAws.Request.Url.build doesn't url encode the path. I'm not sure if this should be done here at this level, or at the HttpClient level where the request is executed

I'll close this issue here, but created it in the ex-aws repo instead